I am stumped to why when the bird goes over the gems it picks and chooses the gems to pick up. Can not figure out why it won’t interact with all the gems very confused. Please any advice on this would be greatly appreciated.
local gemMove1 = function() local function handleOnComplete(target) target:removeSelf() target = nil end myAnimation = display.newSprite( redSheet, sequenceData ) myAnimation.y = 1 + math.random( 450 ); myAnimation.x = 800 physics.addBody(myAnimation, "dynamic", {isSensor = true}) transition.to(myAnimation,{time = math.random(6000,25000),x=(W-2000), onComplete = handleOnComplete}) myAnimation:setSequence( "Gem1" ) myAnimation:play() myAnimation.type = "gems1" myAnimation.value = 1 sceneGroup:insert(myAnimation) end local gemMove2 = function() local function handleOnComplete(target) target:removeSelf() target = nil end myAnimation2 = display.newSprite( greenSheet, sequenceData ) myAnimation2.y = 1 + math.random( 450 ); myAnimation2.x = 800 physics.addBody(myAnimation2, "dynamic", {isSensor = true}) transition.to(myAnimation2,{time = math.random(6000,25000),x=(W-2000), onComplete = handleOnComplete}) myAnimation2:setSequence( "Gem1" ) myAnimation2:play() myAnimation2.type = "gems2" myAnimation2.value = 1 sceneGroup:insert(myAnimation2) end local sheetInfo = require("spirdyAnimations") local myImageSheet = graphics.newImageSheet( "spirdyAnimations.png", sheetInfo:getSheet() ) local sequenceData2 = {{ name="forwards", sheet = myImageSheet, start=83, count=41, time=6000, loopCount=0 }, { name="backwards", sheet =myImageSheet, start=1, count=41,time=6000, loopCount=0 }, { name="upwards", sheet =myImageSheet, start=124, count=41, time=6000, loopCount=0 }, { name="downwards", sheet =myImageSheet, start=42, count=41, time=6000, loopCount=0 }} --display the sprite sheets bird1 = display.newSprite( myImageSheet, sequenceData2 ) bird1.x = display.contentWidth/2 ; bird1.y = display.contentHeight/2 local imageFile = "forwards0.png" local imageOutline = graphics.newOutline( 2, imageFile ) physics.addBody( bird1, "dynamic", { outline=imageOutline, density=100, friction=0.0, bounce=0.0 } ) bird1:play() bird1.type = "player" local imageFile2 = "backwards0.png" local imageOutline2 = graphics.newOutline( 2, imageFile2 ) local imageFile3 = "up0.png" local imageOutline3 = graphics.newOutline( 2, imageFile3 ) local imageFile4 = "down0.png" local imageOutline4 = graphics.newOutline( 2, imageFile4 ) -- Listens for the Analog stick function moveAnalog(e) if e.phase == "began" then MyStick.x = e.x MyStick.y = e.y e.target = MyStick.Thumb e.phase = "began" MyStick.onDrag(e) elseif e.phase == "moved" then timer.createTimer(0, transition.cancel(tapAnalog)) end end Runtime:addEventListener("touch", moveAnalog) physics.setDrawMode( "hybrid" ) -- Moves Spirdy around the level function main( event ) -- MOVE THE SHIP MyStick:move(bird1, 6.0, false) if MyStick:getAngle()\>= 45 and MyStick:getAngle()\<= 135 and bird1.sequence ~= "forwards" then physics.removeBody(bird1) bird1:setSequence( "forwards") bird1:play() physics.addBody( bird1, "dynamic", { outline=imageOutline, density=100, friction=0.0, bounce=0.0 } ) bird1.isFixedRotation = true bird1.type = "player" elseif MyStick:getAngle()\>= 225 and MyStick:getAngle()\<= 315 and bird1.sequence ~= "backwards" then physics.removeBody(bird1) bird1:setSequence( "backwards") bird1:play() local imageFile2 = "backwards0.png" local imageOutline2 = graphics.newOutline( 2, imageFile2 ) physics.addBody( bird1, "dynamic", { outline=imageOutline2, density=100, friction=0.0, bounce=0.0 } ) bird1.isFixedRotation = true bird1.type = "player" elseif MyStick:getAngle()\> 315 and MyStick:getAngle()\<= 360 and bird1.sequence ~= "upwards" or MyStick:getAngle()\> 0 and MyStick:getAngle()\< 45 and bird1.sequence ~= "upwards" then physics.removeBody(bird1) bird1:setSequence( "upwards") bird1:play() local imageFile3 = "up0.png" local imageOutline3 = graphics.newOutline( 2, imageFile3 ) physics.addBody( bird1, "dynamic", { outline=imageOutline3,density=100, friction=0.0, bounce=0.0 } ) bird1.isFixedRotation = true bird1.type = "player" elseif MyStick:getAngle()\> 135 and MyStick:getAngle()\< 225 and bird1.sequence ~= "downwards" then physics.removeBody(bird1) bird1:setSequence( "downwards") bird1:play() local imageFile4 = "down0.png" local imageOutline4 = graphics.newOutline( 2, imageFile4 ) physics.addBody( bird1, "dynamic", {outline=imageOutline4, density=100, friction=0.0, bounce=0.0 } ) bird1.isFixedRotation = true bird1.type = "player" end end Runtime:addEventListener( "enterFrame", main ) bird1.type = "player" -- Collides with the Red gem and adds to the counter local function onCollision(event) if event.phase == "began" then local player = event.object1 local gem1 = event.object2 print("--------------------------almost") if player.type == "player" and gem1.type == "gems1" then score.add(event.object2.value) event.object2.alpha = 0 print("------------------------got it") end end end Runtime:addEventListener("collision", onCollision) -- Collides with the Gree gem and adds to the counter local function onCollision2(event) if event.phase == "began" then local player = event.object1 local gem2 = event.object2 print(" almost") if player.type == "player" and gem2.type == "gems2" then score.add(event.object2.value) event.object2.alpha = 0 print(" got it") end end end