1

Andengine でゲームを作成していますが、回転するスプライトからの撮影で 2 日間立ち往生しています。私は幾何学のヒーローではなく、すでに先生に質問していますが、彼も正しい答えを教えてくれませんでした。それで、誰が数学のヒーローで、私を助けてくれます:)。

問題は、弾丸が砲塔の前に出現する場所を特定できないことです。弾丸が行かなければならない目的地を回転させて見つけることは問題ありません。スポーンポイントだけです。

この質問のために多くの面白くないコードを削除しました。

さて、ここにタレット回転からの回転コードがあります:

public class AlienShip extends Ship {

public static final float BASE_ROTATION_SPEED = 0.25f;
public static final int DEFAULT_IMAGE_ROTATION = 90; //90 degrees 



protected PlayerShip ship;


public AlienShip(float pX, float pY, TextureRegion pTextureRegion,
        VertexBufferObjectManager pVertexBufferObject,FixedStepPhysicsWorld pw, int baseDurability) {

    super(pX, pY, pTextureRegion, pVertexBufferObject, pw, baseDurability);
}

public void rotateToPlayer()
{
    if (ship != null) {

        float dX = this.getX() - ship.getX();
        float dY = this.getY() - ship.getY();

        float angle = (float) Math.atan2(-dY, dX);

        float rotation = MathUtils.radToDeg(angle) + DEFAULT_IMAGE_ROTATION;

        RotationModifier rotMod = new RotationModifier(BASE_ROTATION_SPEED, this.getRotation(), rotation);
        this.registerEntityModifier(rotMod);

    }

}

public void rotateToInitPos() {

    RotationModifier rotMod = new RotationModifier(BASE_ROTATION_SPEED, this.getRotation(), 0);
    this.registerEntityModifier(rotMod);
}
}

上記のコードは正常に動作しています。

これは、船が発射しているレーザーからのコードです。コメントを読んで、魔女の部分が機能していないことを確認してください。

public class GameScene extends Scene {

protected PlayerShip playerShip;



private SpawnCallback createShootCallback(boolean player) {

 return new SpawnCallback() {
            @Override
            public void spawn(SpawnTimer spawnTimer) {
                PhysicsSprite laser = null;
                AlienShip alienShip = (AlienShip) spawnTimer.getPhysicsSprite();


                    // laser = alienMissilePool.getMissileFromPool(x,y)
                    //spawn the laser in front of the rotating ship [Not working :( ]
                    laser = alienMissilePool.getMissileFromPool( ( alienShip.getX() * FloatMath.cos(MathUtils.degToRad(rotation)) - ((1280 - alienShip.getY() - alienShip.getY()/2) * FloatMath.sin(MathUtils.degToRad(rotation)) ) ) ,
                                                              ( alienShip.getX() * FloatMath.sin(MathUtils.degToRad(rotation)) + ((1280 - alienShip.getY() - alienShip.getY()/2) * FloatMath.cos(MathUtils.degToRad(rotation)) ) ) );

                    //Set the rotation from the laser same to the ship rotation [Is working perfectly].
                    float rotation = alienShip.getRotation();
                    laser.setRotation(rotation);

                    //Set laser speed and direction [Is working perfectly]
                    float pX = 0.01f * (playerShip.getX() - laser.getX());
                    float pY = 0.01f * (playerShip.getY() - laser.getY());

                    laser.getSpriteBody().setLinearVelocity(pX, pY);


                spawnPhysicsSprite(laser);
                }

        };
}

}

これは、x 軸と y 軸の値を示す図面へのリンクです。 http://s24.postimg.org/citz29339/gamescene.png

ありがとうございました!

4

1 に答える 1