Question

I am trying to make a sprite move using MoveByModifier in Andengine. I want it to keep repeating after the modifier has finished but i am unable to achieve that. Following is my code if anyone can help...

MoveByModifier mod1 = new MoveByModifier(20, 150, 400){
        @Override
        protected void onModifierFinished(IEntity pItem) {
            super.reset(); 
        }
    };

Sprite.registerEntityModifier(mod1);
mMainScene.attachChild(Sprite);

I also tried LoopEntityModifier but still it does not repeat... I cant understand why?

Sprite.registerEntityModifier(new LoopEntityModifier(mod1));
Was it helpful?

Solution

If you want repeating moving sprite from start position, you can use

MoveModifier mod1 = new MoveModifier(20,Sprite.getX(), Sprite.getY(), Sprite.getX()+150, Sprite.getY()+400);
Sprite.registerEntityModifier(new LoopEntityModifier(mod1));

Repeating MoveByModifier continues moving from current coordinates.

OTHER TIPS

No need to reset the modifier after finish it.You have to remove super.reset(); inside onModifierFinished method. Because when you call this, it removes the applied modifier from the Sprite.

For repeating the sprite from old postion to new one, write like

  MoveModifier moveModifier= new MoveModifier(20,Sprite.getX(), Sprite.getY(), Sprite.getX()+150, Sprite.getY()+400);
Sprite.registerEntityModifier(new LoopEntityModifier(moveModifier));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top