我一直在创建这个简单的游戏,以获取娱乐,我遇到了一些麻烦。
设置对象下降的新速度。随着用户的分数提高,我想更改速度并立即提高速度。但是发生的事情是,当前速度只是随着我想提高的速度而添加的,所以它是因为更快的速度。
这是我的活动:
public void startTimer() {
timer = new Timer();
initializeTimerTask();
timer.schedule(timerTask, 100, 20);
}
public void stoptimertask() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
public void initializeTimerTask() {
timerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
goDown();
}
});
}
};
}
public void goDown() {
frame = (FrameLayout) findViewById(R.id.frame);
frameHeight = frame.getHeight();
boxY = (int) txtWord.getY();
boxSizeY = txtWord.getHeight();
if(scoreCount >= 0)
{
boxY += 1;
}
if(scoreCount >= 5)
{
boxY += 2;
}
if(scoreCount >= 10)
{
boxY += 3;
}
txtWord.setY(boxY);
if (boxY > frameHeight - boxSizeY) {
boxY = frameHeight - boxSizeY;
stoptimertask();
displayGameOver();
}
}
事先感谢您的任何见解或帮助!:D
if(scoreCount >= 0 && scoreCount < 5)
{
boxY += 1;
}
if(scoreCount >= 5 && scoreCount < 10)
{
boxY += 2;
}
if(scoreCount >= 10)
{
boxY += 3;
}
尝试此速度问题。