Jump to content

Multi-texture sprite batching and ParticleContainer


Lehooo
 Share

Recommended Posts

Hi, first time poster here!

I recently started using PIXI for a game project with a tile-based engine. I used the ParticleContainer for a while but had to switch to a regular Container because I need to support several different base textures. I got really excited when I found the post on the blog about multi-texture batching in v4, but soon noticed that the example used a regular Container and that the ParticleContainer is not even present in the latest v4 dev branch (at least PIXI.ParticleContainer is undefined for me). So I'm wondering if this is because you are working on supporting multi-texture batching for ParticleContainers right now, or if they will continue to require all sprites to use the same base texture in the final release of v4. Really hoping for an answer to this as I have to support several different base textures but could really use the performance boost that a ParticleContainer gives.

Thanks for making an excellent engine!

Link to comment
Share on other sites

Thanks for the tip, but I've already checked that out and it doesn't quite do what I need so I've developed my own solution. But this wasn't really the focus of my question, sorry if I was a bit unclear. What I was really wondering about is whether the multi-texture batching feature will work for ParticleContainers in v4 of PIXI. Maybe there is no clear answer to this yet, I could just wait and see what v4 brings once it gets closer to being done.

Link to comment
Share on other sites

Yes it would be great to see, but I don't know much about the technical details of how PIXI works under the hood so maybe it would be hard to implement for some reason.

Well, this might be getting a bit off-topic considering the title of this thread but I can try to explain it briefly. I'm working on the basics of a game with a 3d coordinate system but with old-school 2d graphics. The grid that holds the tiles is 3-dimensional and each cell is a cube which has a tile associated with it and can have different "tile variants" set for each of the cube's faces. When a cell is set, the tile sets the tile variants of the faces based on whether the tile is flat (then only the bottom face of the cube is set) or thick (then the top and front faces are set). The tile variants of the faces are also dependent on whether the neighboring cells contain the same type of tile or not. I don't know if my description is a bit confusing or not so I'm supplying a screenshot of what I have so far, maybe that will give you a general idea of what I'm trying to do.

Maybe I could just use the data structures I have and generate tilemaps using pixi-tilemap but I decided to just use a regular Container and add sprites to that, it's working fine for me except I'd like to have the ability to use several different base textures in a ParticleContainer so I could use that instead of a regular Container. I can explain some more things about this if you want but I don't know how strict you are at this forum about keeping threads on topic so maybe I should post that somewhere else.

ankos.png

Link to comment
Share on other sites

You can create issue so we wont forget that: https://github.com/pixijs/pixi.js/issues

ParticleContainer will work just fine in your case. pixi-tilemap has different strategy, which is more effective both in memory (less objects) and performance: buffers dont change between clear() calls. Also, if your tiles are squares or at least half-squares, it will use gl.POINTS, and buffers will be smaller. Also, pixi-tilemap will have some optimizations for canvas2d mode, ported from rpgmaker and gameofbombs.com 

Link to comment
Share on other sites

Okay, I'll create an issue for that, thanks for the tip!

Actually, ParticleContainer won't work for me because I have to support several different base textures. I can get away with a single base texture for the tiles, but the player character you see there uses a different base texture and his sprite needs to be inserted between the tiles. I will add many moving characters and other moving sprites later on to my maps and they can't all use a single base texture, so ParticleContainer just won't work unless it supports several different base textures, which is currently not the case.

I'll take a closer look at pixi-tilemap, maybe I can make it work for me, thanks again for the tip!

Link to comment
Share on other sites

Just one more question, I don't know exactly how to describe the issue. Right now when I'm using the latest dev version of PIXI v4, PIXI.ParticleContainer is undefined. I'm wondering if I should mention this, but I guess the reason it is undefined currently is just that it is being worked on in some way, so maybe I should leave that out and just describe how ParticleContainer should support multi-texture batching.

Link to comment
Share on other sites

Okay, I actually tried a similar approach previously with one ParticleContainer for each layer. The problem there is that I allow tiles to be placed in a 3d grid, anywhere between 0 and 48 for all coordinates (x, y and z). Thus, I get a maximum of 48 layers and I noticed a significant decrease in performance with 48 ParticleContainers. This is why I switched to just adding all tiles in a single Container and that's why the player sprite needs to be in that same container.

Link to comment
Share on other sites

Then performance will suffer because you'll have to sort all that stuff whenever player changes his position. You can also try 48 pixi.tilemap's , I use 22 for rpgmaker maps and they are working just fine.

 I'm working V4 will have a way to solve that thing, by sorting z-indices, Z-buffer and even 2.5d projections.

Link to comment
Share on other sites

Actually, sorting is not a problem. At first, I sorted the whole container every time the player moved and that did decrease performance. I then realized I only had to reinsert the player sprite at the appropriate position in the array and that works just fine. I'm not having performance problems now, this works much better than having 48 ParticleContainers did, I was just wondering about ParticleContainers and multi-texture batching because it's always nice to get an additional performance boost. I'll look into using 48 tilemaps though, maybe that will work better.

Thanks for all the help and thanks for helping me find the ParticleContainer in v4, I was really wondering where it went... :)

Link to comment
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...
 Share

  • Recently Browsing   0 members

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