Hello Community, I’m trying to my airplane drops boxes between a specific range. Here’s my code:
[code]
local airplane
local crate
local airon = false
local c
local function spawnair ()
airplane = display.newImage ( “Airplane.png” )
airplane:setReferencePoint ( display.TopCenterReferencePoint )
airplane.x = -50
airplane.y = 50
airon = true
c = mRandom ( 150, 460 )
end
timer.performWithDelay ( 4000, spawnair, 0 )
local function cra ()
if ( gameplay == true and airon == true ) then
if ( airplane.x == c ) then
crate = display.newImage ( “Crate.png” )
crate:setReferencePoint ( display.TopCenterReferencePoint )
crate.x = airplane.x
crate.y = 70
physics.addBody ( crate )
end
end
end
Runtime:addEventListener ( “enterFrame”, cra )
local function air ()
if ( gameplay == true and airon == true ) then
airplane.x = airplane.x + 10
end
end
Runtime:addEventListener ( “enterFrame”, air )
local function remair ()
if ( gameplay == true and airon == true and airplane.x == 530 ) then
airplane:removeSelf ()
airplane = nil
airon = false
end
end
[/code] [import]uid: 81091 topic_id: 21295 reply_id: 321295[/import]
