我有一个爆米花的arraylist由以下制作:
public class Popcorn
{
int posX;
int posY;
int speed;
int taps;
public Popcorn(int x, int y)
{
posX = x;
posY = y;
speed = PowerConstants.popcorn_speed;
taps = 0;
}
public void tick()
{
posY += speed;
}
public int getX()
{
return posX;
}
public int getY()
{
return posY;
}
public void addTap()
{
taps++;
}
public int getTaps()
{
return taps;
}
}
我想在这些爆米花上使用不同的通电,其中一个涉及使爆米花在屏幕上下降得更快(因此处理速度)一段时间。通电工作(定时系统也是如此);然而,它只会影响新创建的爆米花,而不会影响屏幕上已有的爆米花。以下是相关代码:
ArrayList <Popcorn> popcorns;
Image happyPopcorn;
popcorns = new ArrayList<Popcorn>();
happyPopcorn = Assets.happyPopcorn;
//This section is in the updateRunning() section of my code
if ((PowersScreen3.getDecodedChoice() == Assets.powerup_speedup && System.currentTimeMillis() - power_start_3 <= 10000) ||
(PowersScreen2.getDecodedChoice() == Assets.powerup_speedup && System.currentTimeMillis() - power_start_2 <= 10000) ||
(PowersScreen.getDecodedChoice() == Assets.powerup_speedup && System.currentTimeMillis() - power_start <= 10000)) {
//The above if-state is just checking the timing system and deciding which powerup was chosen
PowerConstants.popcorn_speed = 4;
Log.d("Powerups", "all popcorn speed up");
}
有意义的是,通过改变速度常数,新形成的爆米花的速度会发生变化。但是,我也希望arraylist中的当前爆米花也能改变它们的速度。我怎样才能做到这一点?