My app is made for iPad. Viewed Portrait, there is a red bar at the bottom of the screen and a blue bar at the top. When a user taps on the screen, a disk appears. I made it so that the disk is either blue or red. There is also gravity, so the disks fall down to the red bar. I want to make it so that when a blue disk touches the red bar, it is removed, but the red disks will do nothing. Since I don’t have a definitive name for the disks, I am not sure what to call to remove(in the last function)?
Here’s my code…
[code]local redBase = display.newImage(“redBase.png”)
redBase.y = 1008
physics.addBody(redBase, “static”, {bounce = 1, friction = 1})
local blueBase = display.newImage(“blueBase.png”)
blueBase.y = 15
physics.addBody(blueBase, “static”, {bounce = 1, friction = 1})
local diskGfx = { “redDisk.png”, “blueDisk.png”}
local allDisks = {} – empty table for storing objects
local function spawnDisk( event )
local phase = event.phase
if “ended” == phase then
randImage = diskGfx[math.random( 1, 2 )]
allDisks[#allDisks + 1] = display.newImage( randImage )
local disk = allDisks[#allDisks]
disk.x = event.x; disk.y = event.y
disk.rotation = math.random( 1, 360 )
disk.xScale = 0.8; disk.yScale = 0.8
physics.addBody( disk, { bounce= 1, density=1, friction=1, radius= 30.0 } )
disk.linearDamping = 0.4
disk.angularDamping = 0.6
end
end
background:addEventListener( “touch”, spawnDisk ) – touch the screen to create disks
local function removeBlueDisk(event)
if(event.phase == “began”) then
disk:removeSelf()
end
end
redBase.collision = removeBlueDisk
redBase:addEventListener(“collision”, removeBlueDisk)
[/code]
Sorry about the bland title, I didn’t know what the problem I am having would be called… [import]uid: 7116 topic_id: 6873 reply_id: 306873[/import]
[import]uid: 7116 topic_id: 6873 reply_id: 24147[/import]