Hi All,
I'm working on my second app and I'm trying to create efficient code so I'm using modules and tables. In this project I have students clicking on directional arrows to make a robot go through a course, then when the robot finishes the course, they press the "clear" button to remove all of the stored robot movements. (as they click the directional arrows, a visual representation of what they have clicked appears on the screen). Everything is working fine except the removal of the images that show what they have clicked. To show the initial images I am doing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | function turnImages() if introduction.turn1 == "forward" then firstImage = display.newImage(imageTable[1]) firstImage.x= 50; firstImage.y = 30 else if introduction.turn1 == "right" then firstImage = display.newImage(imageTable[2]) firstImage.x= 50; firstImage.y = 30 else if introduction.turn1 == "backward" then firstImage = display.newImage(imageTable[3]) firstImage.x= 50; firstImage.y = 30 else if introduction.turn1 == "left" then firstImage.x= 0; firstImage.y = 0 else if introduction.turn1 == nil then firstImage = display.newImage(imageTable[5]) end end end end end |
use a for loop to remove all your data in table
1 2 3 4 | for i=1,#table do display.remove(table[i]) -- get rid of images table[i] = nil -- clear the table end |
Awesome! Thank you!
views:1243 update:2011/12/28 9:26:54