Hello i m new in corona development
my problem is in simulator the code work’s fine but in device the code won’t work
i has a space ship controlled by accelerometer and need fire some bullets forever , in simulator the code works fine , but in device it dont shoot any bullets , anyone know what i m doing wrong ?
I tested it on Sony Xperia S and Samgsung Galaxy S3
code :
--make this file visible to all files in project module(..., package.seeall) new = function ( params ) local localGroup = display.newGroup() local weaponGroup = display.newGroup() --add physics to map local physics = require ("physics") physics.start() physics.setGravity(0,0) --Backgroud Settings local backGround backGround = display.newImage( "BackGround.png" ) localGroup:insert( backGround ) --add the ship to the map local ship local centerX local centerY local bullets = display.newGroup() ship = display.newImage("Ship.png") centerX =(display.contentWidth / 2) centerY =(display.contentHeight / 1.5) ship.x = centerX ship.y = centerY physics.addBody(ship,"dynamic", { density=0.1, friction=0.3, bounce=0.2} ) -- add the object to local group, so Director class can manage it localGroup:insert(ship) ----------------------------------------------- --\*\*\* move the ship\*\*\* ----------------------------------------------- local function moveShip(xGravity,yGravity) local calculedX local calculedY local hasXValue local hasYValue calculedX = (centerX + (centerX \* (xGravity \* 2))) calculedY = (centerY + (centerY \* (yGravity \* 2) \* -1)) if calculedX \>= display.contentWidth - ship.width then ship.x = display.contentWidth-ship.width hasXValue = true end if calculedX \<= 0 + ship.width then ship.x = 0 + ship.width hasXValue = true end if calculedY \>= display.contentHeight - ship.height then ship.y = display.contentHeight - ship.height hasYValue = true end if calculedY \<= 0 + ship.height then ship.Y = 0 + ship.height hasYValue = true end if hasXValue ~= true then ship.x = centerX + (centerX \* (xGravity \* 2)) end if hasYValue ~= true then ship.y = centerY + (centerY \* (yGravity \* 2) \* -1) end end ----------------------------------------------- --\*\*\* Start the ship firing automatically \*\*\* ----------------------------------------------- local function startProjectiles() local fireTimer local function fireNow() if gameIsActive == false then timer.cancel(fireTimer); fireTimer = nil else local bullet = display.newImage( "bullet.png") bullet.x = ship.x bullet.y = ship.y - ship.height bullet.name = 'bullet' physics.addBody( bullet, { isSensor = true } ) weaponGroup:insert( bullet ) end end fireTimer = timer.performWithDelay(850, fireNow, 0) end startProjectiles() local function onAccelerate( event ) moveShip(event.xGravity,event.yGravity) end function update(e) --Move our bullets up each frame! for i = weaponGroup.numChildren,1,-1 do local weapon = weaponGroup[i] if weapon ~= nil and weapon.y ~= nil then weapon:translate(0, -18); end end end Runtime:addEventListener('enterFrame', update) Runtime:addEventListener ("accelerometer", onAccelerate); return localGroup end