feat: P.0.lib.camera integration — center camera + camera.begin/finish in render hook
This commit is contained in:
20
init.lua
20
init.lua
@@ -1,8 +1,8 @@
|
||||
local maps = require("lib-core.maps")
|
||||
local r_lib = require("lib-core.render")
|
||||
local camera = require("lib-core.camera")
|
||||
|
||||
-- inline stubs (extract in P.0.lib.{camera,input,player_control,actor,interaction})
|
||||
local camera = { hello = function() return "camera stub" end }
|
||||
-- inline stubs (extract in P.0.lib.{input,player_control,actor,interaction})
|
||||
local input = { hello = function() return "input stub" end }
|
||||
local player_control = { hello = function() return "player_control stub" end }
|
||||
local actor = { hello = function() return "actor stub" end }
|
||||
@@ -11,31 +11,39 @@ local interaction = { hello = function() return "interaction stub" end }
|
||||
local demo_map = maps.load("maps/demo.map.json")
|
||||
maps.set_current(demo_map)
|
||||
|
||||
-- Center camera on map center
|
||||
local m_size = maps.size()
|
||||
local t_size = maps.tile_size()
|
||||
camera.set_target((m_size.w * t_size) / 2, (m_size.h * t_size) / 2)
|
||||
camera.set_zoom(1.0)
|
||||
|
||||
local frames = 0
|
||||
local TARGET_FRAMES = 60
|
||||
|
||||
function init(ctx)
|
||||
engine.print("spine-prototype init: maps loaded")
|
||||
engine.print("inline stubs loaded: "
|
||||
.. camera.hello() .. ", "
|
||||
.. input.hello() .. ", "
|
||||
.. player_control.hello() .. ", "
|
||||
.. actor.hello() .. ", "
|
||||
.. interaction.hello())
|
||||
local size = maps.size()
|
||||
engine.print(string.format("map size: %dx%d", size.w, size.h))
|
||||
engine.print(string.format("map size: %dx%d", m_size.w, m_size.h))
|
||||
local corner = maps.tile_at(0, 0)
|
||||
local interior = maps.tile_at(5, 5)
|
||||
engine.print("tile at (0,0): " .. corner.id)
|
||||
engine.print("tile at (5,5): " .. interior.id)
|
||||
engine.print("walkable at (0,0): " .. tostring(maps.is_walkable(0, 0)))
|
||||
engine.print("walkable at (5,5): " .. tostring(maps.is_walkable(5, 5)))
|
||||
engine.print(string.format("render: %d tiles per frame", size.w * size.h))
|
||||
engine.print(string.format("render: %d tiles per frame", m_size.w * m_size.h))
|
||||
local t = camera.target()
|
||||
engine.print(string.format("camera: target=(%d,%d) zoom=%.2f", t.x, t.y, camera.zoom()))
|
||||
end
|
||||
|
||||
function render(ctx)
|
||||
engine.render.clear_color(engine.render.rgb(20, 20, 30))
|
||||
camera.begin()
|
||||
r_lib.draw_map()
|
||||
camera.finish()
|
||||
end
|
||||
|
||||
function update(ctx, dt)
|
||||
|
||||
Reference in New Issue
Block a user