User Tag List

Results 1 to 6 of 6

Thread: Correct way to calculate a delta time on MMF?

  1. #1
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    1,052
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Correct way to calculate a delta time on MMF?

    Lately, I have been switching some of the movements assigned to my active objects from MMF-builtin ones to manual ones.

    So, instead of using say a 8-direction movement I add or substract a value times a deltatime. The way I have calculated the latter is timer minus OldTime (being OldTime equal to timer once DeltaTime is updated).

    Now, the thing is that 8-direction movement is FPS independent when I click Timer-based movement. But my manual movement is not.

    If I set a target update of 1/60, then my delta time -in a normal situation- will be 0.016667. And if I set it say to 30, then it will be 0.33334. But in both, after a second, the value added to a speed variable should be the same (like in the 8-direction movement). This is not the case. Doing something like this Position += 100 * DeltaTime gives different results depending on the FPS what is weird.

    Adding 100 * .016667 to a position 60 times per second should result in the same value than adding 100 * .033334 to that position 30 times per second. In MMF, for 60 FPS and 30 FPS, respectively, results are different. It's seems as if the update method were called more times than the target FPS but the timer where bound to the draw call.

    So how can I tie my custom movement to the timer and update call used for the 8-direction movement? I mean, how can I calculate the delta time between update calls and not draw calls in MMF?

    EDIT: this happens in all MMF runtimes.

  2. #2
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    1,052
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Correct way to calculate a delta time on MMF?

    Found it!

    As I was dividing (timer - OldTime) by 1000.0, it gives different decimal results for addition and substraction of constant values multiplied by the DeltaTime, so it moved faster to the left side than the right one of the screen. A math co-processor innacuracy, maybe?

    In short, it has nothing to do with the FPS. Please disregard this thread.

  3. #3
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleMac Export ModuleSWF Export Module
    AndyH's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,445
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Correct way to calculate a delta time on MMF?

    I've actually found this to work out well for me. I've been testing on a really old device and a new device which gives a good contrast in performance.

    Set gaDelta = 0.8+(timer-gcLastTimer)/(FrameRate+0.0)
    Set gcLastTimer = timer

    Where gaDelta and gcLastTimer are global values.

    Then in game for movements I multiply this value they'd normally move by gaDelta, eg set x=x +1 * gaDelta


    Andy H @ ovine.net
    Awful Jokes - a new cartoon every day: http://awful.ovine.net/
    Ovine's games: http://www.ovine.net

  4. #4
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    1,052
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Correct way to calculate a delta time on MMF?

    Yes, it works. The thing is that it gives me diferent results if I do X = X + 1 gaDelra than X = X - 1 * gaDelta.

    One question, why are you adding "+ 0.0)" when dividing by the Framerate? Is it to avoid a bug with the expression editor or something else?

  5. #5
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleMac Export ModuleSWF Export Module
    AndyH's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,445
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Correct way to calculate a delta time on MMF?

    Well you know MMF will default to working in integer maths unless it thinks you are working with real numbers? It may not actually be needed as I have a reference to a real in the form of 0.8. So it may be as a result of a bad habit on my part
    Andy H @ ovine.net
    Awful Jokes - a new cartoon every day: http://awful.ovine.net/
    Ovine's games: http://www.ovine.net

  6. #6
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Jan 2009
    Posts
    1,052
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Correct way to calculate a delta time on MMF?

    I see. For globals maybe a solution for MMF3 is setting the initial value to 0.0, and with that the global gets marked and MMF will always return a floating point number.

Similar Threads

  1. Delta Time acting wierd?
    By Outcast in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 22nd November 2013, 02:54 AM
  2. How to calculate RGB coefficient?
    By Outcast in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 4th March 2012, 09:34 PM
  3. Date & Time and Calculate Text Rect
    By Fanotherpg in forum XNA Export Module Version 2.0
    Replies: 2
    Last Post: 15th May 2011, 04:25 PM
  4. calculate the total hour time from 1440 munutes
    By daniele in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 20th February 2009, 10:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •