Like I have this:
function love.draw()
love.graphics.draw(one,0, 0)
end
how would I erase the picture "one"?
How do you delete a picture that you have drawn?
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How do you delete a picture that you have drawn?
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?
But if I have already drawn it then how would I stop? This is what I have.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.
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
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: How do you delete a picture that you have drawn?
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?
How do I do that?
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How do you delete a picture that you have drawn?
When you paste code into your message, pit the button labeled "Code" just before you do so. It'll make it look like this:
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:
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
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
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
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
Kurosuke needs beta testers
Re: How do you delete a picture that you have drawn?
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?
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: How do you delete a picture that you have drawn?
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.
This article will help you out a lot, conceptually.
tl;dr: Don't worry about it.
Kurosuke needs beta testers
Who is online
Users browsing this forum: No registered users and 6 guests