Added onLoad() lifecycle function

This commit is contained in:
2023-03-03 00:50:45 +11:00
parent 00587e91b2
commit 4965cd492d
11 changed files with 90 additions and 64 deletions

View File

@@ -6,44 +6,25 @@ import node;
var camX: float = 0;
var camY: float = 0;
var stepCounter: int = 0;
var stepTracker: [int] = [0, 0, 0, 0, 0, 0];
//util to generate and init a child node of a given parent
fn makeChild(parent: opaque, fname: string) {
//util to generate a child node of a given parent
fn loadChild(parent: opaque, fname: string) {
var child: opaque = loadNode(fname);
parent.pushNode(child);
child.initNode();
return child;
}
fn loadLayer(node: opaque, layerName: string) {
//load the given layer as a child
var layerNode = node.makeChild("scripts:/tilemap/" + layerName);
var layerNode = node.loadChild("scripts:/tilemap/" + layerName);
}
//lifecycle functions
fn onStep(node: opaque) {
stepCounter++;
camX--;
camY--;
}
fn onDraw(node: opaque) {
var tmp = stepCounter;
print stepCounter;
stepCounter = 0;
if (tmp > 5) {
tmp = 5;
}
print typeof (stepTracker[tmp] + 1);
//TODO: index[]++
stepTracker[tmp] = stepTracker[tmp] + 1;
print stepTracker;
var screenWidth: int const = getRootNode().callNodeFn("getScreenWidth");
var screenHeight: int const = getRootNode().callNodeFn("getScreenHeight");