Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queue multiple entity modifiers in AndEngine

I'm trying to have a sprite ("pointer" below) along two paths, one after the other. Here is my code:

    scene.attachChild(pointer);

    pointer.clearEntityModifiers();
    pointer.registerEntityModifier(new MoveModifier(
        1.0f, 540, 960, 1000, 1000,
        new IEntityModifierListener() {
            public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {}
            public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                clickSound.play();

                pointer.clearEntityModifiers();
                pointer.registerEntityModifier(new MoveModifier(
                    1.0f, pointer.getX(), pointer.getY(), 500, 2500,
                    new IEntityModifierListener() {
                        public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {}
                        public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
                            pointer.clearEntityModifiers();
                            pointer.detachSelf();
                        }
                    },
                    EaseCubicInOut.getInstance()
                ));
            }
        },
        EaseCubicInOut.getInstance()
    ));

The pointer moves along the first path as expected, and then the clickSound plays, and then nothing happens. The second MoveModifier doesn't have any effect. What am I doing wrong here?

like image 204
Ben Dilts Avatar asked Dec 20 '25 11:12

Ben Dilts


1 Answers

I'm not sure why your code is not working, but I think you can achieve the same thing using the SequenceEntityModifier:

scene.attachChild(pointer);

    pointer.clearEntityModifiers();
    pointer.registerEntityModifier(new SequenceEntityModifier(
        new MoveModifier#1(...),
        new MoveModifier#2(...)));
like image 192
I'm a frog dragon Avatar answered Dec 22 '25 22:12

I'm a frog dragon