55 lines
814 B
Plaintext
55 lines
814 B
Plaintext
import node;
|
|
|
|
//variables
|
|
var parent: opaque = null;
|
|
var x: int = 50;
|
|
var y: int = 50;
|
|
|
|
//accessors
|
|
fn getX(node: opaque) {
|
|
print "Called getX";
|
|
return x;
|
|
}
|
|
|
|
fn getY(node: opaque) {
|
|
return y;
|
|
}
|
|
|
|
//lifecycle functions
|
|
fn onInit(node: opaque) {
|
|
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) {
|
|
print "render.toy:onFree() called";
|
|
|
|
node.freeTexture();
|
|
}
|
|
|
|
fn onDraw(node: opaque) {
|
|
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);
|
|
}
|