Game Development Reference
In-Depth Information
We can colorize the enemies we spawn by adding the color attribute when we spawn them, as follows:
Clr = Random(1,7)
If Rnd == Objects.Plane Then -- spawn a new plane
Spr = Loadimage("_Plane.Png")
Ypos = Random(2,5) * Spr.Height
Speed = FAST
Clr = Colors.
Elseif Rnd == Objects.Balloon Then -- spawn a balloon
Spr = Loadimage("_Balloon.Png")
Ypos = Random(2,5) * Spr.Height
Ydir = 1
Clr = 8 -- overrride the random color
End
After the If...Then block, we call the colorize method and pass it the color index.
Colorize(Spr, Color)
We could set up the colors with named references instead of using a numeric index, but since we
want to give the objects a random color within a particular range, a numeric index is better. If we
wanted to use named colors instead, we could use the following:
Colors = {
Red = {255, 0, 0},
Blue = {0, 0, 255},
Green = {0, 255, 0},
-- and so on...
}
Displaying Information
We also need to display information to the player about how many survivors were saved, how much
fuel is left, how much distance covered, and so on. To display this information, we use text objects.
Here's the code for Corona SDK:
function newText(theText, xPos, yPos, theFontName, theFontSize)
local xPos, yPos = xPos or 0, yPos or 0
local theFontSize = theFontSize or 14
local theFontName = theFontName or native.systemFont
local _text = display.newText(theText, xPos, yPos, font, 24)
position(_text, xPos, yPos)
_text:setTextColor(0,0,0)
return _text
end
 
Search WWH ::




Custom Search