Added sorting layers to nodes
This commit is contained in:
@@ -103,8 +103,8 @@ fn onDraw(node: opaque) {
|
||||
var originOffsetY: int = node.getNodeRectH() * int scaleY / 2;
|
||||
|
||||
node.drawNode(
|
||||
floor(posX * scaleX) - originOffsetX,
|
||||
floor(posY * scaleY) - originOffsetY,
|
||||
floor(posX * scaleX) - originOffsetX + globalCameraX,
|
||||
floor(posY * scaleY) - originOffsetY + globalCameraY,
|
||||
floor(node.getNodeRectW() * scaleX),
|
||||
floor(node.getNodeRectH() * scaleY)
|
||||
);
|
||||
|
||||
@@ -169,12 +169,12 @@ fn onDraw(node: opaque) {
|
||||
var scaleY: float = node.getNodeWorldScaleY();
|
||||
|
||||
//this offset is because the sprite cell for lejana is twice as big as the sprite cell for the floor tiles
|
||||
var originOffsetX: int = node.getNodeRectW() * int scaleX / 4;
|
||||
var originOffsetY: int = node.getNodeRectH() * int scaleY / 2;
|
||||
var originOffsetX: int = player.getNodeRectW() / 2;
|
||||
var originOffsetY: int = player.getNodeRectH();
|
||||
|
||||
node.drawNode(
|
||||
floor(posX * scaleX) - originOffsetX,
|
||||
floor(posY * scaleY) - originOffsetY,
|
||||
floor(posX * scaleX) - originOffsetX + globalCameraX,
|
||||
floor(posY * scaleY) - originOffsetY + globalCameraY,
|
||||
floor(node.getNodeRectW() * scaleX),
|
||||
floor(node.getNodeRectH() * scaleY)
|
||||
);
|
||||
|
||||
@@ -21,13 +21,9 @@ fn onInit(node: opaque) {
|
||||
|
||||
//load and initialize the UI (depends on map stuff)
|
||||
stepCounter = node.loadChild("scripts:/gameplay/step-counter.toy");
|
||||
stepCounter.setNodeRect(
|
||||
0,
|
||||
0,
|
||||
floor(TILE_PIXEL_WIDTH * MAP_GRID_WIDTH * tilemap.getNodeWorldScaleX()), //width - stretches along the top of the tilemap
|
||||
stepCounter.getNodeRectH() //default height
|
||||
);
|
||||
stepCounter.setNodeRect(0, 0, CAMERA_SCREEN_W, 32);
|
||||
stepCounter.callNodeFn("setMaxSteps", 100);
|
||||
stepCounter.setNodeLayer(100);
|
||||
|
||||
//offset the scene node, so it shows the map outside separate from the UI
|
||||
node.setNodePositionY(16);
|
||||
@@ -47,6 +43,17 @@ fn onFree(node: opaque) {
|
||||
fn onDraw(node: opaque) {
|
||||
//use the onDraw to sort - skip too many steps
|
||||
node.sortChildrenNode(depthComparator);
|
||||
|
||||
var scaleX: float = player.getNodeWorldScaleX();
|
||||
var scaleY: float = player.getNodeWorldScaleY();
|
||||
|
||||
//this offset is because the sprite cell for lejana is twice as big as the sprite cell for the floor tiles
|
||||
var originOffsetX: int = player.getNodeRectW() / 2;
|
||||
var originOffsetY: int = player.getNodeRectH() / 2;
|
||||
|
||||
//use the room scene's onDraw to set the global camera position
|
||||
globalCameraX = floor((CAMERA_SCREEN_W / 2) - (player.getNodeWorldPositionX() * scaleX)) - originOffsetX;
|
||||
globalCameraY = floor((CAMERA_SCREEN_H / 2) - (player.getNodeWorldPositionY() * scaleY)) - originOffsetY;
|
||||
}
|
||||
|
||||
//gameplay functions
|
||||
|
||||
@@ -41,6 +41,7 @@ fn alterRemainingSteps(node: opaque, increment: int) {
|
||||
fn loadChild(parent: opaque, fname: string) {
|
||||
var child: opaque = loadNode(fname);
|
||||
parent.pushNode(child);
|
||||
child.setNodeLayer(parent.getNodeLayer());
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ fn onDraw(node: opaque) {
|
||||
|
||||
//draw to the screen
|
||||
node.drawNode(
|
||||
floor((i * TILE_PIXEL_WIDTH + posX) * scaleX),
|
||||
floor((j * TILE_PIXEL_HEIGHT + posY) * scaleY),
|
||||
floor((i * TILE_PIXEL_WIDTH + posX) * scaleX) + globalCameraX,
|
||||
floor((j * TILE_PIXEL_HEIGHT + posY) * scaleY) + globalCameraY,
|
||||
floor(TILE_PIXEL_WIDTH * scaleX),
|
||||
floor(TILE_PIXEL_HEIGHT * scaleY)
|
||||
);
|
||||
|
||||
@@ -5,10 +5,15 @@ var TILE_PIXEL_HEIGHT: int const = 16;
|
||||
var MAP_GRID_WIDTH: int const = 16;
|
||||
var MAP_GRID_HEIGHT: int const = 16;
|
||||
|
||||
var CAMERA_SCREEN_W: int const = 800;
|
||||
var CAMERA_SCREEN_H: int const = 600;
|
||||
|
||||
var CAMERA_SCALE_X: float const = 2.0;
|
||||
var CAMERA_SCALE_Y: float const = 2.0;
|
||||
|
||||
|
||||
//this is a very odd pattern...
|
||||
var globalCameraX: int = 0;
|
||||
var globalCameraY: int = 0;
|
||||
|
||||
//A quirk of the setup is that anything defined in the root of `init.toy` becomes a global object
|
||||
//To resolve that, the configuration is inside a block scope
|
||||
@@ -45,12 +50,7 @@ var CAMERA_SCALE_Y: float const = 2.0;
|
||||
|
||||
|
||||
//this function must always be called, or the engine won't run
|
||||
initWindow(
|
||||
"Airport",
|
||||
floor(TILE_PIXEL_WIDTH * MAP_GRID_WIDTH * CAMERA_SCALE_X),
|
||||
floor(TILE_PIXEL_HEIGHT * MAP_GRID_HEIGHT * CAMERA_SCALE_Y) + 32, //32 is UI space
|
||||
false);
|
||||
//TODO: custom FPS setting
|
||||
initWindow("Skylands", CAMERA_SCREEN_W, CAMERA_SCREEN_H, false); //TODO: custom FPS setting
|
||||
|
||||
//kick off the logic of the scene graph
|
||||
loadRootNode("scripts:/gameplay/scene.toy");
|
||||
|
||||
Reference in New Issue
Block a user