gpt4 book ai didi

android - 如何移动角色 - 尝试应用 touchDown 和 touchUp

转载 作者:行者123 更新时间:2023-11-29 21:40:36 26 4
gpt4 key购买 nike

使用示例 with the bucket 我正在尝试而不是使用

 if(Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);

使用 touchUp 和 touchDown。

所以,为了使用它们,我定义:

 Vector2    position = new Vector2();
Vector2 velocity = new Vector2();

然后:

public boolean touchDown(int x, int y, int pointer, int button) {

if (x < 800 / 2 && y > 480 / 2) {
//here?? for left movement
}
if (x > 800 / 2 && y > 480 / 2) {
//here?? for right movement
}
return true;

}

一般来说,我知道我有一个位置和一个速度。我必须更新与速度相关的位置,但我不知道该怎么做。

最佳答案

您必须使用增量时间和速度矢量每帧更新对象的位置。

像这样的东西(在渲染中):

position.set(position.x+velocity.x*delta, position.y+velocity.y*delta);

和:

public boolean touchDown(int x, int y, int pointer, int button) {

if (x < 800 / 2 && y > 480 / 2) {
//here?? for left movement
velocity.x = -10;
}
if (x > 800 / 2 && y > 480 / 2) {
//here?? for right movement
velocity.x = 10;
}
return true;
}

public boolean touchUp(int x, int y, int pointer, int button) {
velocity.x = 0;
}

关于android - 如何移动角色 - 尝试应用 touchDown 和 touchUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17220633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com