Added sorting layers to nodes

This commit is contained in:
2023-06-29 13:47:35 +10:00
parent 51a0c94ba2
commit 2d6ad5efcc
10 changed files with 39 additions and 44 deletions

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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)
);