Page 1 of 1
How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 1:05 am
by nPwn
Like I have this:
function love.draw()
love.graphics.draw(one,0, 0)
end
how would I erase the picture "one"?
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 2:37 am
by Jasoco
Simple answer. Stop drawing it. That's basically it. Use if's and then's and variables to determine if it's supposed to draw or not.
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 2:51 am
by nPwn
Jasoco wrote:Simple answer. Stop drawing it. That's basically it. Use if's and then's and variables to determine if it's supposed to draw or not.
But if I have already drawn it then how would I stop? This is what I have.
local one, two, three
local a = 1
function love.load()
one = love.graphics.newImage("one.png")
two = love.graphics.newImage("two.png")
three = love.graphics.newImage("three.png")
love.graphics.setBackgroundColor(255,255,255)
end
timer, called = 0, 0
function love.update(dt)
if a == 4 then
return end
timer = timer + dt
if timer > 1 and called < 2 then
if a == 1 then
function love.draw()
love.graphics.draw(three,0, 0)
a = 2
end
elseif a == 2 then
function love.draw()
love.graphics.draw(two,0, 0)
a = 3
end
elseif a == 3 then
function love.draw()
love.graphics.draw(one,0, 0)
a = 4
end
end
timer = 0
called = called + 1
end
end
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 3:04 am
by Jasoco
Please edit your post to use the CODE tags. I can't read that code without indentation.
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 3:41 am
by nPwn
How do I do that?
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 4:28 am
by tentus
When you paste code into your message, pit the button labeled "Code" just before you do so. It'll make it look like this:
Code: Select all
local one, two, three
local a = 1
function love.load()
one = love.graphics.newImage("one.png")
two = love.graphics.newImage("two.png")
three = love.graphics.newImage("three.png")
love.graphics.setBackgroundColor(255,255,255)
end
timer, called = 0, 0
function love.update(dt)
if a == 4 then
return end
timer = timer + dt
if timer > 1 and called < 2 then
if a == 1 then
function love.draw()
love.graphics.draw(three,0, 0)
a = 2
end
elseif a == 2 then
function love.draw()
love.graphics.draw(two,0, 0)
a = 3
end
elseif a == 3 then
function love.draw()
love.graphics.draw(one,0, 0)
a = 4
end
end
timer = 0
called = called + 1
end
end
Now, a quick correction that HAS TO be addressed immediately. function love.draw() should never be inside another function. Ever. Put functions and if statements inside of love.draw all you want, but not the other way around.
If you do that, your code comes out like this:
Code: Select all
function love.draw()
if a == 1 then
love.graphics.draw(one,0, 0)
elseif a == 2 then
love.graphics.draw(two,0, 0)
elseif a == 3 then
love.graphics.draw(three,0, 0)
end
end
Or, even better, if you put your images into a table you can skip the if statement in love.draw, like this:
Code: Select all
function love.load()
imgs = {}
imgs[1] = love.graphics.newImage("one.png")
imgs[2]= love.graphics.newImage("two.png")
imgs[3] = love.graphics.newImage("three.png")
love.graphics.setBackgroundColor(255,255,255)
end
function love.draw()
love.graphics.draw(imgs[a],0, 0)
end
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 5:21 am
by nPwn
Okay thanks. I am new to love but not new to lua. I learned lua from ROBLOX originally. So back to my original question, is there anyway to "undraw" or erase an image?
Re: How do you delete a picture that you have drawn?
Posted: Thu Jan 26, 2012 6:52 am
by tentus
As Jasoco started to explain, the answer is
no, but it's an inappropriate question for Love. Once you've drawn an image, it will stay drawn for the rest of the frame. The very next frame starts you over though, the screen is clear out. Remember, love.draw is called each frame, so if you've got an FPS of 60, love.draw is being called 60 times in sequence.
This article will help you out a lot, conceptually.
tl;dr: Don't worry about it.