Hi all.
I’m messing with some code from the modified “Many crates” from the “How to Display and Save Scores” tutorial, but I’m running into an issue when using the code with composer - here’s modified Many Crates:
https://www.dropbox.com/s/u3vz4cquely690s/Scores.zip
Obviously, if I create a new display group within scene:create (and insert the “apple” into the group, from within the newApple function), my touch event listener will remove all display objects within said group - without inserting them into the scene:create, the touch event listener completely ignores them.
Is there an alternative way I can insert them (individually, not a group) into scene:create from within the function? Or Is there something very obvious I’m missing, and it’s an easy fix?
Here’s the code I’ve modified:
local function newApple() rand = math.random( 200 ) local apple if (rand \< 80) then apple = display.newImageRect("assets/apple1.png", 70, 75); apple.y = 90 + math.random( 200 ) apple.x = -25 timer.performWithDelay(2000, function() display.remove( apple ); end) physics.addBody( apple, "dynamic", {filter=appleCollisionFilter} ) apple:applyLinearImpulse( 0.5, 0.2, apple.x, apple.y ) apple.value = 50 elseif (rand \< 60) then apple = display.newImageRect("assets/apple4.png", 70, 75) apple.y = 90 + math.random( 200 ) apple.x = -25 timer.performWithDelay(2000, function() display.remove( apple ); end) physics.addBody( apple, "dynamic", {filter=apple2CollisionFilter} ) apple:applyLinearImpulse( 0.5, 0.2, apple.x, apple.y ) apple.value = 100 elseif (rand \<100) then apple = display.newImageRect("assets/apple3.png", 70, 75); apple.y = 90 + math.random( 200 ) apple.x = -25 timer.performWithDelay(2000, function() display.remove( apple ); end) physics.addBody( apple, "dynamic", {filter=apple4CollisionFilter} ) apple:applyLinearImpulse( 0.5, 0.2, apple.x, apple.y ) apple.value = 100 else apple = display.newImageRect("assets/apple2.png", 70, 75); apple.y = 90 + math.random( 200 ) apple.x = -25 timer.performWithDelay(2000, function() display.remove( apple ); end) physics.addBody( apple, "dynamic", {filter=apple3CollisionFilter} ) apple:applyLinearImpulse( 0.5, 0.2, apple.x, apple.y ) apple.value = 500 return apple end end
Any help will be greatly appreciated!
Kind regards,
Lewis