Sign in to follow this  
!untrue

Redrawing only when needed?

Recommended Posts

How I usually use Pixi is that the render loop will just keep going. Which is fine for things that are undergoing constant change and interaction, but I'm considering using Pixi for something more static... something that'll display a certain thing.... be interactive and respond when needed, but really be doing nothing most of the time. What I'm concerned about is the idle CPU usage... it uses a relatively small amount of CPU to leave the whole thing running at 60fps doing nothing, but it feels inefficient and wasteful. (As a user of an older mobile device, it really drives me nuts when I encounter a site that's inexplicably a performance pig.)

I'm just curious what other people are doing in these situations, and how you approach this. Does it make sense to exit the render loop when everything is finished updating, then have an event put us back in? Can you stop/pause Pixi itself? Or is this just more trouble than it's worth?

Share this post


Link to post
Share on other sites

https://github.com/pixijs/pixi.js/wiki/v5-Custom-Application-GameLoop

As for how to detect if something was changed - we can't implement that because we value readability of PixiJS code more than that feature.

Its possible to track changes in transforms, but everything else is difficult. Usually people just set special flag if they app changes something and add "if (flag) { renderer.render(stage); } " in gameloop

Share this post


Link to post
Share on other sites

I have a method where I have two different changes that can happen in the scene. Tweens and handlers that get run every frame.

For tweens I check if  amount of active tweens creater than 0, then it means that something is changing.

For onrender-handlers I have a custom component that allows for components to register themselves to get onrender -events and their return value will tell if something has updated.

If either tween has updated or any of the components requires rendertime, then that frame is rendered. Otherwise no render will occur.

In some cases this can be improved by splitting the scene into multiple canvases. One that gets updates rarely and one that holds the actual gameplay and is updated frequently. Though using that method is something that should be clearly thought out beforehand or you'll end up with multiple canvases to render each frame.

Having render loop stop completely is something that you shouldn't do. As calling requestanimationframe is really cheap and not worth the trouble to build a mechanic with renderloop cancellation. Easier to just skip rendering on frames that dont need it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.