我正在制作一场比赛,现在我想要实现一个显示你时代的时钟/天文台。
我想在ChangeableText中显示实际时间,在另一个ChangeableText中显示最佳单圈时间。
如何每秒或每0.1秒更新一次?
我怎样才能检测到一圈结束时的情况,例如终点线(确定的x和y位置)?
感谢。
答案 0 :(得分:7)
试试这个:
int count=60;
youScene.registerUpdateHandler(new TimerHandler(1f, true, new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
count--;
youchangeabletext.setText(String.valueof(count));
if(count==0){
youScene.unregisterUpdateHandler(pTimerHandler);
//GameOver();
}
pTimerHandler.reset();
}
}));
参数“1f”是在这种情况下运行方法1f = 1秒的时间,现在每秒运行方法,当计数为“0”时,方法将从游戏中移除。
现在为了检测一圈完成,你可以扩展你车的Sprite类:
public class Car extends AnimatedSprite {
public Car(final float pX, final float pY, final TiledTextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
super(pX, pY, pTextureRegion, pVertexBufferObjectManager);
}
//the method onManagedUpdate run in milliseconds
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
//for example when car is in the position 100 in x
if(this.getX()>=100){
//lap finish
}
super.onManagedUpdate(pSecondsElapsed);
}
}
答案 1 :(得分:0)
int time=110;
timerText = new Text(700, 440, resourcesManager.font, "10", new TextOptions(HorizontalAlign.RIGHT), vbom);
TimerHandler mTime = new TimerHandler(0.1f,true, new ITimerCallback(){
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
// TODO Auto-generated method stub
time--;
timerText.setText(""+(time/10));
if(time==0){
//Do something
}
}
});