CPoint:new
The new method constructs a new instance of a CPoint object. The CPoint class includes 2 properties that describe the x and y values of a point. You can treat this object as a classic point or you can use it simply to hold 2 numbers. Using this class method is equivalent to using the global function NewPoint.
P = CPoint:new() P = CPoint:new( CPointOld ) P = CPoint:new( x, y ) P = CPoint:new( x ) P = CPoint:new( CRect ) P = CPoint:new( array ) where The first form with no arguments creates a default CPoint object with properties initialized to the default values 0,0. If a CPoint is passed, a new CPoint object is created initialized to the properties of the CPointOld argument. x, y are numbers, If two numbers are passed, the new CPoint is inialized accordingly. If one number is passed, both x and y properties are initialized to the same value. If a CRect is passed, the CPoiont is initialized to the width and height of the rectangle. This is useful for using the CPoint as a size measurement. If a lua array is passed, the new CPoint is initialized to the first 2 values in a Lua array, in particular, the values of array[1] and array[2]. A new CPoint object, P, is returned. |
The following script illustrates using various forms of new. All produce the same result:
|
-- create CPoint A and set values |
|
-- result: 100 300 |
|
|
|
-- copy CPoint A to a new CPoint B |
|
-- result: 100 300 |
|
|
|
-- create a default CPoint C |
|
|
|
-- result: 100 300 |