Hey everybody, im having a major problem with director class, the simulator is saying that there is a problem with INSERT on line 182 or the
localGroup:insert(enemyBalloon)
as well as also saying attempt to perform arthematic feild on X line 150 or
local px,py = event.x-proj.x, event.y-proj.y
this is also happening with Y. this is mainly happening when i am in the menu screen, switching to the play screen, then going back to the menu screen which the resolves in what i’m basically talking about. the code below this text is the game file. Can someone please help me!!!. i’m really annoyed about this bug.
module(..., package.seeall) -- Project: sticky balloons -- Description: -- -- Version: 1.0 -- Managed with http://CoronaProjectManager.com -- -- Copyright 2013 Harry Newton. All Rights Reserved. -- new = function () local widget = require "widget-v1" widget.setTheme("theme\_ios") display.setStatusBar(display.HiddenStatusBar) local physics = require "physics" physics.start();physics.setGravity(0,1) physics.setDrawMode("normal") local localGroup = display.newGroup() local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY) local cw, ch = display.contentWidth, display.contentHeight local stage = display.getCurrentStage() --------------------------------------------------------------------- --FOREGROUND OBJECTS -------------------------------------------------------------------- local background = display.newImage("background.jpg") localGroup:insert(background) local ground = display.newImage("floor.png") physics.addBody(ground,"static") ground.y = 480 localGroup:insert(ground) local turret = display.newImageRect("BalloonTurret.png",134,134) turret.x = 160 turret.y = 420 localGroup:insert(turret) ------------------------------------------------------------- ------------------------------------------------------------- local function buttonHit() director:changeScene("menu", "fade") display.remove(proj) display.remove(enemyBalloon) end local back = widget.newButton {style = "backSmall",label = "back", onRelease = buttonHit} localGroup:insert(back) local projFiring = false local proj local physicsData = (require "Balloon").physicsData(1.0) local function newProj() proj = display.newImage("Balloon.png"); proj.x = turret.x ; proj.y = turret.y - 20 physics.addBody( proj, "dynamic",physicsData:get("balloon") ) proj.gravityScale = -7 projFiring = false proj.isBullet = true proj.isBodyActive = false proj.isVisible = false localGroup:insert(proj) end --collision handler local function projCollide( self,event ) if ( event.phase == "began" ) then --get world coordinates of projectile for joint reference self:removeEventListener( "collision", self ) ; self.collision = nil --delay function to resolve collision local function resolveColl( timerRef ) if ( timerRef.source.action == "makeJoint" ) then local weldJoint = physics.newJoint( "weld", self, event.other, self.x, self.y ) end end --check if velocity of projectile is sufficient to "stick" local vx,vy = self:getLinearVelocity() local dirVel = math.sqrt( (vx\*vx)+(vy\*vy) ) if ( dirVel \> 100 ) then --if sufficient, stop velocity and trigger joint creation self:setLinearVelocity( 0,0 ) local t = timer.performWithDelay( 10, resolveColl, 1 ) ; t.action = "makeJoint" else --if not sufficient, "break" projectile and create new local t = timer.performWithDelay( 10, resolveColl, 1 ) ; t.action = "none" end end end local function touchAction(event) if ( event.phase == "began" and projFiring == false ) then projFiring = true proj.isBodyActive = true proj.isVisible = true local px,py = event.x-proj.x, event.y-proj.y proj:applyLinearImpulse( px/8, py/8, proj.x, proj.y ) proj:applyTorque( 50 ) proj.gravityScale = -7 proj.collision = projCollide ; proj:addEventListener( "collision", proj ) end if (projFiring == true) then newProj() end end newProj() stage:addEventListener( "touch", touchAction ) local spawnTmr local spawnTime = 5000 local difficultyLevels = 4 local enemyBalloon = nil local function spawnEnemy() enemyBalloon = display.newImage("Balloon.png") physics.addBody(enemyBalloon,"dynamic", physicsData:get("balloon") ) localGroup:insert(enemyBalloon) if math.random(2) == 1 then enemyBalloon:applyTorque( 50 ) enemyBalloon.x = math.random(-100,-25) else enemyBalloon:applyTorque( -50 ) enemyBalloon.x = math.random(display.contentWidth+25,display.contentWidth +100) end enemyBalloon.x = math.random(display.contentWidth) enemyBalloon.y = -60 end --local spawnTimer = timer.performWithDelay(5000,spawnEnemy, 0 ) local function increaseDifficulty() if spawnTmr ~= nil then timer.cancel(spawnTmr) spawnTmr = nil end spawnTime = spawnTime - 500 -- just to be safe, set this to whatever spawn rate would be the -- fastest, so game never spawns to fast if spawnTime \< 250 then spawnTime = 250 end -- spawn at this rate until this timer is canceled spawnTmr = timer.performWithDelay(spawnTime, spawnEnemy, 0) end -- this timer loops only till spawning at most difficult speed is reached local difficultyTmr = timer.performWithDelay(5000, increaseDifficulty,difficultyLevels ) return localGroup end
cheers,hazza