I just wanted to post here my findings experimenting with Etoys. My goals are basically doing arcade style games (complete with chunky graphics) with fast gameplay, cool animations and nice sound comparable to NES or Super Nintendo, nothing fancy with crazy shaders and such and one of the problems that happens is collision detection.
Now, there's tons of programmatic ways to do this, but I think I stumbled into a 'free' way to do it without sacrificing graphical fidelity (you'll see what I mean in a moment). So for collisions we have multiple options: OVERLAPS DOT OVERLAPS ANY DOT SEES COLOR COLOR SEES COLOR DISTANCE TO Now, what I want to get at is that collision detections are happening all the time between all game objects. The background blocks, the characters, their projectiles, random powerups, all these things are checking if they're colliding and then deciding if they want to do something about it. In using OVERLAPS, you have to figure out a way to create a custom collection of siblings IN your playfield. This is possible because you can make a clear playfield that contains these objects. Why you'd do this is becasuse you'd run through all the objects in there to see if the thing you're looking at OVERLAPS one of them, specifically. And you'd do this by running a TEST on COLLECTIONS using a REPEAT tile. Seems slow to me and I didn't even bother. Call me a poor scientist. Next, the most promising is OVERLAPS ANY DOT. This means that you can check your object against all siblings. However, depending on the kind of collision this can be VERY SLOW! So if we consider that things showing and not showing on the screen are part of OVERLAPS checks, this includes every single morph in or out of the playfield, you quickly add up checks that you don't even need. I don't need to check if my bullet overlaps the numerical readout of a flap. Just the aliens! This proved to be the case that it was slow when implemented. I tried to run individual alien scripts checking for overlaps with any bullet but it was slow with just 10 aliens and no bullets! So then I thought, Maybe it's the ticking scripts, let me have th eplayfield tell them all at once to check. Nope, same result (slightly faster, but not playable fast...something like 20fps...and we're shooting for 60 and we just have 10 aliens and NO BULLETS? unacceptable performance!) So next we only have the obvious color checks. But this poses a problem. We want GRAPHICS. If we're checking colors, this means we can't have unique graphics. I have a bullet that blue, that's fine, but I'm checking for one color on an alien made of 30...this is not going to make good collisions! However, it's FAST. SUPER FAST. I made about 50 aliens and filled the screen with bullets and no slowdown. It turns out I discovered what is happening...when checking overlaps, every object is 'woken up' to check if they are in position or not, one at a time. Doesn't matter of individually through own scripts or one script triggering all of those individual scripts, they all individually move memory around for checks. The screen is just ONE object checking ITSELF. The colors are just pixels inside the display screen object. How can we take advantage of this free collision? By just drawing right on top of it when it's done and don't worry about the details. Literally the solution is to hide it in plain sight. Make a playfield that mirrors your objects and hide it for checks then show it before the screen updates. It's like Etoys was just made for this, being able to do it so fast. Attached is a link to a demo video, but a more complete demo is obviously forthcoming with both screens filled. I just had the 'eureka' moment and had to share it and record it so I can make sure my brain internalizes it going forward. Fast Collision with Custom Graphics in Etoys <https://www.youtube.com/watch?v=xOTDDfBeF8Q> I hope this helps folks using any smalltalk and looking to get some performance. There's a lot of 'pure smalltalk speed tricks' I've been figuring out. I know this probably isn't incredibly interesting to anyone, making silly explody boom boom games, but I hope the idea of collisions here for 'free' might be of use. I suspect it was implmented this way because of what I found, but I'm never sure as there's not an especially loud neon sign pointing to this as the 'proper way'. At any rate, thanks for reading. Just sharing in hopes it helps other folks starting out getting some speed when checking collisions for a lot of moving objects. The other thing I can tell you is don't do rotation math unless you have to and don't scale objects UP, scale them DOWN. Memory and CPU wise, these make a lot of savings when stacked.
_______________________________________________ Beginners mailing list -- [email protected] To unsubscribe send an email to [email protected]
