Added animations to node
This commit is contained in:
22
assets/scripts/frames.toy
Normal file
22
assets/scripts/frames.toy
Normal file
@@ -0,0 +1,22 @@
|
||||
import node;
|
||||
|
||||
fn onInit(node: opaque) {
|
||||
node.loadTexture("sprites:/frametest.png");
|
||||
|
||||
//mapped to the given image
|
||||
node.setNodeRect(0, 0, 32, 32);
|
||||
node.setNodeFrames(3);
|
||||
}
|
||||
|
||||
var counter = 0;
|
||||
fn onStep(node: opaque) {
|
||||
counter++;
|
||||
if (counter >= 60) {
|
||||
counter = 0;
|
||||
node.incrementCurrentNodeFrame();
|
||||
}
|
||||
}
|
||||
|
||||
fn onDraw(node: opaque) {
|
||||
node.drawNode(0, 0);
|
||||
}
|
||||
@@ -28,4 +28,4 @@ mapInputEventToKeyUp("character_right", "right"); //event, keysym
|
||||
initWindow("Airport Game", 1080, 720, false);
|
||||
|
||||
//kick off the logic of the scene graph
|
||||
loadRootNode("scripts:/scene.toy");
|
||||
loadRootNode("scripts:/frames.toy");
|
||||
|
||||
@@ -60,7 +60,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
//render each tile
|
||||
for (var j = lowerY; j <= upperY; j++) {
|
||||
for (var i = lowerX; i <= upperX; i++) {
|
||||
node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||
node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
|
||||
continue;
|
||||
}
|
||||
|
||||
node.getNodeChild(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||
node.getChildNode(0).drawNode(round(camX_mod + i * tileWidth_mod), round(camY_mod + j * tileHeight_mod), tileWidth_mod, tileHeight_mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import standard;
|
||||
import node;
|
||||
|
||||
//TODO: get child count
|
||||
var childCounter: int = 0;
|
||||
|
||||
var levelXCount: int const = 4;
|
||||
@@ -49,7 +50,7 @@ fn onDraw(node: opaque) {
|
||||
|
||||
//iterate over each layer, passing in the screen dimensions
|
||||
for (var c = 0; c < childCounter; c++) {
|
||||
node.getNodeChild(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2);
|
||||
node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user