If a function receives a rectangle as an argument it could be several things:
- You can specify the parameters
x, y, width, heightdirectly as arguments of the function. E.g.sprite:crop(0, 16, 64, 32) - You can specify an object with
x,y,width, andheightproperties. E.g.sprite:crop{ x=0, y=16, width=64, height=32 } - You can specify an array with 4 elements:
E.g.
sprite:crop{ 0, 16, 64, 32 } - You can specify a
Rectangleinstance: E.g.sprite:crop(Rectangle(0, 16, 64, 32))
Rectangle()
Rectangle(otherRectangle)
Rectangle(x, y, width, height)
Rectangle{x=number, y=number, width=number, height=number}
Rectangle{number, number, number, number}local x = rectangle.x
rectangle.x = newXGets or sets the x-coordinate of the rectangle. 0 means at the left side of the screen/sprite.
local y = rectangle.y
rectangle.y = newYGets or sets the y-coordinate of the rectangle. 0 means at the top side of the screen/sprite.
local width = rectangle.width
rectangle.width = newWidthGets or sets the width of the rectangle. If it's 0, the rectangle is empty (so the coordinate doesn't matter).
local height = rectangle.height
rectangle.height = newHeightGets or sets the height of the rectangle. If it's 0, the rectangle is empty (so the coordinate doesn't matter).
local point = rectangle.origin
rectangle.origin = newPointGets or sets the origin of the rectangle with a Point object, just like changing Rectangle.x and Rectangle.y at the same time.
local size = rectangle.size
rectangle.size = newSizeGets or sets the size of the rectangle with a Size object, just like changing Rectangle.width and Rectangle.height at the same time.
local booleanResult = rectangle.isEmptyReturns true if the rectangle is empty i.e. width and/or height are 0.
local booleanResult = rectangle:contains(otherRectangle)Returns true if otherRectangle is inside rectangle.
Example:
local bounds = Rectangle{ x=0, y=0, width=32, height=32 }
local rectInside = Rectangle{ x=4, y=4, width=8, height=8 }
if bounds:contains(rectInside) then ... endlocal booleanResult = rectangle:intersects(otherRectangle)Returns true if rectangle intersects in some way otherRectangle.
local newRectangle = rectangle:intersect(otherRectangle)Returns the new rectangle newRectangle which is the intersection of
rectangle and otherRectangle. If both rectangles don't intersect each other, the result will be an empty rectangle
local newRectangle = rectangle:union(otherRectangle)Returns the new rectangle newRectangle which will be a rectangle big
enough to contains both given rectangles rectangle and
otherRectangle.