Hanging on Balloons


One of the best things you can do for yourself in gamedev is to have good tools and an efficient workflow. I’ve already shown how I handle path movement in [Speer] in another post, now I want to show you another small trick I’m using to make level creation easier and quicker.

Note: As always this article will show how I’ve implemented it in HaxeFlixel, as that is the framework I’m using. The general idea however is framework-agnostic and can be implemented anywhere.

[Speer] features balloons that carry various items around the stages:

balloons.gif

I’ve coded this system to be flexible, so as long as an object inherits from a certain class, it can be attached to a balloon and will be updated automatically. But how do I actually attach items to balloons? Well, the most intuitive way would be to actually, physically attach an item to a ballon, wouldn’t you say? I would, so that’s what I did. Enter hookUpBallons():

private function hookUpBalloons():Void{
    grpBalloons.forEach(function(B:Balloon){
        grpBalloonables.forEach(function(C:Balloonable){
            if (B.tileCoords.x == C.tileCoords.x){
                if (B.tileCoords.y == C.tileCoords.y-1){
                    B.assignItem(C);
                }
            }
        });
    });
}

This one might require some explanation. When the map data is parsed ( using HaxeFlixel addons, see this post for more info ) every Balloon that is created gets added to the Group grpBalloons. A Balloonable is an instance of a class that can be attached to a balloon, and those are saved in grpBalloonables.

Once all entities have been instantiated and added to their respective groups, I call hookUpBallons() in my PlayState. The function then loops through all Balloons and all Balloonables and checks their position in the tilemap; if the Balloonable is one tile below the Balloon, it gets attached to that balloon. Note: tileCoords is not a HF-internal property, but it basically just takes an object’s x and ypositions and converts them to tile coordinates in the current map.

So when I position the items like this…

hooked.png

…then the items will be attached to the balloons in-game:

bobbing.gif

However, if I move an item just one tile to the right…

nothooked.png

…it’ll fall down as soon as the game starts:

fallen.png

And that’s pretty much the whole secret. This way I don’t have to set any IDs or explicitly make any connections. I can just intuitively do what I want done: Attaching an item to a balloon. It’s little things like this that make game design not only more efficient but also more fun.

Take It to the Next Level!

Want sneak peeks and early access to stuff? Join my Patreon!

Become a Patron!
Just Want to Buy Me a Coffee?
Get Words in Your Inbox!

Be oldschool and sign up for my newsletter to get updates! Just enter your email address, prove you're not part of Skynet and you're good to go!



Powered by CleverReach. I will not send you spam or sell/give your email address to someone else.  You can of course unsubscribe at any time. By clicking the subscribe button above, you confirm that you have read and agreed to our privacy policy.

Related Posts

Devlog #3: Shiny Shiny Gems

Collectibles are as much a part of platformers as actual platforms. Whether it’s Sonic’s rings, Mario’s coins or Banjo’s notes, it seems like platformer worlds don’t have littering laws because these things are everywhere. And that’s good, because it’s really fun to collect them and sometimes they even help you out. Extra life, anyone? So of course Go! Go! PogoGirl will also have collectibles. After some thinking I settled on gems, because…I dunno, they look pretty and sparkly and coins are pretty overdone.
Read More

Devlog #2: Bouncing Science

When you have a player character that should always bounce, a couple of obvious questions present themselves: How should they bounce? How high should they bounce? How quickly should they bounce? Questions like that form the basis of the entire gameplay concept, so it’s very important to tackle them as early as possible…even if you’ll often end up tackling them a few more times before the game ships. Here are the answers I’ve worked out for now.
Read More

Devlog #1: Introducing PogoGirl!

Welcome to the first post of my new Go! Go! PogoGirl devlog! Here I’ll post long-form updates on the development of Go! Go! PogoGirl, sharing my experiences, crying about the bugs I encounter, and more. Developing a game is a journey, and it’s more fun when you can drag people along with you. Stay away from the radio though; I pick the music. Okay, so let’s start off by explaining what Go!
Read More

By using the Disqus service you confirm that you have read and agreed to the privacy policy.

comments powered by Disqus