Hi,I am trying to make a new game mechanic with some elements of code examples that i found in corona forums and share code section, all works fine on iOS and medium-high Android devices, but I would like that could run on less powerful phones.I think that the main problem is the number of display objects that exist on the screen at the same time,for this, the ball is fired seems slow in these phones with lower performance.When i reduce the number of columns and rows the problem disappears.
Any help is welcome,or even if not possible please someone tell me something.
--module(..., package.seeall) --Physics local physics = require("physics") ; physics.start() ; --physics.setContinuous( false ) --physics.setGravity( 0,-9,8 ) ; --physics.setDrawMode( "hybrid" ) --physics.setTimeStep(0) --physics.setVelocityIterations( 6 ) display.setStatusBar( display.HiddenStatusBar ) --------------------------------------------------------------------------------- --VARIABLES --------------------------------------------------------------------------------- --SCREEN POSITIONS local \_W = display.contentWidth local \_H = display.contentHeight local \_W\_mitad = \_W \* 0.5 local \_H\_mitad = \_H \* 0.5 local xDispositivo = display.screenOriginX local yDispositivo = display.screenOriginY local tablero = {} local blocks = {} local numOfColumns = 8 --Columns local numOfRows = 12 --Rows local tam\_bloque = 45 local colores = {} local mirror = {} local mRandom = math.random --GROUPS local bricks = display.newGroup() local mirrorGroup = display.newGroup() --SHOT local powerShot,arrow --SCORE local score,scoreText --MATH local mCeil = math.ceil local mAtan2 = math.atan2 local mPi = math.pi local mSqrt = math.sqrt --============================================================ --============================================================ function remove\_listenersBlocks() for i = 1, numOfColumns, 1 do for j = 1, numOfRows, 1 do if(tablero[i][j].hasListener == 1)then tablero[i][j]:removeEventListener("collision", tablero[i][j]) physics.removeBody(tablero[i][j]) end end end end function add\_listenersBlocks () for i = 1, numOfColumns, 1 do for j = 1, numOfRows, 1 do if (tablero[i][j].name == ball.name) then tablero[i][j].collision = bounce tablero[i][j]:addEventListener("collision", tablero[i][j]) physics.addBody(tablero[i][j],"static",{density = 0, friction = 0, bounce = 0}) tablero[i][j].isSensor = true tablero[i][j].hasListener = 1 else tablero[i][j].hasListener = 0 end end end end function createBall() colores = { {200,0,0},{0,200,0},{0,0,200},{180,180,0} } local r,g,b ball = display.newCircle(\_W\_mitad,950,12) physics.addBody(ball, "kinematic", {density = 0.35, friction = 0,bounce = 1,radius = 10}) ball.gravityScale = 0 ball:setReferencePoint( display.CenterReferencePoint ) ball.x = display.contentCenterX; ball.y = 730 ball.isReady = false ball.inAir = false --Listener para ,crear el tirachinas de disparo una vez esta creada la bola Runtime:addEventListener("touch",OnScreenTouch) local color\_pelota = math.random(1,4) --local color\_pelota = 1 if(color\_pelota == 1)then r,g,b = colores[1][1],colores[1][2],colores[1][3] ball.name = 1--"rojo" ball.num = color\_pelota end if(color\_pelota == 2)then r,g,b = colores[2][1],colores[2][2],colores[2][3] ball.name = 2--"verde" ball.num = color\_pelota end if(color\_pelota == 3)then r,g,b = colores[3][1],colores[3][2],colores[3][3] ball.name = 3--"azul" ball.num = color\_pelota end if(color\_pelota == 4)then r,g,b = colores[4][1],colores[4][2],colores[4][3] ball.name = 4--"amarillo" ball.num = color\_pelota end ball:setFillColor(r,g,b) end function resetBall() if (ball.y \> 1000 or ball.x \< -10 or ball.x \> 780 )then physics.removeBody(ball) ball:removeSelf();ball = nil remove\_listenersBlocks() createBall() add\_listenersBlocks() end end --THIS FUNCTION GENERATES EACH NEW BLOCK function newGem (i,j) local newGem local transicion\_inicial --aqui se establece la y inicial del tablero y desde donde se crean los nuevos bloques newGem = display.newRoundedRect(i\*tam\_bloque,-1000,tam\_bloque,tam\_bloque,5) newGem.strokeWidth = 1 --RANDOM FOR EACH BLOCK COLOR local R = mRandom(1,4) if (R == 1 ) then newGem:setFillColor( 200, 0, 0 ) newGem.name = 1--"rojo",RED elseif (R == 2 ) then newGem:setFillColor( 0, 200, 0 ) newGem.name = 2--"verde",GREEN elseif (R == 3 ) then newGem:setFillColor( 0, 0, 200 ) newGem.name = 3--"azul",BLUE elseif (R == 4 ) then newGem:setFillColor( 180, 180, 0 ) newGem.name = 4--"amarillo",YELLOW end local function cancelar\_transicion() transition.cancel(transicion\_inicial) end newGem.i = i newGem.j = j newGem.destination\_y = j\*tam\_bloque+tam\_bloque --new gem falling animation transicion\_inicial = transition.to( newGem, { time=1000, y= newGem.destination\_y,onComplete = cancelar\_transicion} ) bricks:insert( newGem ) bricks.x = 15;bricks.y = 0 return newGem end --BLOCKS ANIMATION WHEN COLLIDES WITH BALL function shiftGems (fila, col) local gemToBeDestroyed = tablero[fila][col] -- shiftin whole column down, element by element in one column for k = col, 2, -1 do -- starting from col - finishing at the second row -- curent markedToDestroy Gem is replaced by the one above in the gemsTable tablero[fila][k] = tablero[fila][k-1] tablero[fila][k].destination\_y = tablero[fila][k].destination\_y + tam\_bloque transition.to( tablero[fila][k], { time=1000, y= tablero[fila][k].destination\_y,transition = easing.inOutExpo } ) -- we change its j value as it has been 'moved down' in the gemsTable tablero[fila][k].j = tablero[fila][k].j + 1 end -- create a new gem at the first row as there is en empty space due to gems -- that have been moved in the column tablero[fila][1] = newGem(fila,1) -- destroy the old gem (the one that was invisible and placed in gemToBeDestroyed holder) gemToBeDestroyed:removeSelf() gemToBeDestroyed = nil end --shiftGems() function destroyGems(qtablero) local cuadrado\_tocado local function cancelar\_transicion() transition.cancel(cuadrado\_tocado) end if (qtablero.isMarkedToDestroy == 1) then cuadrado\_tocado = transition.to( qtablero, { time=0, alpha=0.5,onComplete = cancelar\_transicion} ) score = score + 10 scoreText.text = string.format( "SCORE: %6.0f", score ) scoreText:setReferencePoint(display.TopLeftReferencePoint) scoreText.x = 300 end end --THIS FUNCTION CREATES ALL GAMEPLAY ELEMENTS function addGameScreen() --WALLS local mirrorSet = { { 300, 5, 90 }, { 475, 270, 0 }, { 5, 270, 0 }} for m = 1,#mirrorSet do mirror[m] = display.newImage( mirrorGroup, "image/mirror-rect\_peq.png", true ) physics.addBody( mirror[m], "static", {density = 0,bounce = 1,friction = 0, shape={-35,-337.5,35,-337.5,35,337.5,-35,337.5} } ) mirror[m].x, mirror[m].y, mirror[m].rotation = mirrorSet[m][1], mirrorSet[m][2], mirrorSet[m][3] mirror[m].name = "mirror"..m--le asigno un nombre para saber que objeto estoy golpeando con el rayo end --GAME BOARD(tablero) for i = 1,numOfColumns,1 do tablero[i] = {} for j = 1, numOfRows, 1 do tablero[i][j] = newGem(i,j) end end score = 0 scoreText = display.newText( "SCORE:" , 40, 20, "Helvetica", 20 ) scoreText.text = string.format( "SCORE: %6.0f", score ) scoreText:setReferencePoint(display.TopLeftReferencePoint) scoreText.x = 320 scoreText.y = 760 --SHOT ORB powerShot = display.newImage( "image/glow.png") powerShot.xScale = 1.0; powerShot.yScale = 1.0 powerShot.isVisible = false --DIRECTION ARROW arrow = display.newImage( "image/arrow.png" ) arrow.isVisible = false --CREATE THE BALL createBall() --BLOCKS LISTENERS add\_listenersBlocks () --RUNTIME LISTENER FOR RESET BALL gameListeners("add") end --EVENT WHEN BALL COLLIDES WITH BLOCK function bounce(self,event) if ( event.phase == "began" and self.name == event.other.name) then tablero[self.i][self.j].isMarkedToDestroy = 1 tablero[self.i][self.j]:removeEventListener("collision",tablero[self.i][self.j]) --HIDE THE BLOCKS destroyGems(tablero[self.i][self.j]) --DESTROY AND MOVE BLOCKS timer.performWithDelay(400,shiftGems2(self.i, self.j),1) elseif ( event.phase == "ended" ) then --print( self.name .. ": collision ended with " .. event.other.name ) end end --TOUCH EVENTTO ACTIVATE THE SHOT ORB function OnScreenTouch(event) if (event.x \>= 155 and event.x \<= 325 and event.y \>= 705 and event.y \<=825) then if event.phase == "began" then ball.isReady = true powerShot.isVisible = true powerShot.alpha = 0.75 powerShot.x = ball.x; powerShot.y = ball.y powerShot.xScale = 0.1; powerShot.yScale = 0.1 arrow.isVisible = true arrow.x = powerShot.x; arrow.y = powerShot.y elseif event.phase == "ended" and ball.isReady then fling = function() powerShot.isVisible = false arrow.isVisible = false local factor = 12 local x = event.x local y = event.y xForce = (ball.x-x) yForce = (ball.y-y) ball.bodyType = "dynamic" ball:applyLinearImpulse( xForce/factor, yForce/factor, ball.x, ball.y ) ball.isReady = false ball.inAir = true Runtime:removeEventListener("touch",OnScreenTouch) end transition.to( powerShot, { time=175, xScale=0.1, yScale=0.1, onComplete=fling } ) end if powerShot.isVisible == true then local xOffset = ball.x local yOffset = ball.y local distanceBetween = mCeil(mSqrt( ((event.y - yOffset) ^ 2) + ((event.x - xOffset) ^ 2) )) powerShot.xScale = - distanceBetween \* 0.03 powerShot.yScale = - distanceBetween \* 0.03 local angleBetween = mCeil(mAtan2( (event.y - yOffset), (event.x - xOffset) ) \* 180 / mPi) + 90 ball.rotation = angleBetween + 180 arrow.rotation = ball.rotation end else transition.to( powerShot, { time=175, xScale=0.1, yScale=0.1} ) end--fin if principal para limitar aparicion de la orbe de fuerza a una zona end function gameListeners(event) if event == "add" then Runtime:addEventListener("enterFrame", resetBall) elseif event == "remove" then Runtime:removeEventListener("enterFrame", resetBall) end end addGameScreen()