I forgot what I was doing because it's 4:30am
This commit is contained in:
@@ -1,18 +1,54 @@
|
||||
import engine;
|
||||
import node;
|
||||
|
||||
//variables
|
||||
var parent: opaque = null;
|
||||
var x: int = 50;
|
||||
var y: int = 50;
|
||||
|
||||
//accessors
|
||||
fn getX() {
|
||||
print "Called getX";
|
||||
return x;
|
||||
}
|
||||
|
||||
fn getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
//lifecycle functions
|
||||
fn onInit(node: opaque) {
|
||||
node.loadTextureEngineNode("assets/sprites/character.png");
|
||||
print "render.toy:onInit() called";
|
||||
|
||||
node.loadTexture("assets/sprites/character.png");
|
||||
print "loaded texture";
|
||||
|
||||
parent = node.getNodeParent();
|
||||
print "accessed parent";
|
||||
}
|
||||
|
||||
fn onStep(node: opaque) {
|
||||
//
|
||||
print "render.toy:onStep()";
|
||||
}
|
||||
|
||||
fn onFree(node: opaque) {
|
||||
node.freeTextureEngineNode();
|
||||
print "render.toy:onFree() called";
|
||||
|
||||
node.freeTexture();
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
node.drawEngineNode(50, 50, 100, 100);
|
||||
}
|
||||
//print "render.toy:onDraw() called";
|
||||
|
||||
var px = parent.callNode("getX");
|
||||
var py = parent.callNode("getY");
|
||||
|
||||
if (px == null) {
|
||||
px = 0;
|
||||
}
|
||||
|
||||
if (py == null) {
|
||||
py = 0;
|
||||
}
|
||||
|
||||
node.drawNode(x + px, y + py, 100, 100);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
import engine;
|
||||
import node;
|
||||
|
||||
fn _makeChild(parent: opaque, fname: string, init: bool) {
|
||||
fn _makeChild(parent: opaque, fname: string) {
|
||||
var child: opaque = loadNode(fname);
|
||||
|
||||
if (init) {
|
||||
child.initNode();
|
||||
}
|
||||
|
||||
parent.pushNode(child);
|
||||
child.initNode();
|
||||
}
|
||||
|
||||
//root node can load the whole scene, and essentially act as the scene object
|
||||
@@ -17,16 +13,17 @@ fn onInit(node: opaque) {
|
||||
print "root.toy:onInit() called";
|
||||
|
||||
//make a child
|
||||
node.makeChild("assets/scripts/child.toy", true); //indicate whether to call "init" on the new node or not
|
||||
node.makeChild("assets/scripts/child.toy", false);
|
||||
node.makeChild("assets/scripts/child.toy", false);
|
||||
// node.makeChild("assets/scripts/child.toy");
|
||||
// node.makeChild("assets/scripts/child.toy");
|
||||
node.makeChild("assets/scripts/render.toy");
|
||||
|
||||
//actually, grab that first node and free it
|
||||
node.freeChildNode(0); //must be done from the parent node, so it's pointer can be nullified
|
||||
print node;
|
||||
print node.getNodeChild(0);
|
||||
|
||||
var r = loadNode("assets/scripts/render.toy");
|
||||
var o = node.getNodeChild(0);
|
||||
print o.callNode("getX");
|
||||
|
||||
node.pushNode(r);
|
||||
print node.getNodeChild(0).callNode("getX");
|
||||
}
|
||||
|
||||
fn onStep(node: opaque) {
|
||||
|
||||
Reference in New Issue
Block a user