md_lasalle Posted August 21, 2017 Share Posted August 21, 2017 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 More sharing options...
samme Posted August 21, 2017 Share Posted August 21, 2017 You can set obj.renderable = false during update, and then during render: obj.renderable = true; game.renderer.renderDisplayObject(obj); md_lasalle and Taz 1 1 Link to comment Share on other sites More sharing options...
md_lasalle Posted August 21, 2017 Author Share Posted August 21, 2017 This is exactly what I was looking for, thanks samme. samme 1 Link to comment Share on other sites More sharing options...
Taz Posted August 21, 2017 Share Posted August 21, 2017 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... md_lasalle and samme 2 Link to comment Share on other sites More sharing options...
Taz Posted August 22, 2017 Share Posted August 22, 2017 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... md_lasalle and samme 2 Link to comment Share on other sites More sharing options...
samme Posted August 22, 2017 Share Posted August 22, 2017 Yes, as long as you disable automatic rendering of the text objects I think the sprites will batch on their own. Taz and md_lasalle 2 Link to comment Share on other sites More sharing options...
md_lasalle Posted August 22, 2017 Author Share Posted August 22, 2017 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. Taz 1 Link to comment Share on other sites More sharing options...
Recommended Posts