如何Libgdx跟踪时间(机器人) [英] How to track time in Libgdx(android)

查看:106
本文介绍了如何Libgdx跟踪时间(机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏,我想用户收集的奖金后,每70 seconds..here是我的code跟踪的时间,但我无法做得到的solution..I是新来的Libgdx请帮助我这个我抓我的头为过去40天,这..:(

 长gotime;
长targettime;
浮动的timeleft;
 

/ -------------------在我的渲染功能--------- /

  gotime =(长)Gdx.graphics.getDeltaTime();
gotime = System.currentTimeMillis的();
    targettime = gotime + 70;
如果(的timeleft大于0)
 {
的timeleft = 70  - (gotime  -  Gdx.graphics.getDeltaTime())/ 1000; // targettime-gotime;
        的System.out.println(------------+的timeleft);
    }
 

解决方案

该屏幕的渲染(浮动三角洲)功能让你的时间,自上渲染(..)调用已通过,以毫秒为单位的数量,浮法

因此​​,计时器也只是以下内容:

 公共类GameScreen实现屏幕
{
    私人浮动bonusTimer;

    公共GameScreen()
    {
        bonusTimer = 70F;
    }

    @覆盖
    公共无效渲染(浮动三角洲)
    {
        为(浮动ITER = 0; ITER<三角洲; ITER + = 0.125f)
        {
            浮iterNext = ITER + 0.125f;
            浮动currentDelta;
            如果(iterNext>三角洲)
            {
                currentDelta =三角洲 -  ITER;
            }
            其他
            {
                currentDelta = iterNext  -  ITER;
            }

            bonusTimer  -  = currentDelta;
            如果(bonusTimer&所述; = 0)
            {
                奖金();
                bonusTimer + = 70F;
            }
            ...
        }
    }
    ...
}
 

你会想要做的是设置此GameScreen的一个实例是激活屏幕在游戏中的后裔,你的核心类。看看这里的更多信息: https://github.com/libgdx/libgdx /维基/扩展的最简单的游戏

根据需要

调整逻辑(例如,具有自己的GameModel是在比赛开始自行重置)。

I am developing a game in which i want user to collect bonus after every 70 seconds..here is my code to track time but i am unable do get the solution..I am new to Libgdx please help me with this i am scratching my head for past 4 days for this.. :(

    long gotime;
long targettime;
float timeleft;

/-------------------In my render function---------/

gotime=(long) Gdx.graphics.getDeltaTime();
gotime=System.currentTimeMillis();
    targettime=gotime+70;
if(timeleft>0)
 {
timeleft=70 - (gotime - Gdx.graphics.getDeltaTime()) / 1000;//targettime-gotime;
        System.out.println("------------"+timeleft);
    }

解决方案

The Screen's render(float delta) function gives you the amount of time that has passed by since the last render(..) call, in miliseconds, as float.

Therefore, a timer would just be the following:

public class GameScreen implements Screen
{
    private float bonusTimer;

    public GameScreen()
    {
        bonusTimer = 70f;
    }

    @Override
    public void render(float delta)
    {
        for(float iter = 0; iter < delta; iter += 0.125f)
        {
            float iterNext = iter + 0.125f;
            float currentDelta;
            if(iterNext > delta)
            {
                currentDelta = delta - iter;
            }
            else
            {
                currentDelta = iterNext - iter;
            }

            bonusTimer -= currentDelta;
            if(bonusTimer <= 0)
            {
                bonus();
                bonusTimer += 70f;
            }
            ...
        }
    }
    ...
}

What you would want to do is set an instance of this GameScreen to be the active Screen in the descendant of the Game, your core class. Look here for more info: https://github.com/libgdx/libgdx/wiki/Extending-the-simple-game

Adjust the logic as needed (for example, having your own GameModel that resets itself upon the start of the game).

这篇关于如何Libgdx跟踪时间(机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆