In my roguelike I’m using a lighting engine by @SHiLLySiT. And I want to make sure (as the levels are planned to be quite huge) that only visible tiles & objects are rendered and updated. Could you please help me to actually implement this?
Rendering visible terrain only
I don’t have any idea, really. Still feeling kinda new to FlashPunk and AS3.
…However, I know that global lighting update applies to on-camera tiles only. The others are just ignored, but are they still rendered? And how do I keep off-screen entities from updating?..
Only rendering visible tiles may be difficult (I have no idea), but for objects, Flashpunk’s entities have an “onCamera” attribute. You can override an object’s render function like this so that it won’t be drawn unless it’s on camera.
override public function render():void {
if (onCamera) super.render();
}
Similarly so that only objects on camera update, you can do:
override public function update():void {
if (!onCamera) return;
// Rest of object's update code here
}
This sounds like pre-mature optimization though. How large of a level are you planning to make?
Thank you for your answer, @Quasar!
How’s about tiles? I have an entity whose graphic is a huge tilemap. How do I keep off-screen part of it from rendering?
Levels are planned to be not more than 100x100 tiles.
Unfortunately, I’m not sure how to achieve rendering only visible tiles for tilemaps.
A game I’m creating runs fine and it uses two tilemaps that are 30 x 120 tiles each (though each tile is only 16x16 pixels). How big is each of your tiles? And how is your game performing currently?