Game Maker: flattening a room's tile layers to a surface at runtime

This is just a proof-of-concept GML code thing I did for rdein. What it does is this: when you start a room, it draw all of the room's tiles to a surface or series of surfaces, then destroys the tiles. Then it draws the surfaces in place of the tiles. Drawing a few large surfaces is theoretically faster than drawing 1000s of individual tiles, each with their own specific top, left, width, and height values.

AttachmentSize
TileSurfacer.gmk85.47 KB

Comments

Danni's picture

Early console sidescrollers

Early console sidescrollers did this, actually. At least in terms of drawing tiles onto a "canvas" as they were about to enter the screen.

As for PCs, when it comes to software-based rendering the difference is usually negligible if you're using multiple layers since there's very little overhead to each individual blit or drawing call. For hardware rendering, however, there is notable overhead. My guess is that Game Maker does a separate call for each tile it draws, perhaps does some extended bookkeeping as well, resulting in hampered performance.

Back when I was still messing around with Game Maker, I noticed that I was getting pretty bad performance in one of my tile-based games. I was using Objects to handle tile collision (they spawned tiles at the beginning of the room) and as it would seem, there is a lot of overhead to processing each Object entity every frame. I probably could have deactivated collision objects outside of the screen, but that would cause problems in case I wanted any moving objects outside of the view. I settled on holding tile information in an array and then deleting the tile-creating Objects at the start of the room, and then writing my own tile collision system. Doing this roughly doubled the game's performance. This whole thing is perhaps unrelated, but Game Maker's standard ways of handling things like tiles aren't exactly performant in my experience.

pensive-mosquitoes