Ok, I posted a previous topic about collision detection between separate groups and I could not get it to work so now my new post is how to efficiently move 100 coins across the screen without losing performance and fps?
Since I cannot put 100 coins in a display group and move just the display group because I would lose the physics collision detection, I have to leave them out of a group and move them individually across the screen in the “enterFrame” event listener. However, when I test it on my ITouch 3G, the performance sucks. It slows down and my game is not playable.
Again, what would be the best method to move 100 coins across the screen? I tried to use transitions and translate but they all give me performance problems like the “enterFrame” event listener. My BEST method was to place the 100 coins in a display group and move the group across the screen and there was no performance lag in my ITouch 3G, however, I lost my physics collision detection and that is key in my game because I want to detect when the character hits a coin and make the coin disappear.
Another idea I was thinking, but I haven’t done it yet. Would it be better to keep my coins static and just move my character and camera instead towards the coins like those Doodle Jump games? I’m thinking that would be more efficient, however, how would I do that? If I place my coins static on the screen, how would I move my character towards the coins and still simulate a Parallax Scrolling effect?
Note: I’m using the Director class and placing my 100 coins in the localGroup object. My character is also placed in the local group object.
Here is my code. I have an outer loop and inner loop running because I have different shapes for my coins and each shape is stored in a table. The outer table stores the inner table shapes. As you can see, running for loops in the enterFrame event listener is not efficient and it’s taking a toll on my performance:
[code]
function MoveCoinsTable(coinsTable, xOffset, yOffset, turboOffset)
if (PlayState.InGame == true) then
if (PlayState.MoveCoinsStarted == false) then
PlayState.MoveCoinsStarted = true
local index1 = 1
for index1 = 1, #coinsTable + 1, 1 do
if (coinsTable[index1] ~= nil) then
local innerCoinsTable = coinsTable[index1]
local index2 = 1
for index2 = 1, #innerCoinsTable + 1, 1 do
if (innerCoinsTable[index2] ~= nil) then
local coin = innerCoinsTable[index2]
coin.x = coin.x - (xOffset * (.50 + (turboOffset / 4)))
if ((coin.x + (coin.width / 2)) <= 0) then
coin.x = _W + (coin.width / 2)
end
end
end
if (index1 == #coinsTable and index2 == #innerCoinsTable) then
PlayState.MoveCoinsStarted = false
end
end
end
end
end
end
– Code to get 100 coins
local _coinsTable = Coins.GetCoins()
local tPrevious = system.getTimer()
function MoveEnvironment(event)
if (PlayState.InGame == true) then
local tDelta = event.time - tPrevious
tPrevious = event.time
local turboOffset = 50
local xOffset = ( 0.20 * tDelta )
local yOffset = ( 0.15 * tDelta )
MoveCoinsTable(_coinsTable, xOffset, yOffset, turboOffset)
end
end
Runtime:addEventListener(“enterFrame”, MoveEnvironment)
[/code] [import]uid: 87837 topic_id: 17109 reply_id: 317109[/import]