PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Lovingsoul1337 »

Hi !

here is my code:

Code: Select all

-- 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.

thanks in advance !

best regards

Lovingsoul1337
User avatar
Bobble68
Party member
Posts: 160
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Bobble68 »

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'?
Dragon
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Lovingsoul1337 »

seems like the outer corners of my player sprite collapsing and expand out again.

and the top left bottom right seems to do the same.

--> made a vid with geforce experience

https://www.youtube.com/watch?v=uvoMsw-4FC8

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.
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Lovingsoul1337 »

anyone else an idea ?

another question how else could i code this so that i support the most apspect ratios and resolutions ?
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by milon »

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.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by milon »

Oops, double post! :3
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:

main.lua

Code: Select all


-- 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by zorg »

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 :3True 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.
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Lovingsoul1337 »

https://discord.com/channels/1108070667 ... 3742718002

my game as zip for the ones interested.

still not fixed unfornatly.
Lovingsoul1337
Citizen
Posts: 53
Joined: Fri Feb 21, 2020 1:26 pm

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by Lovingsoul1337 »

Can someone test my code and can tell me if you have the same stutter and artiact problem ?

do close out driver issues.

thanks all for ya help.
User avatar
marclurr
Party member
Posts: 105
Joined: Fri Apr 22, 2022 9:25 am

Re: PlayerSprite stutter and eventually is artifacted if drawn on canvas else not

Post by marclurr »

Your link leads nowhere (for me at least). It would be easier for people to offer help if you attach your .love here directly.
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests