core.time Duration how to get units in double/float format?
Borislav Kosharov via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 19 10:11:59 PST 2016
On Tuesday, 19 January 2016 at 15:25:58 UTC, wobbles wrote:
> 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/
Yes that's exactly what I'm using. But they changed it to return
a Duration instead of Time and that broke my code. See the source
https://github.com/Jebbs/DSFML/blob/master/src/dsfml/system/clock.d#L65
More information about the Digitalmars-d-learn
mailing list