![]() |
Just don't worry about the acorn numbers? |
Yeeeah, check the (low)-single-digit FPS in the upper left there. Turns out I've got to deal with it now.
Quick side note first, I love how huge these trees are. Trees are always way too small in games. These guys are big enough to make it feel like you really are a little dude in the woods. I'm into it.
Anyway, the first problem is that GameMaker draws everything that it knows about, many times per second, even if the thing it's drawing is outside of the screen. A single line of code in the tree's draw event stops the game from drawing it when it's outside of the player's view. We see a pretty huge performance gain here:
![]() |
Also don't worry about how he glitches through that tree at the start. |
Still not good enough, though. The game is supposed to update 30 times per second, so any FPS below 30 is slow. And, like, we have a shitload of stuff to add to this game, still. It's just fucking dirt & trees! I'm playing on a mediocre laptop & performance takes a hit from the screen recording software, but still.
At this point, I wasn't really sure what to do. I knew that the problem was that I was drawing a million leaves, but I didn't want to compromise on my original plan & I was liking the way the trees looked & Ok, actually I just didn't want to redo shit. A little bit of research led me to GameMaker's surface drawing functions, which, as it turns out, are super useful. GameMaker calls the thing that it's drawing to a surface; this is, by default, the gameplay screen. But you can instead draw to another programmer-defined surface, basically a virtual canvas, and then draw that surface to the screen whenever you want. So instead of trying to draw a million leaves while calculating their color, rotation, coordinates & scale 30 times every second, I can draw all of that just once to a surface, then draw that single surface, with it's single color, rotation, yadda yadda, 30 times per second. That's like, at most, 1% of the work we were doing before. Each leaf clump has about 100 leaves, and the tree is doing a handful of calculations for each one, but by drawing it all to a surface I can skip all of those calculations and just draw one thing. Anyway, it works:
![]() |
Let me take a moment to point out that masterfully crafted custom mouse cursor & the sick scroll wheel zoom action. |
Well, that's better. It's actually 50+ when the screen recording software isn't running. Any gains over 30 won't have a noticeable effect, but that's headroom that I'm sure I'll need later. Like, when the game is more than dirt & trees & a dude. Like, soon, hopefully?
No comments:
Post a Comment