Finish上的registerEntityModifier

时间:2012-11-09 18:46:34

标签: android andengine

我刚开始使用AndEngine,

我正在移动这样的精灵:

if(pValueY < 0 && !jumping) {

                        jumping = true;

                        // User is currently holding the UP direction
                        // get the player entity (used to apply entity modifier, and get the current X position
                        final Entity playerEntity = (Entity) physicsHandler.getEntity();

                        // set the jump duration, set the starting x position, and how high the jump will be
                        final float jumpDuration = 8;
                        final float startX = playerEntity.getX();
                        final float jumpHeight = 40;

                        // set the move modifiers and set it as a sequence
                        final MoveYModifier moveUpModifier = new MoveYModifier(jumpDuration / 2, startX, startX - jumpHeight); 
                        final MoveYModifier moveDownModifier = new MoveYModifier(jumpDuration / 2, startX + jumpHeight, startX);
                        final SequenceEntityModifier modifier = new SequenceEntityModifier(moveUpModifier, moveDownModifier);

                        // apply modifier
                        playerEntity.registerEntityModifier(modifier);

                    }
                    else {

                        // basically if the user presses left or right this should occur
                        physicsHandler.setVelocityX(pValueX * 10);
                        distance += pValueX;
                    }

我的问题是如何在registerEntityModifier函数完成后将跳转设置为false? (在玩家完成跳跃后)

谢谢!

1 个答案:

答案 0 :(得分:2)

使用andengine的onModifierFinished()方法

    @Override
    protected void onModifierFinished(IEntity pItem)
    {
            super.onModifierFinished(pItem);
            // Your action after finishing modifier
    }

使用此link了解更多详情..,。