在andengine中的一个精灵中的两个动画

时间:2014-06-05 11:30:17

标签: android andengine

这可以为一个精灵添加两个动画吗? 这是我的代码:

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;
    }

}

此代码显示快乐香蕉的动画。现在我想开始在20秒内将这个香蕉旋转360度。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

您可以添加任意数量的动画。 继承人如何:

20f(20s)是时间增加以减慢速度以使其更快。然后是0到360

RotationModifier rotate = new RotationModifier(20f, 0, 360);
spriteBanana.registerEntityModifier(rotate); // delete this line if you want endless 

如果你想无休止地重复它。

spriteBanana.registerEntityModifier(new LoopEntityModifier(rotate))));