【发布时间】:2011-11-21 06:43:51
【问题描述】:
我想将我的Sprite 移动到AndEngine 中进行抛射运动。
谁能用一段代码帮助我解决这个问题?不幸的是,我在AndEngine 中没有看到有关预测的示例。
【问题讨论】:
我想将我的Sprite 移动到AndEngine 中进行抛射运动。
谁能用一段代码帮助我解决这个问题?不幸的是,我在AndEngine 中没有看到有关预测的示例。
【问题讨论】:
我怀疑您正在寻找的是 UpdateModifier。
您希望您的 Sprite 如何移动?您是希望它找到通往目的地的路径,还是只是想在屏幕上保留一些东西?你在用相机吗?所有这些都将决定你应该如何让你的 Sprite 移动。
这是一个关于 UpdateModifiers 的链接:
Update Handlers - Using their Power!
这就是你要找的吗?
【讨论】:
对于弹丸移动,您可以使用物理处理器,然后您可以操纵加速度和速度使其像弹丸一样移动...
projectile=new Sprite(X,Y, ProjectileTextureRegion);
physprojectile = new PhysicsHandler(projectile);
projectile.registerUpdateHandler(physprojectile);
physprojectile.setVelocityX(Xvelocity);
physprojectile.setVelocityY(Yvelocity);
pyhsprojectile.setAcceleration(Accelration) //negative acceleration
【讨论】:
基本上,您可以在精灵(或任何实体)上使用 registerEntityMofidier:Andengine EntityModifierExample
例子:
sprite.registerEntityModifier(new MoveModifier(TIME_IN_SECOND, fromX, toX, fromY, toY));
【讨论】:
stakesprite.registerEntityModifier(new RotationModifier(0.1f, 0.0f,(float) ((360.0f/Math.PI)*Math.atan(velY/velX))));
stake=PhysicsFactory.createCircleBody(this.mPhysicsWorld, stakesprite, BodyType.DynamicBody, FIXTURE_DEF);
//stake = PhysicsFactory.createBoxBody(this.mPhysicsWorld, stakesprite, BodyType.DynamicBody, FIXTURE_DEF);
stake.setBullet(true);
stake.setLinearVelocity(new Vector2(velX, velY));
stake.setSleepingAllowed(true);
mScene.attachChild(stakesprite);
【讨论】: