Skip to content

Instantly share code, notes, and snippets.

@markknol
Created September 9, 2014 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markknol/1367d030757754bc9825 to your computer and use it in GitHub Desktop.
Save markknol/1367d030757754bc9825 to your computer and use it in GitHub Desktop.
Heartbeat component implementation
var _connection:SignalConnection;
override public function onStart()
{
// grap HeartBeat component somewhere in parent entities
var heartBeat = owner.getFromParents(HeartBeat);
// listen to it
_connection = heartBeat.beat.changed.connect(onBeatChanged);
// if you want invoke the listener directly, you could use
//_connection = heartBeat.beat.watch(onBeatChanged);
}
function onBeatChanged(to:Int, from:Int)
{
if (to == 0) // on first note
{
trigger();
}
}
function trigger()
{
trace("spikes triggered at first note");
}
// clean up references
override public function dispose()
{
_connection.dispose();
super.dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment