2016-07-25 2 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 않았다 - (나머지)에 대한. – Martacus