Hi again thanks for the people that help me on the last post here https://developer.anscamobile.com/forum/2012/03/24/help-adding-xcode-432
Anyways back to what I got to say. What I’m trying to do is have a plane shoot at the same time while the person moves it. The problem is when I try to move the plane and try to shoot at the same time the bullets does not come out. Or the plane just starts to go offscreen, or center screen I don’t know why
Here is the code
[code] system.activate( “multitouch” )
local ui = require(“ui”)
limits = 0
local function powertwin2 ()
extrabull = loadFile (“extra.txt”)
if extrabull == “empty” then
extrabull = 2
saveFile(“extra.txt”, extrabull)
end
end
powertwin2()
local function bulletsgood2()
if tonumber(extrabull) == 2 then
limits = 50
limitsbullet = display.newText(“Ammo:50”, 30, 30,“Arial”, 18)
localGroup:insert(limitsbullet)
end
end
timer.performWithDelay(100, bulletsgood2, 1)
------------Right Below Here is were I move the Plane by drag Up and Down------------
local canBeDragged = true
local function startDrag( event )
local t = event.target
local phase = event.phase
if canBeDragged == true then
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
–t.x0 = event.x - t.x
t.y0 = event.y - t.y
– Make body type temporarily “kinematic” (to avoid gravitional forces)
event.target.bodyType = “static”
elseif t.isFocus then
if “moved” == phase then
–t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
– Switch body type back to “dynamic”, unless we’ve marked this sprite as a platform
if ( not event.target.isPlatform ) then
event.target.bodyType = “static”
end
end
end
end
– Stop further propagation of touch event!
return true
end
local box = display.newRect(-40, 100, 30, 30)
localGroup:insert(box)
–local test = require (“game2”)
–local data = test.getSpriteSheetData()
–local game = sprite.newSpriteSheetFromData( “hells2.png”, data )
local sheet1 = sprite.newSpriteSheet( “work4.png”, 92, 63 )
– Defining the sprite we’re going to be using
local heroset = sprite.newSpriteSet (sheet1, 1, 7)
sprite.add (heroset, “hero”, 1, 7, 200, 0)
local heli = sprite.newSprite (heroset)
heli.x = 50
heli.y = 100
heli.hit = “heli”
physics.addBody(heli ,“static”,{radius = 20})
localGroup:insert(heli)
heli:prepare(“hero”)
heli:play()
heli:addEventListener( “touch”, startDrag )
------------Right Above Here is were I move the Plane by drag Up and Down------------
------------Right Below Here is were I try to shoot while I’m dragging the Plane Up and Down------------
local function shoot (event)
if event.phase == “began” then
if limits == 0 then
great = true
end
if great == false then
if tonumber(twinb) == 1 then
local bullet = display.newImageRect(“bullet.png”, 10, 10)
bullet.x = heli.x + 40
bullet.y = heli.y
bullet.hit = “bullet”
bullet.isFixedRotation = true
transition.to (bullet, {time = 2000, x=550})
physics.addBody (bullet, {bounce=0.6})
limits = limits - 1
limitsbullet.text = “Ammo:” …limits
shooting = audio.play( shots)
localGroup:insert(bullet)
bullet:addEventListener(“collision”, bullet)
function bullet:collision (event)
if event.other.hit ~= “heli” then
bullet:removeSelf()
end
end
elseif tonumber(twinb) == 2 then
local twin = display.newImageRect(“bullet.png”, 10, 10)
twin.x = heli.x + 40
twin.y = heli.y
twin.hit = “twin”
twin.isFixedRotation = true
transition.to (twin, {time = 2000, x=550})
physics.addBody (twin, {bounce=0.6})
localGroup:insert(twin)
local twin2 = display.newImageRect(“bullet.png”, 10, 10)
twin2.x = heli.x + 40
twin2.y = heli.y + 15
twin2.hit = “twin”
twin2.isFixedRotation = true
transition.to (twin2, {time = 2000, x=550})
physics.addBody (twin2, {bounce=0.6})
localGroup:insert(twin2)
twin:addEventListener(“collision”, twin)
function twin:collision (event)
if event.other.hit ~= “heli” then
twin:removeSelf()
twin2:removeSelf()
end
end
elseif tonumber(twinb) == 3 then
local bullet3 = display.newImageRect(“rocket.png”, 25, 25)
bullet3.x = heli.x + 45
bullet3.y = heli.y
bullet3.hit = “bullet3”
bullet3.isFixedRotation = true
transition.to (bullet3, {time = 2000, x=550})
physics.addBody (bullet3, {bounce=0.6, isSensor = true})
localGroup:insert(bullet3)
limits = limits - 1
limitsbullet.text = “Ammo:” …limits
shooting = audio.play( shots)
bullet3:addEventListener(“collision”, bullet3)
function bullet3:collision (event)
if event.other.hit ~= “heli” then
bullet3:removeSelf()
end
end
end
end
end
end
ButtonA = ui.newButton{
default = “buttonoverA.png”,
over = “buttonA.png”,
x = 360,
y = 280,
onEvent = shoot,
}
localGroup:insert(ButtonA)
[/code]
Now How does it need to be fix? I try to find it myself and no use [import]uid: 17058 topic_id: 23846 reply_id: 323846[/import]
[import]uid: 21331 topic_id: 23846 reply_id: 96099[/import]