0

我有一个问题,玩家释放一个强力攻击,这个强力攻击必须移动到某个位置然后分离,我怎么能做到这一点?我尝试使用 setvelocity 但效果不佳...请帮助!

好的,这是我按下按钮时调用的攻击方法:

公共无效powerattack(){

    float startBulletX = player.getX() + 30; //Get X position of character body
    float startBulletY = player.getY();      //Get Y position of character body

    final Sprite bullet = new Sprite(startBulletX, startBulletY,
            resourcesManager.special_attack, vbom);  //The special attack sprite

    final FixtureDef bulletFixtureDef1 = PhysicsFactory.createFixtureDef(0,
            0, 0, false, CATEGORYBIT_KNIFE, MASKBIT_KNIFE, (short) 0);
    this.mBulletBody = PhysicsFactory.createBoxBody(physicsWorld, bullet,
            BodyType.DynamicBody, bulletFixtureDef1);  

    mBulletBody.setLinearVelocity(20f,0);

    this.physicsWorld.registerPhysicsConnector(new PhysicsConnector(bullet,
            this.mBulletBody, true, false));


    this.attachChild(bullet);  

}

当我运行此代码时,特殊攻击体移出屏幕......我想将强力攻击限制在某个位置,即距离角色几远。

4

1 回答 1

0

我得到了解决方案,我使用了 onUpdate 方法并在该 onupdate 方法中将代码设置为不可见,这是我的代码:)

public void powerattack() {

    float startBulletX = player.getX() + 30;
    float startBulletY = player.getY();

    final Sprite ray = new Sprite(startBulletX, startBulletY,
            resourcesManager.special_attack, vbom);
    final Vector2 velocity = Vector2Pool.obtain(20f, 0);
    final FixtureDef rayFixtureDef1 = PhysicsFactory.createFixtureDef(0, 0,
            0, false, CATEGORYBIT_RAY, MASKBIT_RAY, (short) 0);
    this.mRayBody = PhysicsFactory.createBoxBody(physicsWorld, ray,
            BodyType.DynamicBody, rayFixtureDef1);

    this.mRayBody.setLinearVelocity(velocity);
    Vector2Pool.recycle(velocity);

    this.physicsWorld.registerPhysicsConnector(new PhysicsConnector(ray,
            this.mRayBody, true, false) {
        /*Update method keeps checking whether the power attack reached the specific distance*/
        @Override
        public void onUpdate(float pSecondsElapsed) {

            if (ray.getX() >= (player.getX() + 300)) {

                ray.setVisible(false);
                ray.setIgnoreUpdate(false);

            }
            super.onUpdate(pSecondsElapsed);
            camera.onUpdate(0.1f);
        }
    });

    mRayBody.setUserData("power");
    this.attachChild(ray);

}
于 2013-08-21T12:07:45.180 回答