-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to pause the render loop if nothing is happening? #263
Comments
Hi, Yes you can do this! Please take a look at the StageRenderMode enum. You can set the stage.renderMode property to one of the following values:
If you change something on the Stage, you can set the "Once" value and you will get an updated stage. After this render event the property will automatically change it's value to "Stop". So every time you want the stage to be rendered you set it back to "Once". I wonder why i have no example for this, i will add this to some of the examples soon! |
When trying to automate this behaviour, I found it best to extend
This should suffice for a lot of use cases. For more complex applications, I haven't yet been able to find an elegant solution for:
If I had the time, I would go for a centralized |
I'd love to have this be auto-magic, @nilsdoehring – I've implemented it before. No clue how easy here. I just don't like tabs burning CPU when nothing is moving. Makes the mobile users sad. |
@kevmoo, would you be able to provide any pointers, preferably in ActionScript? (because easiest to port) I'm motivated to revisit the case, especially since my implementation is faulty, but if disabled, would melt down the CPU in the example linked above. Will follow up, here. |
@nilsdoehring sadly, no. Not sure if there is a way to do it generically. One improvement: it'd be nice to just have a |
The starling framework in v2.0 implemented auto-magic idle mode :) But you won't get it for free, basically every change to one of the DisplayObject or DisplayObjectContainer properties and several other trigger will mark the display tree as dirty. It's nice for applications where most of the time nothing changes, but it hurts performance for games where each frame is different. |
I will work on this feature over the weekend. The code will be very similar to the one fromNils, i will keep you posted. |
I implemented this by using a Once and Stop stage modes. Invalidating an object in my GUI framework causes the Stop to go to a Once. I have to keep track of Canvas Resizes as well. This is a feature one wants on a GUI framework (like I use), but would be expensive to set up in a game framework. |
Anything new? Starting to realize this is a big deal for battery drain. |
Could it be simple as just checking whether or not the juggler has work to do? Then it's on the dev, if he wants to save battery, to make sure animation stops after a period of idle time from user. |
There is a very simple trick. First you set stage.RenderMode to StageRenderMode.AUTO_INVALID which will only render the Stage if someone called the stage.invalidate() method. Next, you derive your own Juggler from the standard Juggler and override the advanceTime method. In this method, check if the hasAnimatable property is true, and in this case call stage.invalidate(). If all your animations use an instace of your Juggler, everything should work as expected. This would be easy to implement in StageXL itself. But i don't want to make the stagexl.animation library (where Juggler exists) dependent on the stagexl.display library (where Stage exists). I was thinking about some magic to make this work, but never figured out a way that makes me happy. Hope this helps. |
In my crazy outdated
bot_web
retained silly - https://github.com/kevmoo/bot_web.dart/tree/master/lib/src/bot_retainedI kept track of dirty information and I wouldn't render frames unless something changed.
Any way to do this with StageXL? I see that the
render
events keep pumping, even if nothing is going on.The text was updated successfully, but these errors were encountered: