Hello ,
I somehow managed to make coin patterns in my game but I’m having a hard time spawning them.
Here’s my code :
coinPatterns[1] = { {1,0,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0,0}, {0,0,1,0,0,0,0,0,0}, {0,0,0,1,0,0,0,0,0}, {0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,1,0,0,0}, {0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,0,0,1,0}, {0,0,0,0,0,0,0,0,1}, } coinPattern = coinPatterns[1]; local function genCoin(coinPattern) if gamePaused == false then for i = 1, 9 do for j = 1, 9 do if coinPattern[i][j] == 1 then coin = display.newImageRect(COINGROUP,"assets/images/coin.png", \_H/15, \_H/ coin.x = \_W + j\*(\_H/15) coin.y = (i\*\_H/15) coin.myName = "coin" coin.id = "coin" coin.isSensor = true physics.addBody( coin, "static") coin:toBack() end end end end function onCollision(event) local platform = event.other if platform.myName == "character" then event.contact.isEnabled = false coin.isVisible=false currentCoins = currentCoins + 1 end end coin:addEventListener("collision", onCollision) transition.to(COINGROUP,{time=6000,x = -\_W \* 2}) end
I also tried
local function globalCollision(event) if event.object1.myName == "character" and event.object2.id == "coin" then print("Character Coin Collision") end end Runtime:addEventListener("collision",globalCollision)
But it just doesn’t collide. Maybe I’m missing something, but my other collisions like character and bottom wall is working .