Last active
August 29, 2015 14:06
-
-
Save markknol/cb584b1d934f493b098d to your computer and use it in GitHub Desktop.
HeartBeat component
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
package nl.stroep.games.components; | |
import flambe.animation.AnimatedFloat; | |
import flambe.Component; | |
import flambe.util.Value; | |
/** | |
* @author Mark Knol [http://blog.stroep.nl] | |
*/ | |
class HeartBeat extends Component | |
{ | |
public var beat:Value<Int>; | |
public var beatsPerMinute:AnimatedFloat; | |
public var ticksPerBeat:Int; | |
var _current:Float = 0; // seconds | |
public function new(beatsPerMinute:Int = 80, ticksPerBeat:Int = 4) | |
{ | |
this.ticksPerBeat = ticksPerBeat; | |
this.beatsPerMinute = new AnimatedFloat(beatsPerMinute); | |
this.beat = new Value<Int>(0); | |
} | |
override public function onUpdate(dt:Float) | |
{ | |
beatsPerMinute.update(dt); | |
_current += dt; | |
beat._ = Std.int((_current % 60) / 60 * beatsPerMinute._) % ticksPerBeat; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment