Saturday, January 26, 2013

Come and Go: Implementing 'Enter' and 'Leave' scripting events

So, I've had a collision scripting event set up for a while. One of the limitations of collision, however, is that it will fire every single frame while the two entities in question are overlapping. What if I wanted to prevent that from happening?

Well, one hack-ish way to accomplish this is to call the following method from inside the method:


But this isn't really what we wanted. What I want is for an event to fire when the collision begins--but if the collision ends, and then begins again, I want that event to fire yet again. Destroying the script entirely is no good.

Introducing the 'Enter' script event!

'Enter' script events fire whenever an entity begins contact with another entity. If you leave and come back again, the event fires again. Imagine a switch that you step on that 'untoggles' when you step off of it, and toggles when you step back on--such a situation could be implemented with the Enter script.

Of course, what would 'Enter' be without 'Leave'? And what would a blog post here be without a video to show you all of this stuff? Four major things to notice in the video:

  • Most of the art is no longer ripped from A Link to the Past! In fact, it's not ripped from anywhere! I'll save a special future blog post to introduce the artist, but the game's now one major step closer to being something beyond an engine.
  • The second part of the video demonstrates that the player is an entity just like everything else. Any cool entity effects from earlier blog posts can just as easily be applied to the player!
  • You can't see the code in the video, but I added a method to the scripting interface which allows the designer to find an entity by a special identifier (tag). This is how the switches in the video know how to spawn balls from the braziers.
  • Texture filtering is on now, everything looks much smoother. There's a few quirks to work out with tiling textures, but they're not really critical at the moment.

No comments:

Post a Comment