Added onLoad() lifecycle function
This commit is contained in:
@@ -4,24 +4,25 @@ import engine;
|
||||
import node;
|
||||
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChildSprite(parent: opaque, spriteName: string) {
|
||||
var child: opaque = loadNode("scripts:/tilemap/tile.toy");
|
||||
//TODO: replace with an empty node function (polyfill)
|
||||
fn loadChildEmpty(parent: opaque) {
|
||||
var child: opaque = loadNode("scripts:/empty.toy");
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
|
||||
child.loadTexture("sprites:/" + spriteName);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
fn onLoad(node: opaque) {
|
||||
//load the child node, with the tiling back image
|
||||
node.makeChildSprite("tile-background.png");
|
||||
node.loadChildEmpty();
|
||||
}
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
node.getChildNode(0).loadTexture("sprites:/tile-background.png");
|
||||
}
|
||||
|
||||
|
||||
//drawing util
|
||||
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
//get the constants from root
|
||||
var root: opaque = getRootNode();
|
||||
|
||||
@@ -4,24 +4,25 @@ import engine;
|
||||
import node;
|
||||
|
||||
|
||||
//util to generate and init a child node of a given parent
|
||||
fn makeChildSprite(parent: opaque, spriteName: string) {
|
||||
var child: opaque = loadNode("scripts:/tilemap/tile.toy");
|
||||
//TODO: replace with an empty node function (polyfill)
|
||||
fn loadChildEmpty(parent: opaque) {
|
||||
var child: opaque = loadNode("scripts:/empty.toy");
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
|
||||
child.loadTexture("sprites:/" + spriteName);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
fn onLoad(node: opaque) {
|
||||
//load the child node, with the tiling back image
|
||||
node.makeChildSprite("tile-wall.png");
|
||||
node.loadChildEmpty();
|
||||
}
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
node.getChildNode(0).loadTexture("sprites:/tile-wall.png");
|
||||
}
|
||||
|
||||
|
||||
//drawing util
|
||||
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
//get the constants from root
|
||||
var root: opaque = getRootNode();
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
//EMPTY
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user