shadwork,
I tried the app on my android and it worked fine, but I can’t get the collision detection to work on the Windows simulator. The collision between the hero (bird) and the top or bottom work fine. But the collision between the hero and the poles (line, lineTop, blocks[]) does not work. Am I looking at an older version? Did you run into a problem like this?
Here’s the code that creates the hero:
[lua]
local heroSpriteSheet = sprite.newSpriteSheet(“heroes.png”, 85, 78)
local heroSprites = sprite.newSpriteSet(heroSpriteSheet, 1, 8)
sprite.add(heroSprites, “swap”, 1, 7, 500, 1)
sprite.add(heroSprites, “stay”, 6, 1, 1000, 0)
hero = sprite.newSprite(heroSprites)
hero.x = halfW
hero.y = halfH
hero:prepare(“stay”);
hero:play(“stay”)
physics.addBody(hero, “static”, {density=.1, bounce=0.1, friction=.2, radius=2.1})
screenGroup:insert(hero)
[/lua]
Here’s the code that makes the poles:
[lua]
for i = 1, 8, 1 do
line = display.newImage(“contur.png”)
line:setReferencePoint(display.TopLeftReferencePoint)
line.speed = 4
line.x = halfW + 54*4 * i
line.y = math.random(holeShift,screenH-holeShift)
line.cross = false
if i==1 then
line.y = math.random(holeShift +hole,screenH-(holeShift-hole))
end
physics.addBody(line, “static”, {density=.1, bounce=0.1, friction=.2})
screenGroup:insert(line)
blocks[i\*2] = line
lineTop = display.newImage(“line.png”)
lineTop:setReferencePoint(display.BottomLeftReferencePoint)
lineTop.x = line.x
lineTop.y = line.y - hole
physics.addBody(lineTop, “static”, {density=.1, bounce=0.1, friction=.2})
screenGroup:insert(lineTop)
blocks[1 + i*2] = lineTop
end
[/lua]
Here is the collision detection code:
[lua]
local function onCollision(event)
if event.phase == “began” then
print(“collision detected”)
hero.bodyType = “static”
end
[/lua]
Here is the code that scrolls the poles across the screen:
[lua]
function scrollBlock(self ,event)
for i = 1, 8, 1 do
if blocks[i\*2].cross == false then
if blocks[i\*2].x < hero.x and blocks[i\*2].x + 54 >hero.x then
blocks[i\*2].cross=true
--audio.play(soundProcess)
score = score +1
scoreMeter.text = score
end
end
blocks[i\*2].x = blocks[i\*2].x - blocks[i\*2].speed
blocks[1+i*2].x = blocks[i\*2].x
if blocks[i\*2].x <= -54*4*3 then
blocks[i\*2].cross=false
blocks[i\*2].x = halfW + 54 + 54 * 4 * 4
blocks[i\*2].y = math.random(holeShift,screenH-holeShift)
blocks[1+i*2].x = blocks[i\*2].x
blocks[1+i*2].y = blocks[i\*2].y - hole
end
end
end
[/lua]
Any thoughts would be appreciated.