【发布时间】:2012-01-15 06:47:23
【问题描述】:
我在 andEngine 中使用这个 TimerHandler 在特定时间生成精灵..
mScene.registerUpdateHandler(new TimerHandler(0.02f, true, new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
addSpriteTime1 += 2; // because timer update = 0.02 seconds
if (addSpriteTime1 == nextSprite1Time) {
addFace();
addSpriteTime1 = 0;
}
addSpriteTime2 += 2;
if (addSpriteTime2 == nextSprite2Time) {
addFace2();
addSpriteTime2 = 0;
}
addSpriteTime3 += 2;
if (addSpriteTime3 == nextSprite3Time) {
addFace3();
addSpriteTime3 = 0;
}
}
}));
现在我在类级别声明了 int 变量..
private int nextSprite1Time = 100;// initial value, could be changed during game
private int nextSprite2Time = 100;
private int nextSprite3Time = 100;
然后我有一个方法可以让我改变速度或 nextSpriteTimes。
private void speed(int f, int g, int h){
this.nextSprite1Time = f;
this.nextSprite2Time = g;
this.nextSprite3Time = h;
Log.e("Time Changed", String.valueOf(this.nextSprite1Time+ "," + this.nextSprite2Time + ","+ this.nextSprite3Time));
}
问题是当我尝试改变速度时..
speed(30, 50, 70);
它只是一起停止,现在添加了精灵,
有没有人知道我在哪里做错了或者可以做不同的事情?
【问题讨论】: