Hey all, in this post we’re going over how to add invincibility to your player character in HaxeFlixel. This one is pretty straight-
forward. Let’s get into it.
Why Invincibility
Invincibility frames are an old-school staple. When Marios gets hit in Super Mario Bros. He loses his power up and he starts to flicker indicating to the player that he’s invulnerable. This is important for two reasons. The player needs time to react after getting hit. The player needs a safety net so they don’t die immediately after losing their power up to the same attack.

Creating The Mechanic
We can make use of this in our own game to provide these two benefits to the player. I’ve done it in my own game. Here’s how we set it up on a player character.
See the above. First, we have a property called INVINCIBLE_TIME. This property tells us how long the player should be invincible. We also have another property isInvincible which is used to tell the rest of the game that the player is invincible. The next thing we do is create a function to start the invincibility. We use Flixel’s flicker method to make the sprite flicker. Additionally, that function lets you pass in a callback function and once it’s complete the callback function runs. This brings the character back from being invincible.
Conclusion
With that said, I hope this helps you add another interesting mechanic to your own game. Good luck in game creation and enjoy the process!!
Recent Comments