Game Development Reference
In-Depth Information
Next, add the following code to override the render() method:
@Override
public void render (SpriteBatch batch) {
TextureRegion reg = null;
// Set special color when game object has a feather power-up
if (hasFeatherPowerup) {
batch.setColor(1.0f, 0.8f, 0.0f, 1.0f);
}
// Draw image
reg = regHead;
batch.draw(reg.getTexture(), position.x, position.y, origin.x,
origin.y, dimension.x, dimension.y, scale.x, scale.y, rotation,
reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(),
reg.getRegionHeight(), viewDirection == VIEW_DIRECTION.LEFT,
false);
// Reset color to white
batch.setColor(1, 1, 1, 1);
}
The preceding code handles the drawing of the image for the bunny head game
object. The image will be tinted orange if the feather power-up effect is active.
Furthermore, add the following code to Constants :
// Duration of feather power-up in seconds
public static final float ITEM_FEATHER_POWERUP_DURATION = 9;
The viewing direction, viewDirection , will change according to the object's
velocity as long as it is unequal to zero. It will be set to VIEW_DIRECTION.LEFT
when the horizontal velocity is negative; otherwise, it will be set to VIEW_
DIRECTION.RIGHT . This simply means that the player's character will always
look in the direction it is moving.
 
Search WWH ::




Custom Search