android – 如何在AndEngine中制作天文台?

我正在制作一个赛车游戏,现在我想要实现一个显示你的时间的时钟/天文台表.

我想在ChangeableText中显示实际时间,在另一个ChangeableText中显示最佳单圈时间.

我如何每秒或每0.1秒更新一次?

我怎样才能检测到一圈结束时的情况,例如在终点线(确定的x和y位置)?

谢谢.

解决方法:

试试这个:

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);
            }
        }

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...