Jump to content

Controlling rendering of sprites


md_lasalle
 Share

Recommended Posts

Hello everyone, I have a case where I have lots of sprites on screen and each sprite has a Phaser.Text attached to it. Right now, I'm rendering in this order : renderSprite -> renderText, renderNextSprite -> renderNextText, thus having to flush the context every time I draw the text since it's not using a common sprite atlas. What I'd like to do is : renderAllSprites -> renderAllTexts

So my question is, is there a way to tell Phaser not render any of these objects, and in the render() function of my current state, call what to render manually ?

I'm opened to other suggestions, but please bear in mind that I cannot switch to bitmap fonts due to the fact that I need to support many languages.

Thanks.

 

Link to comment
Share on other sites

Also note that renderDisplayObject() begins and ends a new batch each time it's called (for the WebGL version) so the sprites wont get batched and you'll have one draw call per sprite...

OTOH if you use a container for all of the sprites and a container for all of the texts, all the sprites will render first with batching then all the texts will render. Since you have lots of them you might want to do this for faster WebGL rendering... EDIT: Note in this case you can just let renderable default to true like usual...

Link to comment
Share on other sites

Also you could leave the text as child of the sprite with renderable false for just the text, then let the sprites render normally. That way you only have to manually render the texts, not the sprites, and the sprites can utilize batching. That's prob easier way to do it without breaking batching and with text still child of sprite, I think...

Link to comment
Share on other sites

16 hours ago, magig said:

Also note that renderDisplayObject() begins and ends a new batch each time it's called (for the WebGL version) so the sprites wont get batched and you'll have one draw call per sprite...

OTOH if you use a container for all of the sprites and a container for all of the texts, all the sprites will render first with batching then all the texts will render. Since you have lots of them you might want to do this for faster WebGL rendering... EDIT: Note in this case you can just let renderable default to true like usual...

Good to know, that would defeat the purpose of this whole optimization :)

I will most likely go with your second approach, just make a pass in the render function to render text separately. I'm guessing that Phaser.Text objects are simply fonts being baked into separate textures? Wouldn't it be awesome to have Phaser create an atlas from all the text objects.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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