Queue multiple entity modifiers in AndEngine

时光总嘲笑我的痴心妄想 提交于 2019-12-06 02:46:52

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(...)));

My first guess woud be, that the code after pointer.clearEntityModifiers(); isn't executed anymore, since it unregisters the modifiers. I am just thinking out loud here, so please tell me if I am wrong. Maybe you can try logging something to see if the method returns after this line. Something like:

pointer.clearEntityModifiers();
Log.v("EntityModifier", "the method continues...");

I always find it hard to manage internal class definitions, because of the state of the variables that are accessed from inside. Like in your case the pointer. If nothing else works, you could still try to do it all in one run. So instead of disposing the first modifier listener and registering another, create your own Listener, with a flag somewhere to tell it what to do and reuse that listener:

public class MyModifierListener extends IEntityModifierListener{

    private Pointer pointer;   // declare your pointer, so you have a reference within the listener
    private boolean firstRun;  // a flag to check if it is the first time the modifier is used

    public MyModifierListener(Pointer pointer){
        super();
        this.pointer = pointer;  // init the pointer within the constructor
        this.firstRun = true;    // should be true the first time
    }

    public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
    }

    public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
        if(firstRun){
             clickSound.play();
         firstRun=false;
             pointer.registerEntityModifier(new MoveModifier(1.0f, pointer.getX(), pointer.getY(), 500, 2500, this), EaseCubicInOut.getInstance());
        }else{
             pointer.detachSelf();
        }
    }
}

And to use it something like that:

MyModifierListener myListener = new MyModifierListener(pointer);
pointer.registerEntityModifier(new MoveModifier(1.0f, 540, 960, 1000, 1000,     myListener), EaseCubicInOut.getInstance());

I couldn't test this, so these are just wild guesses. Tell me if you find something.

regards Christoph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!