Game Development Reference
In-Depth Information
We use another generic function, destroyObject , to remove the object from the screen. It's defined
differently depending on the framework.
Here's the Corona SDK version:
function destroyObject(theObj)
if theObj == nil then return end
display.remove(theObj)
end
And here's the Gideros Studio version:
function destroyObject(theObj)
if theObj == nil then return end
if theObj.removeFromParent then theObj:removeFromParent() end
end
Spawning Enemies
We now have a helicopter that can move on the screen and shoot bullets that disappear once they
reach the edge of the screen. Next, we'll randomly spawn some items that will be used as enemies.
We'll spawn items of the following types:
Plane
Balloon
Flower
Grass
Lamppost
House
Tall house
Cloud 1
Cloud 2
Cloud 3
Angry cloud
The images for these items were shown previously in Figures 15-1 and 15-2 .
Instead of using absolute numbers, we create a table list to refer to these items using the enumerate
function, as follows:
function enumerate(theTextArray)
local returnVal = {}
for i,j in pairs(theTextArray) do
returnVal[j] = i
end
 
Search WWH ::




Custom Search