Hi this is complacently driving me bonkers. but is it possible to to use preCollision ?
local platform = display.newImage( "platform.png" ) platform.collType = "passthru" physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } ) function character:preCollision( event ) local collideObject = event.other if ( collideObject.collType == "passthru" ) then event.contact.isEnabled = false --disable this specific collision! end end
here is a bigger snip of my code :
local starTable = {} -- Set up star table badc1CollisionFilter = { categoryBits = 1, maskBits = 16 } badc2CollisionFilter = { categoryBits = 2, maskBits = 16 } badc3CollisionFilter = { categoryBits = 4, maskBits = 16 } wallCollisionFilter = { categoryBits = 8, maskBits = 16 } playerCollisionFilter = { categoryBits = 16, maskBits = 15 } function initStar() local star1 = {} star1.imgpath = "Cloud1.png"; --Set Image Path for Star star1.movementSpeed = 10000; --Determines the movement speed of star table.insert(starTable, star1); --Insert Star into starTable local star2 = {} star2.imgpath = "Cloud2.png"; star2.movementSpeed = 12000; table.insert(starTable, star2); local star3 = {} star3.imgpath = "Cloud3.png"; star3.movementSpeed = 14000; table.insert(starTable, star3); local star4 = {} star4.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; star4.movementSpeed = 16000; table.insert(starTable, star4); local star5 = {} star5.imgpath = "Cloud5.png"; star5.movementSpeed = 18000; table.insert(starTable, star5); end --END initStar() function getRandomStar() local temp = starTable[math.random(1, #starTable)] -- Get a random star from starTable local randomStar = display.newImage(temp.imgpath) -- Set image path for object if ( temp.imgpath == "BCloud1.png" ) then local objectb1 = physics.addBody( randomStar, { density=.1, bounce=0.1, friction=.2, radius=45, filter=badc1CollisionFilter } ) randomStar.myName = "BCloud1" temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; end if ( temp.imgpath == "BCloud2.png" ) then physics.addBody( randomStar, { density=.1, bounce=0.1, friction=.2, radius=45, filter=badc2CollisionFilter } ) randomStar.myName = "BCloud2" temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; end if ( temp.imgpath == "BCloud3.png" ) then physics.addBody( randomStar, { density=.1, bounce=0.1, friction=.2, radius=45, filter=badc3CollisionFilter } ) randomStar.myName = "BCloud3" temp.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; end randomStar.myName = "star" -- Set the name of the object to star randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move randomStar.x = math.random(-30, \_W); randomStar.y = -35; randomStar.rotation = math.random(0,20) -- Rotate the object starMove = transition.to(randomStar, { time=randomStar.movementSpeed, y=500, onComplete = function(self) self.parent:remove(self); self = nil; end }) -- Move the star end--END getRandomStar() function newCollisionHandler( self, event ) print("oh hello i have a Collision") if myName == "BCloud1" then print("Collided with star1") elseif event.other.myName == "BCloud2" then print("Collided with star2") elseif event.other.myName == "BCloud3" then print("Collided with star3") end end playerSpriteSheet = sprite.newSpriteSheet("player.png", 113, 55) playerSprites = sprite.newSpriteSet(playerSpriteSheet, 1, 4) sprite.add(playerSprites, "players", 1, 4, 1000, 0) player = sprite.newSprite(playerSprites) player.x = -80 player.y = 350 player:prepare("players") player:play() player.collided = false player:setReferencePoint(display.CenterReferencePoint); physics.addBody(player, "static", {density=.1, bounce=0.1, friction=.2, radius=10, filter=playerCollisionFilter } ) player.gravityScale = 0 screenGroup:insert(player) playerIntro = transition.to(player,{time=2000, x=150, onComplete=playerReady}) function scene:enterScene(event) jet.collision = newCollisionHandler jet:addEventListener( "collision", jet ) end