immanuelx2 Posted September 14, 2019 Share Posted September 14, 2019 I have several textures created from PNG's (with transparency), and I would like to layer them onto a sprite so that they would effectively create one "combined texture". The problem is the Sprite object only takes a single texture. The reason I do not want to combine my textures into a single PNG file is because I want to dynamically layer different textures (using random generator functions in JS). So I think my two options, if possible, are: Create a new combined texture from the layered textures at runtime Assign multiple textures to a single sprite Is there an effective way to accomplish this? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 14, 2019 Share Posted September 14, 2019 use sprite width RenderTexture or a multiple sprites in a container, Quote Link to comment Share on other sites More sharing options...
immanuelx2 Posted September 14, 2019 Author Share Posted September 14, 2019 2 hours ago, ivan.popelyshev said: use sprite width RenderTexture or a multiple sprites in a container, Thanks Ivan. It looks like the way to create a RenderTexture is by creating a sprite for each layer (including the initial "base" layer that the others will be added to): const dynamicTexture = PIXI.RenderTexture.create(130, 65), baseSprite = new PIXI.Sprite(resources.base.texture), layerSprite1 = new PIXI.Sprite(resources.layer1.texture), layerSprite2 = new PIXI.Sprite(resources.layer2.texture); app.renderer.render(baseSprite, dynamicTexture, true); app.renderer.render(layerSprite1, dynamicTexture, false); app.renderer.render(layerSprite2, dynamicTexture, false); Any way to bypass sprite creation and just use the texture directly, or is this the most efficient way to do this? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 14, 2019 Share Posted September 14, 2019 you can create a container for those sprites and then you'll need only one "render" operation I dont know what do you mean by efficient here. Its one-time operation. Do you have like 1000 of them? Then "optimization" i suggested can help a bit. Btw, if you are using that for tilemaps - i strongly suggest not to do it. Tilemap discussions are big and you can search them through this subforum, there are better techniques. Quote Link to comment Share on other sites More sharing options...
mobileben Posted September 17, 2019 Share Posted September 17, 2019 Since you want to control your drawing of the layers, you may want to create a class which uses a container as a parent for the sprites. The reason for the class is you could use that as the interface to control the layers (ie. sprite). If you know that the textures are inter-related, if you have not put them in the same atlas, you should. This will eliminate the need for the underlying renderer to change the texture when rendering (ie. higher likely hood depending on what the renderer is doing that they can be drawn with the same draw call). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.