How to move a part of a canvas

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.
Post Reply
User avatar
shingoscar
Prole
Posts: 3
Joined: Fri Aug 28, 2020 2:01 pm

How to move a part of a canvas

Post by shingoscar »

Code: Select all

function love.load(arg, unfilteredArg)
    image = love.graphics.newImage('blocks.png')
    canvas = love.graphics.newCanvas(1000, 1000)
    canvas:renderTo(function ()
        love.graphics.draw(image, 0, 0)
    end)
end

function love.draw()
    love.graphics.draw(canvas)
end
I want to move a part of the canvas (0,0,100,100) to (100,100), so I use the code below:

Code: Select all

canvas:renderTo(function ()
    local quad = love.graphics.newQuad(0, 0, 100, 100, canvas:getDimensions())
    love.graphics.draw(canvas, quad, 100, 100)
end)
But this gives me the error: Cannot render a Canvas to itself!

Please help me to achieve the purpose.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: How to move a part of a canvas

Post by ReFreezed »

Just draw 'image' to different coordinates?

Code: Select all

canvas:renderTo(function()
	love.graphics.draw(image, 100, 100)
end)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
shingoscar
Prole
Posts: 3
Joined: Fri Aug 28, 2020 2:01 pm

Re: How to move a part of a canvas

Post by shingoscar »

ReFreezed wrote: Sat Oct 03, 2020 4:05 pm Just draw 'image' to different coordinates?
Thanks, but the image here is for convience, the canvas is quite complex than a single image.
User avatar
steVeRoll
Party member
Posts: 131
Joined: Sun Feb 14, 2016 1:13 pm

Re: How to move a part of a canvas

Post by steVeRoll »

Then clear the canvas and redraw it, with the image in the new coordinates.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to move a part of a canvas

Post by zorg »

Or use two canvases, and render one to the other, and then swap, and only draw out the currently active one to the screen... not sure which approach has the best performance; your original issue was that you can't render to the same canvas you want to draw, but you can render one to another, probably even with a quad.
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.
Post Reply

Who is online

Users browsing this forum: No registered users and 100 guests