2016-07-25 8 views
0

私は弾丸を一点に移動させ、さらに移動させます。その唯一の演技は本当に本当に奇妙です。その0,0の場所が左下ではなく左上にあると思うように。ピクセルで位置をエンティティに移動する - libgdx - ベクトル計算

これはコードです:

float speed = 100; 

    Vector2 direction; 
    Vector2 thisPos = new Vector2(getX(), getY()); 
    Vector2 mousePos; 

    public Bullet(){ 
     super(); 
     setSprite(sprite); 
     setX(0); setY(0); 
     float dx = Gdx.input.getX() - getX(); 
     float dy = Gdx.input.getY() - getY(); 
     mousePos = new Vector2(Gdx.input.getX(), Gdx.input.getY()); 
     direction = new Vector2(dx, dy); 
     //sprite.setRotation(direction.angle(thisPos)); 
     direction.nor(); 
    } 

    public void update(){ 
     Vector2 dirAd = new Vector2(direction); 
     thisPos.x += dirAd.x * speed * Gdx.graphics.getDeltaTime(); 
     thisPos.y += dirAd.y * speed * Gdx.graphics.getDeltaTime(); 
     setPosition(thisPos.x, thisPos.y); 
     super.update(); 
    } 

私は誰かが私はこれで間違っていたものを私に役立つことを願って。

答えて

1

Gdx.input.getX()およびgetY()は、左上を0,0として処理します。 getX()メソッドから:

"画面の原点は左上隅です。"

カメラの非プロジェクション方法を調べる必要があります。この方法では、画面の入力座標を「ワールド」空間に変換します。

+0

ええ、それはマウスの座標です。スプライトは左下が0,0だと考えます。それはなぜその奇妙な演技でなければならないのだろうか。編集:修正されました。ちょうど720 - (残りの)dyのでした。 – Martacus

関連する問題