Game Development Reference
In-Depth Information
Now, make the following final changes to the same class:
@Override
public void render (SpriteBatch batch) {
TextureRegion reg = null;
// Draw Particles
dustParticles.draw(batch);
// Apply Skin Color
batch.setColor(
CharacterSkin.values()[GamePreferences.instance.charSkin]
.getColor());
float dimCorrectionX = 0;
float dimCorrectionY = 0;
if (animation != animNormal) {
dimCorrectionX = 0.05f;
dimCorrectionY = 0.2f;
}
// Draw image
reg = animation.getKeyFrame(stateTime, true);
batch.draw(reg.getTexture(),
position.x, position.y,
origin.x, origin.y,
dimension.x + dimCorrectionX,
dimension.y + dimCorrectionY,
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);
}
In the render() method, we have removed the color-tinting effect in favor of our
new animations. If an animation other than the standard one ( animNormal ) is
detected, we will apply correcting values to the width and height for rendering.
Since the standard animation is of a different dimension than the other animations,
the other ones will look off-centered without the correcting values.
You can now run the game to check out all the animations we added throughout
this chapter.
 
Search WWH ::




Custom Search