Jump to content

Performance on generating multiple map layers


Jambutters
 Share

Recommended Posts

Currently using Tiled and my maps have multiple layers : 
 

Something like: 

//Floor: 
let floor = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

//Trees: just pretend it's filled with different values
let trees = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

So how I'm going about it is to generate a PIXI.Sprite for every tile and then pushing those into a container, and that container would be the layer:

//an array of PIXI.Textures sliced from the spritesheet for tiles
let tileSpriteResources = [texture, texture, texture]; 

let floorLayer = new PIXI.Container();
let trees = new PIXI.Container();

//something like this: 
function makeLayerSprites(containerLayer,array, width, height){
  let W = width;
  let D = height;
  let shiftY = 0;

   array.map(function(item, index){

    if(index >= W){ //shifts Y downwards when X is passed with width
     shiftY++;
  } 

    if(item === 0){
        let tile = new PIXI.Sprite(tileSpriteResources[0]);
        tile.setTransform(index * 32, shiftY * 32);


        containerLayer.addChild(tile); 
     }

  });

}


I'm going to have like.. 6+ layers and I was wondering if I should just generate 1 layer, and then have the rest of them be the children of every PIXI.Sprite on the first layer. Or is my approach just fine ? 

For culling I'd imagine I would have to loop through all 6 containers children and yeah, I'm not sure how this will strike me in performance. 

Any general advice or recommendations or how you've implemented multi-layered maps in PIXI ?  

 

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...