Reputation: 3031
This is possible to add two animations to one sprite? This is my code:
public class MainGameActivity extends SimpleBaseGameActivity {
private int width, height;
private Scene scene;
private Camera camera;
private BitmapTextureAtlas textureBanana;
private TiledTextureRegion regionBanana;
private AnimatedSprite spriteBanana;
private static int spriteColumns = 4;
private static int spriteRows = 2;
@Override
public EngineOptions onCreateEngineOptions() {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
camera = new Camera(0, 0, width, height);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(
width, height), camera);
return engineOptions;
}
@Override
protected void onCreateResources() {
textureBanana = new BitmapTextureAtlas(getTextureManager(), 256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
regionBanana = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(textureBanana, getAssets(), "gfx/spr_banana.png", 0, 0, spriteColumns, spriteRows);
textureBanana.load();
}
@Override
protected Scene onCreateScene() {
scene = new Scene();
scene.setBackground(new Background(Color.WHITE));
spriteBanana = new AnimatedSprite(width/2, height/2, regionBanana, getVertexBufferObjectManager());
scene.attachChild(spriteBanana);
spriteBanana.animate(50);
return scene;
}
}
This code show animation of happy banana. Now I want to start rotate this banana on 360 degree in 20 seconds. How can I do that?
Upvotes: 0
Views: 172
Reputation:
You can add as many animations you like. heres how:
20f(20s) is time increase to slow decrease to make it faster .then 0 to 360
RotationModifier rotate = new RotationModifier(20f, 0, 360);
spriteBanana.registerEntityModifier(rotate); // delete this line if you want endless
if you want to repeat it endless.
spriteBanana.registerEntityModifier(new LoopEntityModifier(rotate))));
Upvotes: 3