각도에서 점 (벡터 2)을 이동하고 싶습니다. 나는 내 각을 가지고있다. 하지만 저는 수학이나 libgdx에서 좋지 않습니다. 각도를 얻기 위해서 나는 이것을 사용합니다 :각도에서 점 (벡터) 이동 + Libgdx
degrees = (float) ((Math.atan2(touchPoint.x - x,
-(touchPoint.y - y)) * 180.0d/Math.PI) + 240.0f);
이제 벡터를 이동하고 싶습니다. 그러나 나는 정말로 내가해야하는 것을 모른다. .. 나는 질문을 보았다. 그러나 각도를 바꾸는 것, 옮기지 않는 것에 관해 단지 somethings가 있었다. libgdx에서이 기능이 있어야한다고 생각합니다. 도와주세요.
업데이트 : 내가 제대로 질문을 이해하고있는 경우
public class Games implements ApplicationListener {
SpriteBatch spriteBatch;
Texture texture;
float x = 160;
float y = 5;
Vector2 touch;
Vector2 movement;
Vector2 position;
Vector2 dir;
Vector2 velocity;
float speed;
float deltaTime;
@Override
public void create() {
spriteBatch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("images/1.png"));
touch = new Vector2();
movement = new Vector2();
position = new Vector2();
dir = new Vector2();
velocity = new Vector2();
speed = 5;
deltaTime = Gdx.graphics.getDeltaTime();
}
public void render() {
Gdx.gl.glClear(Gdx.gl10.GL_COLOR_BUFFER_BIT);
deltaTime += 0.5f;
spriteBatch.begin();
begin(deltaTime);
spriteBatch.draw(texture, position.x, position.y);
spriteBatch.end();
}
private void begin(float deltaTime) {
touch.set(Gdx.input.getX(), Gdx.input.getY());
position.set(x, y);
dir.set(touch).sub(position).nor();
velocity.set(dir).scl(speed);
movement.set(velocity).scl(deltaTime);
position.add(movement);
}
나는 당신이 말한 것을 할 수 있지만 문제가 있습니다. 나는'scl (...)'메소드에 접근 할 수 없다. 이 방법에 대한 도서관의 이름은 무엇입니까? – Hosein
내 libs했다. 방금 최신 버전을 다운로드하고 수정했습니다. 그러나 그것은 움직이지 않는다. 내 코드를 업데이트합니다. – Hosein
그래서 내 문제는 deltaTime에있었습니다. 나는 그것을 업데이트하지 않았다. 업데이트 후 잘 작동했습니다. tnx. p.s :하지만 더 나은 방법으로 업데이트하는 경우 나에게 말하십시오. D – Hosein