Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Time based animation? — Gideros Forum

Time based animation?

MichalMichal Member
edited March 2012 in Suggestions & requests
Hello, as a new user of giderosmobile (just found it 2 days ago), looking at the API, I can see there is no simple solution for time-based animations. But the problem is there are many devices with different processor speed, some of them overclocked (faster), in battery-saving mode (slower) etc, so I think there is a need for one.
I suggest adding a parameter to indicate how much time has passed since last frame. So, for example:

function Ball:onEnterFrame(event)
local dt=event.dt
local speed=100
-- self:setX(self:getX() + 1) -- frame based
self:setX(self:getX() + speed*dt) --time based
end

What do you think?
Also, related question: what happens with running timers when the application is suspended? Are they "frozen" or not? I could not find info on this.

Comments

  • MikeHartMikeHart Guru
    edited March 2012
    How about using

    event.deltaTime or event.time ?

    :D

    And I know, even.time is nowhere mentioned in the docs and deltaTime only inside a code sample there.
  • Is there such thing? I could not spot it in the docs. Anyways, I can see that os.timer() has good resolution, so that could be used also. Thanks for pointers.
  • Yes they exist. Or I wouldn't have told you. I use them all the time.

    Likes: chipster123

    +1 -1 (+1 / -0 )Share on Facebook
  • atilimatilim Maintainer
    edited March 2012

    Also, related question: what happens with running timers when the application is suspended? Are they "frozen" or not? I could not find info on this.
    No, timers are not frozen. You can use the functions Timer.pauseAll() and Timer.resumeAll() with the events Event.APPLICATION_SUSPEND and Event.APPLICATION_RESUME. (You can look at the example "Hardware/Application Lifecycle")

    But I think it's better to pause the timers when application moves to background by default.

    Likes: GregBUG

    +1 -1 (+1 / -0 )Share on Facebook

  • But I think it's better to pause the timers when application moves to background by default.
    i agree. :)

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    ok then :) I'm adding this issue to bug tracker.
  • @atilim Personally I don't care where Gideros is heading to but for other developers this automatic approach could kick them in the back. So what if you need timers to run in the background? From IOS 4 on, apps can run in the background and act on the outside world. For a game it makes not much sense but for other apps it can be useful. I would rather take the approach here to leave it up to the developer what he/she wants. But if Gideros considers itself a game only framework, then it is better to have this automatic approach.
  • atilimatilim Maintainer
    @MikeHart currently, we don't support timers running in background. assume that one creates a timer that will be dispatched after 10 seconds and then suspends the app. If he/she waits for 11 seconds and then resumes the app, the timer event will be dispatched right after resuming.

    And currently I don't know if we ever support for background running timers.
  • MikeHartMikeHart Guru
    edited March 2012
    @atilim
    :-O
    So you don't need to pause timers when the app will be going into the background? They get paused automatically! Before you said the opposite. You can really confuse the people.
  • atilimatilim Maintainer
    :D

    I mean...

    Assume that you create a 10 second timer then suspend the app. After that wait >11 seconds then resume the app. After resuming your timer should be dispatched after 10 seconds, not just after resuming. (I hope I explained this time)
  • @atilim Personally I don't care where Gideros is heading ... But if Gideros considers itself a game only framework, then it is better to have this automatic approach.
    but Gideros (like many others sdk out there) is not intended to be a Game/multimedia oriented sdk ?

    ...yes you could make an App with it but in which case i think is better to use some other (and appropiate) toolkit i think...

    ... my 2 cents ...
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • alexzhengalexzheng Guru
    edited March 2012
    :D

    I mean...

    Assume that you create a 10 second timer then suspend the app. After that wait >11 seconds then resume the app. After resuming your timer should be dispatched after 10 seconds, not just after resuming. (I hope I explained this time)
    did you mean stop will be called for all timers automatically on APPLICATION_SUSPEND and resume be called on APPLICATION_RESUME?
    Assume that you create a 10 second timer and after 5 seconds suspend the app. After that wait any seconds then resume the app. After resuming your timer should be dispatched after 5 seconds, not just after resuming. Is that right? And nothing to be done for developers currently?
  • avoavo Member
    well this got confusing fast. so I just did a quick test on device to make sure I understood.

    If you start a timer and then the application is suspended, such as hitting the home button on my device, the timer will still run in the background, if the timer completes while in the background, it will trigger the event as soon as its brought to the foreground.

    The proposed idea of pausing the timers on suspend by default makes sense to me, but I'm sure there could be some use cases for keeping a timer running even when an app is suspended, so maybe that should still be an option.

    Hope I got this right and that it makes sense? :)>-
  • alexzhengalexzheng Guru
    edited March 2012
    Btw, @atilim, do you have any plan to enhance MovieClip?
    For example ,change the timeline after create the movieclip.
    As an example, if you have character have some frames for idle state and some frames for jump state, and as it jump,the position will be changed Continuously.These can not be finished by the single movieclip.
  • If this works as @avo describes, it makes no sense for me. Suppose You set up 2 timers, for 10 and 20 seconds, and after 5 secs you suspend the app for 30 secs. You expected timer2 firing 10 seconds after the timer1, but they fire at the same time. It would make sense if the timers (when fired) could activate suspended application (or just some part of it?), otherwise I think it is better to suspend all running timers. It can be easily done in lua code, but it should be described in the documentation. @avo, thanks for testing and sharing!
  • atilimatilim Maintainer
    @alexzheng unfortunately, MovieClip is meant to be static and designed in this way. IMHO, to develop a jumping sprite, jumping frames should be placed to the MovieClip and the position of the jumping sprite should be handled programmatically.
  • Would gtween help?
    https://github.com/gideros/GTween

    (not really understanding the issue, but I had more success with gtween when I was experimenting a couple of months ago.)

Sign In or Register to comment.