Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(3 edits)

I don't know how interesting this would read to some people but I decided it'd be fun to go over what I had to do while working how to implement this feature.

I decided for a bit of flair to add an effect when you click on the bouncing things. After staring at the animation tools for a while I decided instead to spawn a particle effect, which would also have a bit of randomness to where the sparks fly.

My first attempt ended before it ever really began: I attached a particle node as a child to my Bouncing Thing instance, gave it a test and... no particles. When a Bouncing Thing is clicked, it adds points and promptly destroys itself. When a node is destroyed, it destroys all child nodes along with it, meaning the particle child node is created then immediately destroyed along with its parent. Tragic.

Turning off the Bouncing Thing being deleted, though, shows the particle works fine and dandy...except far off from the actual Bouncing Thing's sprite, and anchored-yet-offset to it, so it a was moving and bouncing around in tandem a few inches away. Not quite desirable.

I figured the easiest way to solve this problem would be to make the particle effect not a child of the Bouncing Thing at all, but rather, the Node2D that contains the nodes for all the stage nodes (and also works as the spawner in a moment of perhaps poor judgement). This gave me a particle effect that was stationary, but was stuck at the very top-center of the stage. Still, it felt like progress, and all I had to do now was work out how to move it where I wanted it to be.

To do this, when the Bouncing Thing is clicked, it makes a variable whose value is set_pos(). I then create a second variable that actually loads the particle node instance (not that it's just loaded and not actually assigned as a child yet). I use the first variable to set the particle's position, then add it as a child to Node2D.

Success! Except the particles are spawning forever. No problem, I added an extra line saying that the particle spawner should only emit particles for about 2 seconds. While I'm pretty sure the particle nodes still "exist" in the game, I doubt this is a performance issue for something this simple. At least, I'd be pretty sad if I somehow caused things to dip below 60FPS in a game this simplistic, especially since it only really runs for a minute. Just to be safe, I added a Bouncing Thing-destroyer off-screen at the bottom to clear out anything the player misses instead of keeping them loaded forever. Seeing the object/node amounts in debug mode along with FPS counts make me feel okay.

The net result of all this is here: http://webmshare.com/play/d13qO

All-in-all, it took me a bit over an hour to work this out, including googling and browsing docs to find what I need to do and how to do it. This is probably a bit of a sloppy implementation, but finesse is not the name of the day here. As long as it works, right...?