Jump to content

Does a large child-array with visable=false property influence performance?


webdeveloper_issy
 Share

Recommended Posts

I am creating an 2d tilegame with sometimes an huge map of tiles with different levels.

Currently the game handles the tilemap(.json) as follow:

- Download tilemap(.json).

 

- loop through the map multidimensional array and addChild to displayObjectContainer each x,y have multiple layers so loop through x,y layers array and draw on the same x,y coordination.

 

- When the viewport changes al the tiles that are not within the viewport are set to visable=false and the ones that are new in the viewport are set to visable=true.

 

Is the performance influenced by child's that are set to visable=false?

If so, what other techniques can I use to make an fast tilegame?

 

Link to comment
Share on other sites

What I do is create each tile as a sprite, and set their positions to the proper locations. Then I calculate which need to be shown in the viewport and add those sprites to some rendered DOC. As the map pans I track the pan delta and when they have moved a tile length I remove all the sprite in the row/col they are panning away from and add in all the ones they are moving to.

 

This way only the sprites actively shown in the viewport are rendered in the graph at all, it works really well. I did it in grapefruit's TileLayer Implementation and my phaser-tiled plugin's TileLayer Implementation.

 

Grapefruit's implementation was a little different, it didn't create a sprite for each tile in the map. Rather it created one for each tile in the *viewport* and then just reused them from a pool while panning. That meant there was a lot less tile objects created, but also a lot less flexibility to edit the map.

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