Jump to content

Exclude Sprite from constant repaint


geros
 Share

Recommended Posts

Hi all, 

The situation is this: 
There is  an image that is quite big 1500X1400 and we want to set is as a background to the game (inside canvas). On top of that we will build a tileMap with two layers .
We need this image (i have set it as Sprite) to be excluded from being constant repainted because this costs in dropping FPS to 30 in a desktop!

 

Is this possible ? 

 

Thanks and Regards

 

Link to comment
Share on other sites

The way the canvas renderer works at least is that it redraws the entire frame from scratch every time - there's no simple way around this that I can think of. Have you definitely identified that it's the background that's causing the slowdown? Could you try a TileSprite the size of the screen instead, which will cut down on pixels drawn?

Link to comment
Share on other sites

We need this image (i have set it as Sprite) to be excluded from being constant repainted because this costs in dropping FPS to 30 in a desktop!

 

Sprites are no longer something that just hovers over a background (hardwaresprites on c64 and consoles did that).

In those days you could draw the background once and then move sprites above it.

 

Now everything is just drawn onto the same canvas. If you do not repaint everything each frame the sprites will leave trails (the old position of the sprite will still be fully visible).

 

See this example:

 

http://examples.phaser.io/_site/view_full.html?d=display&f=render+texture+trail.js&t=render%20texture%20trail

 

This is exactly what it looks like, if you do not redraw the background every time you move something on screen.

Link to comment
Share on other sites

The classic (pre-GL) way for sprites to render extremely fast was an erase-move-copy-paint scheme. For this to work, you'd have to manage sprite-depth yourself.

 

For each sprite that needs to move:

 

1) Delete it by drawing over it with its 'copy buffer' (e.g. "erase")

2) Update its coordinates to the new location (e.g. "move")

3) Duplicate the backbuffer data underneath the sprite's new location/rect into its 'copy buffer' (e.g. "copy")

4) Draw the sprite using its 'sprite buffer' (e.g. "paint")

 

This is done only when a sprite needs to move, or when the entire screen changes (e.g. all sprites have moved).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...