High FlxG.updateFramerate with low FlxG.drawFramerate doesn't seem to work

  • I'm working on a solitaire game for HTML5, where most of the time nothing changes on the screen. To save power on mobile (and fans spinning up on desktop/laptop), I though I'd reduce the framerate from 60 to 10 fps, setting it back to 60 when the player starts dragging a card. But in order to respond to input immediately, I still need update() to be called at 60 fps or thereabouts.

    So I did the obvious:

    FlxG.updateFramerate = 60;
    FlxG.drawFramerate = 10;
    FlxG.fixedTimestep = false; // Edit: added

    However, if I do this, my update() gets called only 10 times per second, with elapsed == 0.1, and input is noticeably laggy. Once the frame has been processed and drawFramerate has been cranked back up, everything is fine again.

    Using neko for debugging, but observing the same on html5. Using HaxeFlixel 4.2.0, OpenFL 3.6.1.

    Is it possible to have my cake and eat it too?

    Edit: Looking at the code for FlxGame, it seems step() is called at most once per draw frame, if fixedTimestep == false. On the other hand, if fixedTimestep == true, I would expect to get multiple update() calls in a burst right before for each draw frame, so that's not really helping either.

  • Remove this would help:

    FlxG.fixedTimestep = false;

    Maybe you need to speed up the game also:

    FlxG.drawFramerate = 10;
    FlxG.timeScale = 6;

  • Thanks, but that's how I started (with fixedTimestep == true). I don't think timeScale will do what I want either; you'd just get the update calls in 10 bursts of 6 calls each.

  • So what's you're trying to do again?

  • Get update() calls at a regular frequency of 60 Hz. Not merely 60 calls per second, but spread out evenly throughout that second.

    Here's another idea, which I'll try when I get time: subclass FlxGame to override draw() with a method that calls super.draw() only 1 out of 6 times. I hope this won't confuse HaxeFlixel too much :)

  • So I've written a little test to understand your problem. When FlxG.fixedTimestep == true, it does lag when you move the test subject.

    Since I assume you only use HaxeFlixel for your game, I recommend modify FlxGame source code instead of creating a subclass

    Some dirty and quick workaround:
    Replace FlxG.fiixedTimestep with false in your FlxGame where you mentioned
    Like this:

    if (false)
    	_accumulator += _elapsedMS;
    	_accumulator = (_accumulator > _maxAccumulation) ? _maxAccumulation : _accumulator;
    	while (_accumulator >= _stepMS)
    		_accumulator -= _stepMS; 

    Or just replace all that with this but it will be a bit harder to reverse that


Log in to reply