Zeto Posted January 18, 2020 Share Posted January 18, 2020 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... Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 18, 2020 Share Posted January 18, 2020 (edited) 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 January 18, 2020 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
Zeto Posted January 18, 2020 Author Share Posted January 18, 2020 @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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 19, 2020 Share Posted January 19, 2020 Yep, its no automatic, but the code should be very simple and configurable. I prefer my users to handle their own FOR's, instead of relying on forEach, you know That way everyone can feel that they are making their own engine and not just using prepackaged bigmacs 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.