create room canvas
This commit is contained in:
parent
2a41828540
commit
55a5991820
3 changed files with 63 additions and 4 deletions
43
conf.lua
Normal file
43
conf.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
gw = 480
|
||||||
|
gh = 270
|
||||||
|
sx = 1
|
||||||
|
sy = 1
|
||||||
|
|
||||||
|
function love.conf(t)
|
||||||
|
t.identity = nil -- The name of the save directory (string)
|
||||||
|
t.version = "11.5" -- The LÖVE version this game was made for (string)
|
||||||
|
t.console = false -- Attach a console (boolean, Windows only)
|
||||||
|
|
||||||
|
t.window.title = "BYTEPATH Clone" -- The window title (string)
|
||||||
|
t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
|
||||||
|
t.window.width = gw -- The window width (number)
|
||||||
|
t.window.height = gh -- The window height (number)
|
||||||
|
t.window.borderless = false -- Remove all border visuals from the window (boolean)
|
||||||
|
t.window.resizable = true -- Let the window be user-resizable (boolean)
|
||||||
|
t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
|
||||||
|
t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
|
||||||
|
t.window.fullscreen = false -- Enable fullscreen (boolean)
|
||||||
|
t.window.fullscreentype = "exclusive" -- Standard fullscreen or desktop fullscreen mode (string)
|
||||||
|
t.window.vsync = true -- Enable vertical sync (boolean)
|
||||||
|
t.window.fsaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
|
||||||
|
t.window.display = 1 -- Index of the monitor to show the window in (number)
|
||||||
|
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
|
||||||
|
t.window.srgb = false -- Enable sRGB gamma correction when drawing to the screen (boolean)
|
||||||
|
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
|
||||||
|
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
|
||||||
|
|
||||||
|
t.modules.audio = true -- Enable the audio module (boolean)
|
||||||
|
t.modules.event = true -- Enable the event module (boolean)
|
||||||
|
t.modules.graphics = true -- Enable the graphics module (boolean)
|
||||||
|
t.modules.image = true -- Enable the image module (boolean)
|
||||||
|
t.modules.joystick = true -- Enable the joystick module (boolean)
|
||||||
|
t.modules.keyboard = true -- Enable the keyboard module (boolean)
|
||||||
|
t.modules.math = true -- Enable the math module (boolean)
|
||||||
|
t.modules.mouse = true -- Enable the mouse module (boolean)
|
||||||
|
t.modules.physics = true -- Enable the physics module (boolean)
|
||||||
|
t.modules.sound = true -- Enable the sound module (boolean)
|
||||||
|
t.modules.system = true -- Enable the system module (boolean)
|
||||||
|
t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
|
||||||
|
t.modules.window = true -- Enable the window module (boolean)
|
||||||
|
t.modules.thread = true -- Enable the thread module (boolean)
|
||||||
|
end
|
||||||
16
obj/Room.lua
16
obj/Room.lua
|
|
@ -4,12 +4,14 @@
|
||||||
---@field area Area room area
|
---@field area Area room area
|
||||||
---@field id string room id
|
---@field id string room id
|
||||||
---@field super Room
|
---@field super Room
|
||||||
|
---@field main_canvas love.Canvas
|
||||||
local Room = Object:extend()
|
local Room = Object:extend()
|
||||||
|
|
||||||
---Instantiates room.
|
---Instantiates room.
|
||||||
function Room:new()
|
function Room:new()
|
||||||
self.area = Area(self)
|
self.area = Area(self)
|
||||||
self.id = UUID()
|
self.id = UUID()
|
||||||
|
self.main_canvas = love.graphics.newCanvas(gw, gh)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Updates room (see [love.update()](lua://love.update))
|
---Updates room (see [love.update()](lua://love.update))
|
||||||
|
|
@ -19,7 +21,21 @@ function Room:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Draws graphics (see [love.draw()](lua://love.draw))
|
---Draws graphics (see [love.draw()](lua://love.draw))
|
||||||
|
---**DO NOT OVERRIDE:** use Room:canvasDraw() instead
|
||||||
function Room:draw()
|
function Room:draw()
|
||||||
|
love.graphics.setCanvas(self.main_canvas)
|
||||||
|
love.graphics.clear()
|
||||||
|
self:canvasDraw()
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
|
||||||
|
love.graphics.setColor(255, 255, 255, 255)
|
||||||
|
love.graphics.setBlendMode('alpha', 'premultiplied')
|
||||||
|
love.graphics.draw(self.main_canvas, 0, 0, 0, sx, sy)
|
||||||
|
love.graphics.setBlendMode('alpha')
|
||||||
|
end
|
||||||
|
|
||||||
|
---Draw to the canvas
|
||||||
|
function Room:canvasDraw()
|
||||||
self.area:draw()
|
self.area:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ function Stage:new()
|
||||||
Stage.super.new(self)
|
Stage.super.new(self)
|
||||||
self.timer = Timer()
|
self.timer = Timer()
|
||||||
self.timer:every(2, function()
|
self.timer:every(2, function()
|
||||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, 800), love.math.random(1, 600))
|
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
|
||||||
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
@ -15,7 +15,7 @@ function Stage:update(dt)
|
||||||
Stage.super.update(self, dt)
|
Stage.super.update(self, dt)
|
||||||
|
|
||||||
if input:pressed('action') then
|
if input:pressed('action') then
|
||||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, 800), love.math.random(1, 600))
|
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh), {radius = 15})
|
||||||
end
|
end
|
||||||
|
|
||||||
if input:pressed('right') then
|
if input:pressed('right') then
|
||||||
|
|
@ -27,8 +27,8 @@ function Stage:update(dt)
|
||||||
self.timer:update(dt)
|
self.timer:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Stage:draw()
|
function Stage:canvasDraw()
|
||||||
Stage.super.draw(self)
|
Stage.super.canvasDraw(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Stage
|
return Stage
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue