Files
LNXSDK/leenkx/Sources/leenkx/logicnode/PulseNode.hx
2025-01-22 16:18:30 +01:00

43 lines
670 B
Haxe

package leenkx.logicnode;
import iron.system.Time;
class PulseNode extends LogicNode {
var running = false;
var interval: Float;
var lastTick: Null<Float>;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
if (from == 0) {
// Start
interval = inputs[2].get();
if (!running) {
tree.notifyOnUpdate(update);
running = true;
}
}
else if (from == 1) {
// Stop
if (running) {
tree.removeUpdate(update);
running = false;
}
}
}
function update() {
var tick = Time.time();
if (lastTick == null || tick - lastTick > interval) {
runOutput(0);
lastTick = tick;
}
}
}