Jump to content

In pixi-tilemap, should I redraw the frames when the camera moves?


Recommended Posts

Right now i have a 30x30 tiles layer with pixi-tilemap, and I simply use tiles.pivot.set(camerax, cameray) to move around (it works well). With sprites, I know I have to manually set renderable = true/false for sprites that are in/out of the screen, to reduce the renderer's workload. However, with pixi-tilemap, I am not sure whether I should redraw the tiles depending on where the camera is.

My question is: Suppose I have a 3000x3000 tiles map, and my screen only shows 20x10 at any given moment, should I render the 3000x3000 tiles before the game begins and use tiles.pivot.set(camerax, cameray), OR should I only addFrame 20x10 tiles, then clear and addFrame again if camerax/cameray changes?

The structure of pixi-tilemap gives me the impression that it is all automated depending on what is seen on the screen but I could be very wrong. In Alan01252's  tutorial, the clear function is nowhere used, which makes me think that one can addFrame as many times as one needs, but it seems very sketch after I read the source code a bit more...

Link to comment
Share on other sites

Maintain a window around the camera, that is drawn. When camera touches that window - move it and refill everything with elements that intersect that wnidow.

I have that algo in a tutorial: https://github.com/ivanpopelyshev/pixi-starfighter/tree/master/lesson1_5-tilemap , however you have to delete all other things from it :)

Edited by ivan.popelyshev
Link to comment
Share on other sites

@ivan.popelyshev thank you for your quick reply! I just want to make sure I get this right, suppose I have a 20x10 tiles screen, what you suggest is to draw let's say 30x20 around the camera, and when the camera goes out of the 30x20 drawn area, I clear the CompositeTileLayer and addFrame the new 30x20 tiles around the camera.

So essentially it isn't automatic. 

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.

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.


  • Recently Browsing   0 members

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