Game Development Reference
In-Depth Information
}
public void render (SpriteBatch batch) {
if (collected) return;
TextureRegion reg = null;
reg = animation.getKeyFrame(stateTime, true);
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(),
false, false);
}
In the init() method, we use the inherited setAnimation() method of
AbstractGameObject to set the animGoldCoin animation. Also, the state time is
initialized with a random value in the range from 0.0f to 1.0f . This is really a
special use case here where we want each gold coin to use a different starting frame
so that they look much more natural instead of being perfectly synchronized.
The following screenshot is of some gold coins that were initialized using the
random state time:
 
Search WWH ::




Custom Search