微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐