I’ll just start by saying I’m new to programming in general and am teaching myself as I go. So if this is an elementary problem than that is why I don’t get it. I’m using Windows Corona which means Android.
I am trying to create a scenario where circles of random sizes are generated on screen. I want them to be removed from the screen when I touch them.
I have the code set up to generate the circles. I borrowed it from the ManyCrates sample project.
The issue is trying to get a listener set up to respond to touch on the shapes. I’ve read all the documentation in the Resources section, I’ve browsed the forums here trying the code examples, I’ve tried borrowing code from other sample projects and throughout it all tried rearranging all the code pieces as I’ve seen it structured just in the attempt to get anything working.
The problem is that the circles will not show up on the screen. They are supposed to drop from the top and they won’t. Before I started playing with this listener stuff they would drop just fine.
I have a white rectangle set up at the bottom of the screen so I know it’s seeing something from my code.
I can only assume that perhaps removeSelf() is deleting the circle object itself before it can run through the spawn code. I don’t get it.
And to give credit where credit is due, I left off trying to copy how this example did things: http://developer.anscamobile.com/code/tables-lua-dictionaries-and-arrays
This is what I have:
[code]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9)
local ground = display.newRect( 0, 490, 325, 40 )
ground:setFillColor(255, 255, 255, 255)
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
circles = {}
function tapped(event)
event.target:removeEventListener(“touch”, tapped)
event.target:removeSelf()
circles[event.target] = nil
end
function newObj()
rand = math.random( 100 )
if (rand < 60) then
local j = display.newCircle( 20, 20, math.random(10, 40) )
j:setFillColor( 255, 100, 100 , 255 )
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=0.9, friction=0.3, bounce=0.3} )
j:addEventListener( “touch”, tapped )
circles[j] = j
end
for i = 1, 5 do
newObj()
end
end
[/code]
I’m running this in the emulator. Sometimes I’ve had it so that the circles showed up but would not respond to the mouse clicks( which I assumed represented touch), and other times the circles wont show up at all like I said. [import]uid: 20207 topic_id: 6260 reply_id: 306260[/import]