-- main.lua
-- graphics
love.graphics.setDefaultFilter('nearest', 'nearest', 0)
love.graphics.setBackgroundColor(0.2, 0.2, 0.2)
-- canvas
local canvas = love.graphics.newCanvas(240, 135)
-- require
local gameStateManager = require('gameStateManager')
local playscene = require('playscene')
function love.load()
-- add scenes
gameStateManager:addScene('playscene', playscene)
-- set currentScene
gameStateManager:setCurrentScene('playscene')
-- load scenes
gameStateManager:load()
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
end
function love.update(dt)
gameStateManager:update(dt)
end
function love.draw()
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 0)
love.graphics.setBlendMode("alpha")
gameStateManager:draw()
love.graphics.print("FPS: " .. love.timer.getFPS(), 10, 10)
love.graphics.setCanvas()
love.graphics.setBlendMode("alpha", "premultiplied")
love.graphics.scale(8, 8)
love.graphics.draw(canvas, 0, 0)
end
did i do something wrong ?
i did try vsync on and off and doesn't seem to have any effect. also changing canvas size doesn't seem to help and checking my driver settings with vsync on and off. also i startet my game via command console to be sure my code editor doesn't do anything.
if someone has anything else what i can try would be well appreciated.
I can't find anything obviously wrong with it - I don't have the required modules, so I had to remove them to test it, but without them it runs fine on my pc. Maybe your GPU doesn't fully support canvases?
Side note, what do you mean exactly when you say the player sprite 'is artefacted'?
can't have to do with my tilemap drawing i tought there is the problem since i draw in my map.lua file the most.
but even without my map the player looks like on this video.
best regards
Lovingsoul1337
eventually i ain't use a anymore canvas sound's me to complicated anyways i try a maximum map size for my platformer instead and center there my map and offer some common resolutions.
and scale by the right values.
canvas sounded cool draw all on a small canvas and rezize this to whatever the resolution is and have everything perfectly screen fittet scaled and sized.
You've only uploaded part of your code so I can't test it. Nothing in main.lua does much of anything with your sprite. The problem could be a GeForce driver issue, or it could be a bug in your gameStateManager or playscene libraries. I suggest creating a .love and uploading so we can test. (Just zip the folder contents together, and rename the .zip to .love)
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Lovingsoul1337 wrote: ↑Wed Dec 27, 2023 3:11 pm
another question how else could i code this so that i support the most apspect ratios and resolutions ?
Make your screen layout responsive to the current screen resolution - similar to how HTML/CSS accomplishes this on the web. Everyone has a different way of doing so. My suggestion is something like this:
-- do all globals, requires, etc here (outside of all functions and before you do anything else)
-- make sure all tables, etc are created for use
function love.load()
local w, h = love.graphics.getDimensions()
love.resize(w, h) -- force a call to the resize function so you have 1 place where you do all dimension-related calculations
-- this is about the only reason for love.load to exist, IMHO
end
function love.resize(w, h) -- gets automatically called when the user resizes the screen or changes resolution
-- note that it's more mobile-friendly to do this:
local x, y, w, h = love.window.getSafeArea() -- use this function since it's aware of screen notches etc
-- now do all graphics layout calculations here and store the values in your tables made at the start
-- decide on sizes for various parts of the gui, sprite multipliers if any, etc
-- make sure to release any previously existing objects before re-creating them! Otherwise your memory use will skyrocket just from resizing the window. This can be a simple check. For example, assuming you store the player's sprite in table player.sprite:
if player.sprite then player.sprite:release() end
player.sprite = love.graphics.newImage...
end
EDIT: You can see a functional version of this in my Wordle clone at viewtopic.php?p=248963#p248963. Note that I opted to put "love.resize(love.graphics.getDimensions())" at the very end of main.lua instead of using love.load() at all.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
You could also consider not killing your performance by recreating everything graphics related every time you resize your project by just having a virtual resolution that's constant, and tied to a canvas, then you only need to position and scale that canvas to fit the actual window/screen resolution.
While i don't really recommend using the Push library, it does implement this in its own way.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.