【发布时间】:2017-02-14 16:32:46
【问题描述】:
触球后我的分数没有增加。仅当我触摸球及其靠近屏幕中心时它才会增加。 当我的球只在 x 轴上移动并保持 y 不变时,触摸效果很好。但是当两者都增加时,只有在触摸中心时分数才会增加。
@Override
public void render () {
batch.begin();
Gdx.gl.glClearColor(1,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.draw(ball,xposi,yposi,100,100);
if(gameState==1) {
if (Gdx.input.justTouched()) {
tmp = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
textureBounds = new Rectangle(xposi, yposi, 100, 100);
if (textureBounds.contains(tmp.x, tmp.y)) {
Gdx.app.log("Click", "On Ball");
score++;
}
else {
Gdx.app.log("Click", "Not on Ball");
}
}
font.draw(batch, String.valueOf(score), 100, 300);
font.draw(batch, String.valueOf(lives), 200, 300);
xposi+=velocity;
yposi+=velocity;
if (xposi >= xmax - 100) {
velocity = -velocity;
} else if (xposi <= xmin) {
velocity = -velocity;
}
if (yposi >= ymax - 100) {
velocity = -velocity;
} else if (yposi <= ymin) {
velocity = -velocity;
}
batch.end();
}
}
【问题讨论】: