0
\$\begingroup\$

How can I clear the entire display? I have tried doing display.remove(obj) and obj:removeSelf() on everything that was drawn, but it seems to miss a few things and I am unsure why.

A very basic version of this part would look like this:

Runtime:addEventListener("accelerometer", onShake)
Runtime:addEventListener( "touch", draw );

--Initialize arrScreen and other variables

function onShake (event)
  if event.isShake then
    --for loops
      display.remove(arrScreen[i][j])
      --arrScreen[i][j]:removeSelf()
    --end for loops
  end
end

function draw(event)
  if event.phase == "began" then
    arrScreen[event.x][event.y]=display.newRect(event.x,event.y,size,size)
    lastPoint.x=event.x
    lastPoint.y=event.y
  elseif event.phase ~= "ended" then
    arrScreen[event.x][event.y]=display.newLine(event.x,event.y,lastPoint.x,lastPoint.y)
    lastPoint.x=event.x
    lastPoint.y=event.y
  end
end
\$\endgroup\$
4
\$\begingroup\$

With Corona SDK, you normally group things such as sprites.

myGroup = display.newGroup() -- create a new group
myGroup:insert(sprite1) -- insert sprite1 in it
myGroup:insert(sprite2) -- insert sprite2 in it
myGroup:removeSelf() -- remove everything in this group
myGroup = nil -- nil the group's reference
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

To clear the entire screen, you have to remove all display objects you have created. I would recommend creating a table and inserting all objects into it.

objectsOnScreen = {}
-- Everytime you create a new display object, add it to the table
local newObject = display.newImage("foo.png")
table.insert(objectsOnScreen, newObject)

Then when you want to remove all objects from screen:

local function removeAllScreenObjects()
  for i=1, #objectsOnScreen do
    objectsOnScreen[i]:removeSelf()
    -- Can also use: objectsOnScreen[i].isVisible = false
    objectsOnScreen[i] = nil
  end
end

Another option is to create a rectangle the size of the screen and drawing it on top of everything.

Hope this helps.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.