how do you delete one object without clearing the whole screen?
?
If you are going with a list-based approach, just have a list of objects with sprite, width, height, x, and y data (i,e
init = function()
objects = [
["sprite1", -0, -10, 30, 30]
["sprite2", -40, 5, 10, 30]
["sprite3", 3, 100, 60, 134]
["sprite1", 23, -40, 50, 30]
]
end
) then in draw, iterate through them.
draw = function()
screen.clear()
for obj in objects
screen.drawSprite(obj[0], obj[1], obj[2], obj[3], obj[4])
end
end
and if you want to, say, remove the last object when you press the F key, you could do that in update pretty simply
update = function()
if keyboard.press.F then
objects.removeAt(objects.length-1)
end
end
or maybe you want to remove the third object after 300 frames?
update = function()
if t >= 300 and not removed then
removed = 1
objects.removeAt(2)
end
t += 1
end
Hope this helps :D
Thanks a lot this really helps.
yw :)