Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to change game speed? — Gideros Forum

How to change game speed?

edited August 2016 in General questions
Hi everyone,
I am playing with physic world and i want to create some effect like slow motion game.
For example:

http://giderosmobile.com/code/cfeMSinNWTZIapuJoKn8YdlPIN2Jdi2g

In this example, touch screen to make the ball jump.

What params should i add or change to make ball jump more slowly or more quickly ? (Still keep the same jump height )

Thank so much!

P/S this code base on article by @ar2rsawseen from: http://appcodingeasy.com/Gideros-Mobile/Gideros-Camera-Move
Coming soon

Comments

  • n1cken1cke Maintainer
    If you need to slow down all box2d world then you should dynamically change `1/60` value to something else:
    local worldspeed = 1/60 -- before `scene:onEnterFrame()` (to create free variable)
    self.world:step(worldspeed, 8, 3) -- worldspeed is instead of `1/60`
    .....
    If you need to slow down that ball only then I think you need to create another box2d world for it and dynamically change that world speed.
  • @n1cke Thank for your quickly reply. Yes i only need slow down all 2d world but if change world speed to 1/120 or 1/30 the ball jump height is not same as before.
    I still need keep same ball jump height.
    Coming soon
  • n1cken1cke Maintainer
    Accepted Answer
    I think to balance that you also need to dynamically change framerate of your app. For example, create a Timer, use it's events instead of Event.ENTER_FRAME and modify framerate with Timer:setDelay function.
  • totebototebo Member
    Accepted Answer
    I reckon the simplest thing which won't affect the physics is to control the frequency of stepping Box2D. The caveat there is that if you call it too infrequently it will become jerky.

    Another option is to change fps of the app from 60 to 30 with application:setFps().
    My Gideros games: www.totebo.com
  • Hey, awesome!
    With your advices, i think we can control this by skip frames:
    local frame_count = 0
    local speed_ratio  =  5
     
    function scene:onEnterFrame() 
     
        -- frame_count % speed_ratio seem do not work on this snippet environment?
        frame_count = frame_count + 1
        if frame_count < speed_ratio then
            return true
        else
            frame_count = 0
        end
        -- all code above equals frame_count % speed_ratio == 0
    ......
    http://giderosmobile.com/code/cfeMSinNWTZIapuJoKn8YdlPIN2Jdi2g
    Coming soon
Sign In or Register to comment.