Reputation: 147
I am making a game in Lua that requires an image to change multiple times. The way I am doing it right now is to display a new image over the old one. This works but it causes a lot of lag. I am wondering if someone knows a way to get rid of the old image and then place the new image in the same location. Thanks guys.
Example of what I'm doing each time something happens:
local function checkPlayer1()
if P1 == 1 then
player1 = display.newImage("1.png",64,128) --starting
end
if P1 == 2 then
player1 = display.newImage("2.png",64,128)
end
if P1 == 3 then
player1 = display.newImage("3.png",64,128)
end
if P1 == 4 then
player1 = display.newImage("4.png",64,128)
end
if P1 == 5 then
player1 = display.newImage("5.png",64,128) --dead
end
end
Upvotes: 4
Views: 2173
Reputation: 5525
I'm guessing, by the look of it, it's Corona SDK. You can use player1:removeSelf()
to remove the previous image object before creating a new one. That's assuming player1
is a global (or a closure) that points to the previous image.
Upvotes: 5