Android 如何使用andengin中的移动修改器将精灵从a点移动到B点?

Android 如何使用andengin中的移动修改器将精灵从a点移动到B点?,android,andengine,Android,Andengine,我是游戏开发新手。我使用和引擎开发游戏。当用户触摸屏幕时,我创建精灵(例如:-击中敌人的箭头)使用场景触摸监听器。我使用移动修改器移动箭头。但箭头不显示在屏幕上。当我在日志中触摸屏幕时,cat显示 记录Cat错误 10-29 18:36:41.913: V/AndEngine(25704): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 0 item not ye

我是游戏开发新手。我使用和引擎开发游戏。当用户触摸屏幕时,我创建精灵(例如:-击中敌人的箭头)使用场景触摸监听器。我使用移动修改器移动箭头。但箭头不显示在屏幕上。当我在日志中触摸屏幕时,cat显示

记录Cat错误

10-29 18:36:41.913: V/AndEngine(25704): org.andengine.input.touch.TouchEvent$TouchEventPool<TouchEvent> was exhausted, with 0 item not yet recycled. Allocated 1 more.

10-29 18:36:41.913: V/AndEngine(25704): org.andengine.util.adt.pool.PoolUpdateHandler$1<TouchEventRunnablePoolItem> was exhausted, with 0 item not yet recycled. Allocated 1 more.
10-29 18:36:41.913:V/AndEngine(25704):org.AndEngine.input.touch.TouchEvent$TouchEventPool已用完,0项尚未回收。再分配1个。
10-29 18:36:41.913:V/AndEngine(25704):org.AndEngine.util.adt.pool.PoolUpdateHandler$1已用完,0项尚未回收。再分配1个。
代码

private void shootProjectile(final float pX, final float pY) {

        int offX = (int) (pX - player.getX());
        int offY = (int) (pY - player.getY());
        if (offX <= 0)
            return;

        final Sprite projectile;
        // position the projectile on the player
        projectile = new Sprite(player.getX(), player.getY(),
                arrow.deepCopy(),mEngine.getVertexBufferObjectManager());
        mainScene.attachChild(projectile);

        int realX = (int) (camera.getWidth() + projectile.getWidth() / 2.0f);
        float ratio = (float) offY / (float) offX;
        int realY = (int) ((realX * ratio) + projectile.getY());

        int offRealX = (int) (realX - projectile.getX());
        int offRealY = (int) (realY - projectile.getY());
        float length = (float) Math.sqrt((offRealX * offRealX) + (offRealY * offRealY));
        float velocity = 480.0f / 1.0f; // 480 pixels / 1 sec
        float realMoveDuration = length / velocity;

        // defining a move modifier from the projectile's position to the
        // calculated one
        MoveModifier mod = new MoveModifier(realMoveDuration,projectile.getX(), realX, projectile.getY(), realY);
        projectile.registerEntityModifier(mod);

        /*projectile.registerEntityModifier(modifier);

        PhysicsHandler handler = new PhysicsHandler(projectile);

        projectile.registerUpdateHandler(handler);

        handler.setVelocity(realX,realY);*/

        projectilesToBeAdded.add(projectile);
        // plays a shooting sound
    }
private void shootsheet(最终浮动pX,最终浮动pY){
intoffx=(int)(pX-player.getX());
intoffy=(int)(pY-player.getY());

如果(offX有两件事是有帮助的:

  • 这些错误消息是警告级别的消息,而不是错误。它们是andengine的正确操作。当触摸池中没有触摸时,它会在创建新触摸时发出警告。在触摸池中有一些触摸后,它们会被回收,因此只有当所需触摸次数超过触摸池中的触摸次数时,才会出现该消息小结:别担心这个

  • 当您创建sprite时,我看到TextureRegion参数“Arrow.deepCopy()”有点奇怪。我猜该方法不会返回有效的TextureRegion,因此不会显示箭头。由于任意数量的精灵都可以使用相同的TextureRegion,因此我建议只使用对箭头纹理的标准引用

  • 问题的范围将是两件事中的一件:没有纹理,或者箭头被放置在屏幕外。因此,首先将精灵放置在您知道它将被看到的地方,没有修改器。如果您看到它,您的纹理是好的。 如果纹理是好的,那么修改器中的位置是坏的,所以请再次检查您的数学,然后重试