diff options
Diffstat (limited to 'parallax/main.lua')
-rw-r--r-- | parallax/main.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/parallax/main.lua b/parallax/main.lua index 3028d36..6a799f4 100644 --- a/parallax/main.lua +++ b/parallax/main.lua @@ -2,21 +2,22 @@ local boundary = { x = 200, y = 100, w = 100, - h = 80, + h = 20, } local bg = { x = 200, y = 100, w = 150, - h = 80 + h = 20 } local p = { x = boundary.x + 10, y = boundary.y + 10, speed = 1, } - +local sw, sh = jin.graphics.getSize() +local canvas = jin.graphics.newCanvas(sw, sh) function jin.core.onLoad() end @@ -51,8 +52,8 @@ local function updateBg() if jin.keyboard.isPressed("Down") then p.y = p.y + p.speed end - p.x = clamp(p.x, boundary.x, boundary.x + boundary.w) - p.y = clamp(p.y, boundary.y, boundary.y + boundary.h) + p.x = clamp(p.x, boundary.x + 20, boundary.x + boundary.w - 20) + p.y = clamp(p.y, boundary.y + 10, boundary.y + boundary.h - 10) local x0 = boundary.x local x1 = boundary.x + boundary.w @@ -69,6 +70,8 @@ function jin.core.onUpdate(dt) end function jin.core.onDraw() + jin.graphics.bindCanvas(canvas) + jin.graphics.clear() jin.graphics.setColor(100, 100, 100, 255) jin.graphics.rect("fill", bg.x, bg.y, bg.w, bg.h) jin.graphics.setColor(255,255,255,255) @@ -77,4 +80,7 @@ function jin.core.onDraw() jin.graphics.rect("fill", p.x - 2, p.y- 2, 4, 4) jin.graphics.setColor(0, 255, 0) jin.graphics.rect("line", p.x - 20, p.y - 10, 40, 20) + jin.graphics.unbindCanvas() + jin.graphics.setColor(255, 255, 255) + jin.graphics.draw(canvas, 0, 0) end |