core.time Duration how to get units in double/float format?

wobbles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 19 07:25:58 PST 2016


On Tuesday, 19 January 2016 at 14:07:50 UTC, Borislav Kosharov 
wrote:
> On Monday, 18 January 2016 at 12:46:31 UTC, Jonathan M Davis 
> wrote:
>> [...]
>
> I want to use float time in a game where I call the update 
> method passing the delta time as float seconds. It's more easy 
> to multiply the dt with a speed constant meaning how much the 
> object will move after 1 second. Such float delta time is used 
> in many game engines and it's somewhat standart way of doing 
> it. Also the method you wrote returns a string and I need a 
> float to multiply it with a number.
> Thanks for the reply anyway

Checkout out how DSFML handles this.
You simply pass around a Clock object that you can restart every 
frame using

clock.restart();

You then call your update function with 
update(Clock.getElapsedTime());
Then in each objects update(Time t) method you just get the time 
in whatever unit you want. Works pretty well.

http://www.dsfml.com/


More information about the Digitalmars-d-learn mailing list