question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event Properties with Callbacks

See original GitHub issue

Hey again!

In the game I am creating, it will be necessary to be able to know when I am interacting with certain tiles on the map. Since the plugin is the one handling collision checks and movement, I suggest a number of properties that could be super useful for map events. I’ll also give a use case for each event, but these mechanics would be implemented by the game developer. I am only suggesting we add properties for certain tilemap-based events.

  • onEnter - this event would trigger any time a certain tile has been entered. This could be used in such cases as initiating fights, minigames or puzzle mechanics.

  • onStanding - this event will trigger every frame that the character is standing on the given tile. This could be used for automated platforms for puzzles, weight buttons or healing pads.

  • onExit - this event will trigger when the character leaves a given tile. This could be used to trigger trap doors, or other cinematic effects such as rockslides behind the player.

  • onFacing - this event could be triggered when the player is adjacent to and facing the given tile. This could be used to initiate interactions with objects, dialog with NPCs, et cetera. This would, however, require adding a “facing” mechanic to the plugin itself to implement.

The uses for such events are immense; players could define “trigger” areas on a tilemap that would start certain events or cinematics, and it would facilitate a lot of dynamic interactions with the world such as dialogs, shops, puzzles, platforms, et cetera.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
splashskycommented, Mar 4, 2021

It looks excellent. I presume we could grab any tile property we wanted via this method, so it’s flexible enough. Excellent work!

0reactions
Annoraaqcommented, Mar 9, 2021

@splashsky Published with 1.7.0 release.

There is now an observable positionChanged() as well as a method for getting movement state: isMoving(). I also added methods for getting (getFacingDirection()) and setting (turnTowards()) the facing direction.

There are three new examples to demonstrate their usage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Events and Callbacks
To react to an event you listen for it and supply a function which will be called by the browser when the event...
Read more >
Defining behavior with event callbacks and listeners
Windows generate events when the user moves or resizes the window. To handle these events, define callback functions for onMove , onMoving ,...
Read more >
javascript - How to add event object to a callback function?
Instead, use the modern approach to event handling and use .addEventListener() separately in your JavaScript. Then, the event object reference ...
Read more >
Events and Callbacks - Framework Design Guidelines
Events are a special case of callbacks that supports convenient and consistent syntax for supplying the delegate (an event handler).
Read more >
DOM - Event Object (Callback function parameter)
A event callback function may have a parameter specified with a name such as event, evt, or simply e. This is the event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found