diff options
author | the lemons <citrons@mondecitronne.com> | 2022-08-27 02:49:55 -0500 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2022-08-27 02:50:27 -0500 |
commit | a96780e04d22c916921be996a6b99487efc4e569 (patch) | |
tree | c83eec2efa53b4f54b56bc0fd750c0c5ad46c920 | |
parent | 0e89c14698023c50001fb820c82f2f59b0730b03 (diff) |
store the current camera as an attribute of the world
-rw-r--r-- | Bolvis.lua | 1 | ||||
-rw-r--r-- | Camera.lua | 4 | ||||
-rw-r--r-- | main.lua | 6 | ||||
-rw-r--r-- | world.lua | 3 |
4 files changed, 8 insertions, 6 deletions
@@ -20,6 +20,7 @@ local Hand = component( function Bolvis:init(inst) inst.hand = self.obj.world:object(Hand {bolvis = self.obj}) inst.camera = self.obj.world:object(Camera {following = self.obj}) + inst.camera[Camera]:use() inst.blink = 10 end @@ -5,6 +5,10 @@ local Transform = require 'Transform' local Camera = component({Transform}) function Camera:use() + self.obj.world.camera = self +end + +function Camera:transform() local trans = self.obj:get(Transform):love() local cam_trans = love.math.newTransform(1920 / 2, 1080 / 2) love.graphics.applyTransform(cam_trans * trans:inverse()) @@ -17,9 +17,7 @@ function love.load() love.mouse.setRelativeMode(true) level = world() - local bolvis = level:object(Transform {pos = {960, 540}}, Bolvis()) - camera = bolvis[Bolvis].i.camera[Camera] - + level:object(Transform {pos = {960, 540}}, Bolvis()) level:object(Transform {pos = {400, 540}}, Sprite {name = 'utah-teapot'}) level:object(Transform {pos = {600, 540}}, Sprite {name = 'apioform'}) level:object(Transform {pos = {960, 300}}, Sprite {name = 'test'}) @@ -51,7 +49,7 @@ end function love.draw() love.graphics.applyTransform(screen_transform()) - camera:use() + level.camera:transform() local to_draw = {} for o in level:iterate(Drawable) do table.insert(to_draw, o) @@ -74,8 +74,7 @@ function obj_proto:require(ct, instance) end local world_proto = {} -local world_mt = - {__index = world_proto, __newindex = function()assert(false)end} +local world_mt = {__index = world_proto} local function world() local w = setmetatable({objects = {}, components = {}}, world_mt) |