如何用PathModifier()创建一个循环?

时间:2012-02-24 13:32:24

标签: android andengine

AndEngine。我在游戏中使用Path()和PathModifier()。

path = new Path(2).to(10, 10).to(100, 100);
sprite.registerEntityModifier(new LoopEntityModifier(new PathModifier(1f, path, null, new IPathModifierListener() {


            public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity) {                  
            }


            public void onPathWaypointStarted(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) {                   
            }


            public void onPathWaypointFinished(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) {
            }


            public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity) {               

            }
    }, EaseSineInOut.getInstance())));

它有效,但我不想要无限循环。然后我改变了方法onPathFinished():

public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity) {               
                pEntity.clearEntityModifiers();
            } 

但之后我的精灵完成了1次循环并返回第一个位置(10,10)并停止。 那么,如何在1循环后停止位置(100,100)?

1 个答案:

答案 0 :(得分:3)

您应该在yourSprite.setPosition(100,100)

中使用onPathFinished()