JohnSundell / ImagineEngine

A project to create a blazingly fast Swift game engine that is a joy to use 🚀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add 'actorAdded' event on Scene

JohnSundell opened this issue · comments

In order to be able to observe whenever an actor was added to a scene, it would be awesome to have an event for it. That way really cool plugins could be written, like this:

class ColorAllActorsPlugin: Plugin {
    func activate(for scene: Scene, in game: Game) {
        scene.events.actorAdded.observe { scene, actor in
            actor.backgroundColor = .red
        }
    }
}

The above plugin would add a red background color to all actors that are added to the scene that the plugin is attached to. Very useful to implement things like debug tools 👍

Things to do:

  • Add a new event on SceneEventCollection for when an actor was added (see the other events for inspiration).
  • Trigger the event when a new actor is added to a scene.

Hi John, please let me know if I might take additional steps at this point. Thanks!

SceneEventCollection