Yeah I had that in there at some point. Sometimes it becomes easy to forget to bring something back in after you have taken it out. With this added I am still not getting anywhere. It spawns the dart and the dart just sits there. Except for now when I shoot a second dart it moves the first dart up a little bit. I am going to post my code for the whole level maybe there is something else that I am just missing. Sorry for the huge post but at least this way you can see all of the code I have for this level.
[code]
module(…, package.seeall)
–====================================================================–
– SCENE: BALLOON LEVEL
–====================================================================–
–[[
- Version: 0.1
- Made by Ninja Carnival Team @ 2011
******************
–]]
new = function ( params )
– Imports
local ui = require ( “ui” )
– Groups
local localGroup = display.newGroup()
– Variables
local levelTimer = 15
– start physics
local physics = require(“physics”)
physics.start()
physics.setGravity(0,0 )
– Display Objects
local background = display.newImage(“images/Lvl_1/Level_1_BG.png”)
local gun = display.newImage(“images/Lvl_1/goldenGun3.png”)
– Player Stats
local statTextSize = 16
local score = 0
local scoreNum = display.newText(0, 0, 0, native.systemFontBold, statTextSize)
local scoreText = display.newText(“SCORE:”, 0, 0, native.systemFontBold, statTextSize)
local gameTimer = 60
local gameTimerText = display.newText(“60”, 0, 0, native.systemFontBold, statTextSize)
local statsBackground = display.newRect(0,0,_W,scoreText.height+2.5)
– BUTTONS
– FUNCTIONS
–rotate gun
local rotDirection = 1
local function gunRotation(event)
gun.rotation = gun.rotation + rotDirection
if gun.rotation > 90 then
rotDirection = -1
elseif gun.rotation < -80 then
rotDirection = 1
end
end
–function for firing the dart
local function fireDart(event)
local dart = display.newImage(“images/Lvl_1/dart.png”)
dart:setReferencePoint(display.CenterReferencePoint);
dart.x = gun.x
dart.y = gun.y
dart.rotation = gun.rotation
physics.addBody(dart, “dynamic”, {density=1.0, friction=0.5, bounce=0.1})
local speed = 5
local velocity = {}
velocity.x = math.cos( math.rad( dart.rotation - 90 ) )
velocity.y = math.sin( math.rad( dart.rotation - 90 ) )
dart:applyForce(velocity.x, velocity.y, dart.x, dart.y)
end
– PARAMETERS
– INITIALIZE
local initVars = function ()
– Inserts
localGroup:insert(background)
localGroup:insert(statsBackground)
localGroup:insert(scoreText)
localGroup:insert(gameTimerText)
– Positions
– score positions
scoreText.x = (scoreText.width * 0.5) + 10
scoreText.y = (scoreText.height * 0.5) + 5
scoreNum:setReferencePoint(display.CenterLeftReferencePoint);
scoreNum.x = scoreText.width + 5
scoreNum.y = scoreText.y
– timer position
gameTimerText.x = _W * 0.5
gameTimerText.y = scoreText.y
– gun position
gun:setReferencePoint(display.centerReferencePoint);
gun.x = display.contentWidth / 2
gun.y = display.contentHeight - 30
– Colors
–background:setFillColor(255,255,255)
statsBackground:setFillColor(50,0,0)
scoreText:setTextColor(255,0,0)
scoreNum:setTextColor(255,0,0)
gameTimerText:setTextColor(255,0,0)
– Listeners
–Runtime:addEventListener(“enterFrame”, update)
Runtime:addEventListener( “enterFrame”, gunRotation);
Runtime:addEventListener(“tap”, fireDart);
end
– Initiate variables
initVars()
– Update
local update = function ( event )
end
local updateTimer = function( event )
gameTimer = gameTimer - 1
gameTimerText.text = gameTimer
scoreNum.text = (scoreNum.text+1) * 5
scoreNum:setReferencePoint(display.CenterLeftReferencePoint);
scoreNum.x = scoreText.width + 5
scoreNum.y = scoreText.y
end
timer.performWithDelay(1000, updateTimer, 60)
– Clear objects
local clear = function ()
end
– MUST return a display.newGroup()
return localGroup
end
[code] [import]uid: 49863 topic_id: 15330 reply_id: 56691[/import]