0

嗨,我试图让精灵在淡出和缩小后淡入并放大。为此,我使用了实体修饰符侦听器,但它不起作用?这是我的代码:

public class GameScene {

Scene gameScene;
Engine engine;
Activity activity;

BitmapTextureAtlas mTextureAtlas;
ITextureRegion X;
ITextureRegion O;
ITextureRegion XO;

FadeInModifier fadeIn = new FadeInModifier(2);
FadeOutModifier fadeOut = new FadeOutModifier(2);
ScaleModifier scaleDown = new ScaleModifier(3, 1, 0);
ScaleModifier scaleUp = new ScaleModifier(2, 0, 1);

Sprite XOsprite;
Random rand = new Random();
boolean XYset = false;

public GameScene(Engine eng, Activity act) {
    engine = eng;
    activity = act;
}

public Scene getScene() {

    gameScene = new Scene();
    gameScene.setBackground(new Background(0, 256, 59));
    int x = 0, y = 0;

    if (rand.nextInt(2) == 0) {
        XO = X;
    } else {
        XO = O;
    }

    if (!XYset) {
        x = rand.nextInt(MainActivity.CAM_WIDTH);
        y = rand.nextInt(MainActivity.CAM_HEIGHT);
        XYset = true;
    }



    XOsprite = new Sprite(x, y, XO, engine.getVertexBufferObjectManager()) {
        @Override
        public boolean onAreaTouched(final TouchEvent te, final float xVal,
                final float yVal) {
            XOsprite.registerEntityModifier(fadeOut);
            XOsprite.registerEntityModifier(scaleDown);
            return true;

        }
    };
    IEntityModifierListener fadeOutListener = new IEntityModifierListener() {

        @Override
        public void onModifierStarted(IModifier<IEntity> pModifier,
                IEntity pItem) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onModifierFinished(IModifier<IEntity> pModifier,
                IEntity pItem) {
            // TODO Auto-generated method stub
            XOsprite.clearEntityModifiers();
            XOsprite.setPosition(rand.nextInt(MainActivity.CAM_WIDTH), rand.nextInt(MainActivity.CAM_HEIGHT));
            XOsprite.registerEntityModifier(fadeIn);
            XOsprite.registerEntityModifier(scaleUp);
        }
    };
    fadeOut.addModifierListener(fadeOutListener);
    XOsprite.registerEntityModifier(scaleUp);
    XOsprite.registerEntityModifier(fadeIn);

    gameScene.attachChild(XOsprite);
    gameScene.registerTouchArea(XOsprite);

    return gameScene;
}

精灵只是淡出,没有任何反应。我还希望精灵在淡入时改变到屏幕上的随机位置。帮助?

4

1 回答 1

0

如果你想并行淡入和缩放,那么你可以使用parallelEntityModifier。

同样,对于淡出和横向扩展,您可以使用 parallelEntityModifier。

要按顺序运行这两个,请使用 SequenceEntityModifier。试试这个它会工作。

于 2013-08-22T12:07:03.640 回答