I couldn’t find a resolution in the forum so I’m starting a new thread regarding my issue.
I’m trying to make a side scroller game similar to mario brothers however, the difference is that the background and game objects are moving towards the character while the character is static in one location. I used the same code example found in the HorseAnimation game in Corona. I’m also grouping a bunch of coins in a display group and moving the coins towards the character because I don’t want to code each coin individually to move to the character. The display group is like a container where I can just move the group instead of each coin manually.
My problem is that when the character jumps towards the coins, the collision event does not register when the coins are inserted in a display group. However, if I don’t insert the coins in a display group and the character jumps into them, the collision event works correctly.
Now, you might be thinking, “well, don’t insert the coins in the display group and you’re all good”. It’s not that easy. I tried not inserting the coins in a display group and coded logic to move each coin individually towards the character, however, since I’m moving around 20 coins, it started causing issues with the framerate and the performance of my game started slowing down. It’s pretty bad where my character does not jump smoothly and its pretty much unplayable until the coins get removed off the screen.
Oh yeah, I’m testing my game on a 3rd gen IPod Touch with IOS 5 operating system. The game can perform fine on my IPad 2, but the game is slow on the IPod Touch.
If I place all 20 coins in a display group and just move the group in the “enterFrame” event, the performance does not degrade and my game runs fine. However, I lose my collision event because my coins are in a group. I’ve been beating my head on this and coding/re-coding just to get this working but no luck. Can someone help me out? Is it possible to have collision events work across multiple display groups?
Code example below:
[code]
local characterGroup = display.newGroup()
local character = display.newImage(“character.png”, 0, 0)
physics.addBody(character, “dynamic”, {density = 1.0, friction = 0.3, bounce = 0.2})
characterGroup:insert(character)
local coinGroup = display.newGroup()
local coin1 = display.newImage(“coin.png”, 0, 0)
local coin2 = display.newImage(“coin.png”, 0, 0)
local coin3 = display.newImage(“coin.png”, 0, 0)
physics.addBody(coin1, “dynamic”, {density = 1.0, friction=0.3, bounce = 0.2})
physics.addBody(coin2, “dynamic”, {density = 1.0, friction=0.3, bounce = 0.2})
physics.addBody(coin3, “dynamic”, {density = 1.0, friction=0.3, bounce = 0.2})
coinGroup:insert(coin1)
coinGroup:insert(coin2)
coinGroup:insert(coin3)
function MakeCoinSparkle(event)
if (event.other.Name = “character”) then
local coin = event.target
coin.isVisible = false
coinSparkle.isVisible = true
end
end
coin1:addEventListener(“collision”, MakeCoinSparkle)
coin2:addEventListener(“collision”, MakeCoinSparkle)
coin3:addEventListener(“collision”, MakeCoinSparkle)
local tPrevious = system.getTimer()
function MoveCoins(event)
local tDelta = event.time - tPrevious
local xOffset = (.20 * tDelta)
coinGroup.x = coinGroup.x - xOffSet
return true
end
Runtime:addEventListener(“enterFrame”, MoveCoins)
[/code] [import]uid: 87837 topic_id: 17035 reply_id: 317035[/import]