I’ve got a sprite walking slowly into a brick (composer). The collision detection works when I place the two near but stop working at a distance. It’s a difference of around 5 seconds.
I’ve tried toggling sleeping and awake in both composer and script for both sprite and bricks, but no change, also tried putting these in various locations. I’ve disabled nearly all my code and can’t figure it out. The composer bricks are dynamic.
I’ve run out of ideas on this so help would be amazing
[lua]
function collisionHandler(self,e)
print (e.phase … " " … e.name)
print (“test”)
end
–construct hero man
local heroMan
local function constructHeroMan()
local walkingSheetOptions = {width = 79, height = 101, numFrames = 8}
local local_walkingSheet = graphics.newImageSheet (“walkingMan2.png”, walkingSheetOptions)
local sequences_walkingMan1 =
{
{name = “walk”,frames = {1,2,3,4},time = 500,loopCount = 0,loopDirection = “forward”}
}
heroMan = display.newSprite (local_walkingSheet, sequences_walkingMan1)
physics.addBody(heroMan, “static”, {isSensor=true}) --<<<<
heroMan.isSleepingAllowed = false
--heroMan.isAwake = true
heroMan.y = 500; heroMan.x = 800
heroMan:setSequence(“walk”)
heroMan.name = “heroMan”
heroMan:play()
heroMan.collision = collisionHandler
heroMan:addEventListener(“collision”,heroMan)
local function animateHeroMan(event)
heroMan.x = heroMan.x + 1
end
Runtime:addEventListener(“enterFrame”, animateHeroMan)
end
constructHeroMan()
[/lua]