Game Development Reference
In-Depth Information
We can add an outline to the rectangle by specifying the stroke color and the stroke line width, as
follows:
rect_01.strokeWidth = 2
rect_01:setStrokeColor(0,255,0)
strokeWidth sets the width of the stroke line (outline); setting it to 0 is equivalent to specifying no
border or outline for the object. setStrokeColor is similar to setFillColor in terms of the arguments
it takes. These are colors specified in the RGBA format.
We can scale the rectangle using the scale function.
Note You can adjust an object's scale using either the scale() function or the xScale and yScale
properties, although they work somewhat differently. The function scales the object relative to the
current scaling, and the properties assign absolute scale values to the object.
In this exercise, we'll simply use the xScale or yScale method to scale the rectangle. The advantage
is that we can scale an object on one axis when required with the scale property, whereas with the
scale() function, we need to specify the scales for both the x- and y-axis.
rect_01.xScale = 0.5
Rotating the object is equally simple—we can simply use the rotation property or the rotate()
function. Similar to the scaling function and method, rotate and rotation also work with relative or
absolute rotation. If we were to call the rotate() function on the object three times with a value of
30, that would rotate the object to 90 degrees (i.e., 30 degrees × 3), whereas calling the rotation
property with 30 any number of times would rotate it to an absolute value of 30 degrees.
rect_01.rotation = 30
Here's the code all together:
local rect_01 = display.newRect( 50, 50, 200, 200 )
rect_01:setFillColor(255,0,0)
rect_01.strokeWidth = 2
rect_01:setStrokeColor(0,255,0, 128)
rect_01.xScale = 0.5
rect_01.rotation = 30
Figure 8-6 shows what it would look like after applying all of the transformations just described.
 
Search WWH ::




Custom Search