Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
changing fps in runtime — Gideros Forum

changing fps in runtime

In my app, I need to change fps from 60 to 30 in runtime. However, application:setFps(30) has no effect and application:getFps() always returns 60. I'm working on Windows PC. Is it impossible to change fps in runtime?

Comments

  • E1e5enE1e5en Member
    Hey!
    I decided to try these functions and it works for me. I took the "Button" example as a basis and changed it a little. Code:
    -- Label for print FPS
    local label = TextField.new(nil, "FPS: ".. application:getFps())
    label:setPosition(120,240)
    stage:addChild(label)
     
    -- Create the up and down sprites for the button
    local up = Bitmap.new(Texture.new("button_up.png"))
    local down = Bitmap.new(Texture.new("button_down.png"))
     
    -- Create the button
    local button = Button.new(up, down)
     
    -- Event click
    button:addEventListener("click", 
    	function() 
    		if application:getFps() == 60 then
    			application:setFps(30)
    		else
    			application:setFps(60)
    		end
    	end)
     
    -- Print FPS
    stage:addEventListener(Event.ENTER_FRAME, function()
    	label:setText("FPS: ".. application:getFps())
    end)
     
    button:setPosition(40, 150)
    stage:addChild(button)
    Result:


    Perhaps you should show the code.
    Beginner game developer
    https://e1e5en.itch.io
    +1 -1 (+2 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited August 26
    (at) E1e5en, pretty good for a beginner game developer :)

    edit: according to your itch.io page you're not a beginner ;) I am happy you decided to give gideros a try :)

    Likes: E1e5en

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • E1e5enE1e5en Member
    edited August 26
    MoKaLux, thanks! =)
    I consider myself a newbie because I haven't released any game. Almost all games (itch.io) are project contests (Game Jams, lasting 2-3 weeks). Each of them was made on its own game engine (Construct 2, Godot Engine, GameMaker Studio 2). I'm in search of a tool for myself that I would like (I have complaints about others and not only those listed earlier I have considered) and decided to try Gideros. :)
    Beginner game developer
    https://e1e5en.itch.io
    +1 -1 (+2 / -0 )Share on Facebook
  • rrraptorrrraptor Member
    edited August 27
    Seems like
    application:setFps(fps)
    does not work at all.
    First, I thought that is does not affect gideros player, so I exported the app and tested on it. As a result, there is no effect.

    On the left - gideros player, on the right - exported app.
    @hgy29 ping :)
    +1 -1 (+2 / -0 )Share on Facebook
  • salesioparksalesiopark Member
    edited August 27
    Now, I'm now very confused about fps in Gideros. My PC is Windows10 system.
    When I set fps in Gideros Studo(template>properties>Graphics>fps) as 60 and wrote in my main.lua


    local function update(e)
    print(string.format('%d',1/e.deltaTime))
    end
    stage:addEventListener(Event.ENTER_FRAME, update)


    I expect that update() function is called exactly 60 times per second. However, when I set fps in Gideros Player>Hardware>Frame rate as 30, update() function is called 30 times per second regaredless of the settings of template fps.
    In the case of executing some time later,


    application:setFps(30)


    the update() function is called 60 times if Gideros Player>Hardware>Frame rate as 60.

    My question is this. If my exported app's fps is changed to 30 at some time using application:setFps(30), can I expect the update() function call and the screen redraw to happen exactly 30 times per second after that?

    Likes: E1e5en

    +1 -1 (+1 / -0 )Share on Facebook
  • rrraptor said:

    Seems like

    application:setFps(fps)
    does not work at all.
    First, I thought that is does not affect gideros player, so I exported the app and tested on it. As a result, there is no effect.

    On the left - gideros player, on the right - exported app.
    @hgy29 ping :)
    Looks like a bug in Gideros.
  • E1e5enE1e5en Member
    edited August 27
    salesiopark, sorry for not thoroughly examining your problem.
    Looking at the result in different assemblies, it turns out that the function does not work correctly on all platforms:
    - Gideros Player (Android) - works correctly;
    - Android - works correctly;
    - Win32 - works correctly;


    - Gideros Player (Windows) - does not work, setting the FPS value is done through the settings;
    - Windows Desktop - does not work, depends on the project settings;

    - HTML5 - no setting works, it gives out as much as it can.

    Likes: salesiopark

    Beginner game developer
    https://e1e5en.itch.io
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    E1e5en thanks for checking on various platforms. On my confident it works on iOS too, but yes it won't work at all in HTML, because in HTML the animation loop is driven by the browser and Gideros has no control on the exact timing. I suppose it could be reduced by skipping frames if actual FPS is higher than what is configured, but obviously not the other way.

    On Desktop player it is basically a timer, or actual monitor refresh rate is Vsync is turned on, and possibly not controllable through lua.

    I'll have a look at the code and see if I can do something.
    +1 -1 (+2 / -0 )Share on Facebook
  • E1e5enE1e5en Member
    edited August 27
    Got to Macbook (Catalina - 10.15.7):
    - Gideros Player (MacOS) – does not work, setting the FPS value is done through the settings;
    - MacOS – does not work, depends on the project settings.

    HTML5:
    hgy29 said:

    I suppose it could be reduced by skipping frames if actual FPS is higher than what is configured, but obviously not the other way.

    Do you mean frame skipping is a negative FPS setting (eg application:setFps(-30))? As written in the docs.

    I tried it, it doesn't work.



    Beginner game developer
    https://e1e5en.itch.io
  • hgy29hgy29 Maintainer
    I meant calling gideros rendering loop once for two calls of html rendering loop, to achieve 30fps as seen from lua even if the browser calls us at 60fps
  • hgy29hgy29 Maintainer
    I fixed desktop (player and export) to honor calls to application:setFps(). I also added a possible fix for HTML, but I still need to try it. I am upgrading our emscripten version to benefit from recent improvements regarding threads
    +1 -1 (+3 / -0 )Share on Facebook
  • E1e5enE1e5en Member
    hgy29 said:

    I meant calling gideros rendering loop once for two calls of html rendering loop, to achieve 30fps as seen from lua even if the browser calls us at 60fps

    I thought the setFPS() setting would work in this case. But it turns out that changes are needed in the engine code.

    If you can get the deltaTime values from the browser loop, then equate it to the required value (setting set in the project - FPS), skipping the loop iteration. So will it work or is there another mechanism?
    Beginner game developer
    https://e1e5en.itch.io
  • I confirmed that it works normally with 30 frames after executing application:setFps(30) on Android devices. In order to view at 30 frames in Gideros Player (Windows), I also learned that Hardware>frame rate>30 menu should be selected even if the template setting is set to 30.
    https://youtu.be/XCy5qqj1BqI
  • SinisterSoftSinisterSoft Maintainer
    For html5 I think that a way for the current method to work too would be good - in case the new code breaks something.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.