I have a restart button that resets the entire scene except these apples that are falling from the sky, the code for them is as follows.
-- Insert knife io.output():setvbuf("no") -- Don't use buffer for console messages display.setStatusBar(display.HiddenStatusBar) local allTmp = {} local physics = require("physics") physics.start() physics.setGravity(0,9.8) --physics.setDrawMode( "hybrid" local function onTouch( self, event ) allTmp[self] = nil display.remove(self) return true end local function createKnife( ) -- Randomly create one of five knife images local imgNum = math.random( 1, 5 ) local tmp = display.newImage( "knife.png", 295/5, 482/5 ) tmp.myName = "tmp" -- Randomly place the knife tmp.y = -50 tmp.x = math.random( 50, 430 ) -- Scale it to make a 'smaller' balloon --tmp:scale( 0.1, 0.1 ) tmp:scale(0.3,0.3) -- add a touch listener -- Give it a body so 'gravity' can pull on it physics.addBody( tmp, { radius = tmp.contentWidth/2, bounce=1.5 } ) -- Give the body a random rotation tmp.angularVelocity = math.random( -180, 180 ) -- Give it drag so it doesn't accelerate too fast tmp.linearDamping = 1 allTmp.bounce = 10 -- Self destruct in 5 seconds timer.performWithDelay( 100000, function() allTmp[tmp] = nil display.remove( tmp ) end ) end
But when I use the code local.sceneGroup = self.view in the destroy section and click restart, it restarts everything except the apples in that code, instead it makes it double so how do I reset it completely so that it is the same falling pace and frequency every time?
On the code it says knife but I changed it to apples as an image in the actual game but never changed the code.
Basically how do i reset everything completely, only the code above doesn’t seem to reset instead it doubles.