我正在制作一个游戏,用户可以按下通电。当用户按下通电时,我希望通电运行3秒钟,然后所有受影响的变量将恢复正常。我尝试了下面的代码(专注于速度图像在屏幕上比正常情况下快3秒):
if (x2 >= power_remove_X && x2 < (power_remove_X + power_remove.getWidth())
&& y2 >= power_remove_Y && y2 < (power_remove_Y + power_remove.getHeight())) {
//image tapped
power_start = System.currentTimeMillis();
//Find out which power up and apply the effect
Log.d("GameScreen", "Power 3 Selected");
power_comparer(PowersScreen3.getDecodedChoice());
}
private void power_comparer(Image decodedChoice) {
// TODO Auto-generated method stub
long currentTime = System.currentTimeMillis();
long refresh = power_start + 3000;
if (decodedChoice == Assets.powerup_speedup) {
Log.d("Powerup - Refresh", Long.toString(refresh));
while (currentTime < refresh) {
PowerConstants.popcorn_speed = 4;
PowerConstants.popcorn_color_speed = 10;
PowerConstants.popcorn_mad_speed = 4;
speeduptapped = true;
//Log.d("Powerups", "all popcorn speed up");
}
但是,当我按下通电时,此代码会导致我的游戏冻结。我哪里错了?