Made UI render on a different canvas, implemented defaultZoom

This commit is contained in:
entar 2025-06-11 09:34:45 +07:00
parent 5dde11ce55
commit 83df5079a4
11 changed files with 85 additions and 10 deletions

12
log.log

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,7 @@ local function state(songName, songDifficulty)
local beat = 0
local zoom = 1
local uiZoom = 1
local volume = 100
local modules = {}
@ -360,6 +361,7 @@ local function state(songName, songDifficulty)
end
if beat % 4 == 0 then
zoom = zoom + .02
uiZoom = uiZoom + .05
end
else
for name, character in next, characters do
@ -525,7 +527,8 @@ local function state(songName, songDifficulty)
end
end
zoom = myMath.lerp(zoom, 1, .05)
zoom = myMath.lerp(zoom, stage.defaultZoom or 1, .05)
uiZoom = myMath.lerp(uiZoom, 1, .05)
if inst and inst:getVolume() ~= volume / 100 then
inst:setVolume(volume / 100)
@ -554,6 +557,7 @@ local function state(songName, songDifficulty)
end
local mainCanvas
local uiCanvas
function state.draw()
@ -563,6 +567,12 @@ local function state(songName, songDifficulty)
myTypes.drawSprites()
love.graphics.setCanvas(uiCanvas)
love.graphics.clear()
myTypes.drawUI()
if ui.ratings then
for index, window in next, rankWindows do
love.graphics.print({{0,0,0,1}, tostring(ratings[window.rating])}, evenBiggerFont, 200, 330 + 75 * (index - 1))
@ -603,9 +613,9 @@ local function state(songName, songDifficulty)
love.graphics.setCanvas()
love.graphics.draw(mainCanvas, (love.graphics.getWidth() - (love.graphics.getWidth() * zoom)) / 2, (love.graphics.getHeight() - love.graphics.getHeight() * zoom) / 2, 0, love.graphics.getWidth()/sharedVars.canvasSize.x * zoom, (love.graphics.getHeight()/sharedVars.canvasSize.y * zoom))
love.graphics.draw(uiCanvas, (love.graphics.getWidth() - (love.graphics.getWidth() * uiZoom)) / 2, (love.graphics.getHeight() - love.graphics.getHeight() * uiZoom) / 2, 0, love.graphics.getWidth()/sharedVars.canvasSize.x * uiZoom, (love.graphics.getHeight()/sharedVars.canvasSize.y * uiZoom))
love.graphics.print({{0,0,0,1}, string.format("FPS: %s \nVolume: %s", love.timer.getFPS(), volume)}, font)
end
function state.load()
@ -861,6 +871,7 @@ local function state(songName, songDifficulty)
local canvasSize = sharedVars.canvasSize or myTypes.Vector2(1920,1080)
mainCanvas = love.graphics.newCanvas(canvasSize.x, canvasSize.y)
uiCanvas = love.graphics.newCanvas(canvasSize.x, canvasSize.y)
local screenSize = sharedVars.screenSize or myTypes.Vector2(1280, 720)

View File

@ -19,6 +19,7 @@ module.destroyAllSprites = renderClasses.destroyAllSprites
module.drawSprites = renderClasses.drawSprites
module.updateSprites = renderClasses.updateSprites
module.preload = renderClasses.preLoad
module.drawUI = renderClasses.drawUI
module.Vector2 = vectorClass.Vector2

View File

@ -177,7 +177,10 @@ function module.updateSprites(dt)
module.cameraPosition = module.cameraPosition:Lerp(module.cameraTarget or module.myTypes.Vector2(0,0), .2)
end
local leftOvers = {}
function module.drawSprites()
leftOvers = {}
local everything = {}
for index, image in next, Images do
@ -200,6 +203,10 @@ function module.drawSprites()
end)
for index, thing in ipairs(everything) do
if thing.ui then
leftOvers[#leftOvers+1] = thing
goto continue
end
if thing.isImage then
local cameraOffset = thing.ui and module.myTypes.Vector2() or module.cameraPosition
@ -237,6 +244,52 @@ function module.drawSprites()
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x) + cameraOffset.x * rect.modifier), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y) + cameraOffset.y * rect.modifier), rect.rotation or 0, quad.resize.x * (rect.flipX and -1 or 1), quad.resize.y* (rect.flipY and -1 or 1))
end
end
::continue::
end
end
function module.drawUI()
for index, thing in ipairs(leftOvers) do
if thing.isImage then
local cameraOffset = thing.ui and module.myTypes.Vector2() or module.cameraPosition
love.graphics.draw(thing.image, thing.position.x + cameraOffset.x * thing.modifier , thing.position.y + cameraOffset.y * thing.modifier, thing.rotation, thing.resize.x * (thing.flipX and -1 or 1), thing.resize.y * (thing.flipY and -1 or 1))
elseif thing.isSprite then
local sprite = thing
if sprite.animation and sprite.quads and sprite.quads[sprite.animation] then
local quad = sprite.quads[sprite.animation][sprite.frame] or sprite.quads[sprite.animation][0]
if quad then
if quad.offset.x == 0 and quad.offset.y == 0 and sprite.quads[sprite.animation][0].offset.x ~= 0 then
quad.offset.x = sprite.quads[sprite.animation][0].offset.x
quad.offset.y = sprite.quads[sprite.animation][0].offset.y
end
if sprite.flipX and not quad.flipped then
quad.flipped = true
quad.offset.x = -quad.offset.x
end
local cameraOffset = sprite.ui and module.myTypes.Vector2() or module.cameraPosition or module.myTypes.Vector2()
love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x) + cameraOffset.x * sprite.modifier), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y) + cameraOffset.y * sprite.modifier), sprite.rotation or 0, quad.resize.x * (sprite.flipX and -1 or 1), quad.resize.y* (sprite.flipY and -1 or 1))
end
end
elseif thing.isRect then
local rect = thing
if rect.animation then
local quad = rect.quads[rect.animation][0]
if rect.flipX and not quad.flipped then
quad.flipped = true
quad.offset.x = -quad.offset.x
end
local cameraOffset = rect.ui and module.myTypes.Vector2() or module.cameraPosition or module.myTypes.Vector2()
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x) + cameraOffset.x * rect.modifier), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y) + cameraOffset.y * rect.modifier), rect.rotation or 0, quad.resize.x * (rect.flipX and -1 or 1), quad.resize.y* (rect.flipY and -1 or 1))
end
end
::continue::
end
end

View File

@ -1,6 +1,6 @@
{
"directory": "week4",
"defaultZoom": 0.7,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [500, -140],

View File

@ -1,6 +1,6 @@
{
"directory": "week4",
"defaultZoom": 0.9,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [500, -140],

View File

@ -1,6 +1,6 @@
{
"directory": "",
"defaultZoom": 0.8,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [577, -100],

View File

@ -1,6 +1,6 @@
{
"directory": "",
"defaultZoom": 0.8,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [577, -100],

View File

@ -1,6 +1,6 @@
{
"directory": "",
"defaultZoom": 0.75,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [700, 100],

View File

@ -1,6 +1,6 @@
{
"directory": "",
"defaultZoom": 0.85,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [977, -160],

View File

@ -1,6 +1,6 @@
{
"directory": "",
"defaultZoom": 0.9,
"defaultZoom": 1,
"isPixelStage": false,
"boyfriend": [800, -250],