Created
September 9, 2014 08:32
-
-
Save markknol/1367d030757754bc9825 to your computer and use it in GitHub Desktop.
Heartbeat component implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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