Libraries.Game.Shapes.Rectangle Documentation
The Rectangle class stores the location of an unrotated rectangle. This is managed as a location on the screen in (x,y) coordinates coupled with a given height and width.
Inherits from: Libraries.Language.Object
Actions Documentation
Area()
This action returns the area of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(0, 0, 200, 100)
number area = rectangle:Area()
end
end
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Contains(number testX, number testY)
This action tests if the given point is contained within the Rectangle. If it is, this action will return true. Otherwise, it will return false.
Parameters
- number testX
- number testY
Return
boolean:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(50, 50, 100, 100)
boolean hasPoint = rectangle:Contains(125, 75)
end
end
Contains(Libraries.Game.Shapes.Rectangle rectangle)
This action tests if the entire given Rectangle is contained within this Rectangle. If it is, this action will return true. Otherwise, it will return false.
Parameters
Return
boolean:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(75, 75, 50, 50)
boolean contains = rectangle1:Contains(rectangle2)
end
end
CopyRectangle(Libraries.Game.Shapes.Rectangle rectangle)
This action sets the coordinates, width, and height of this rectangle to be the same as the given rectangle.
Parameters
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(20, 20, 200, 80)
rectangle2:CopyRectangle(rectangle1)
end
end
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
FitInside(Libraries.Game.Shapes.Rectangle rectangle)
This action scales this Rectangle so it maintains the same aspect ratio and fits inside the given Rectangle.
Parameters
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(0, 0, 200, 100)
rectangle2:SetRectangle(100, 100, 150, 200)
rectangle1:FitInside(rectangle2)
end
end
FitOutside(Libraries.Game.Shapes.Rectangle rectangle)
This action scales this Rectangle so it maintains the same aspect ratio and fits around the given Rectangle.
Parameters
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(0, 0, 200, 100)
rectangle2:SetRectangle(100, 100, 150, 200)
rectangle1:FitOutside(rectangle2)
end
end
GetAspectRatio()
This action will return the aspect ratio of the Rectangle, which is the ratio of the width over the height of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(200, 100)
number ratio = rectangle:GetAspectRatio()
end
end
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetHeight()
This action returns the current height of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetHeight(100)
number height = rectangle:GetHeight()
end
end
GetWidth()
This action returns the current width of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetWidth(100)
number width = rectangle:GetWidth()
end
end
GetX()
This action returns the current x coordinate of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
number x = rectangle:GetX()
end
end
GetY()
This action returns the current y coordinate of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
number y = rectangle:GetY()
end
end
Merge(Libraries.Game.Shapes.Rectangle rectangle)
This action will make this Rectangle expand to contain the given Rectangle.
Parameters
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(100, 100, 100, 100)
rectangle1:Merge(rectangle2)
end
end
Merge(number pointX, number pointY)
This action will make this Rectangle expand to contain the given point.
Parameters
- number pointX
- number pointY
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(50, 50, 100, 100)
rectangle:Merge(75, 250)
end
end
Overlaps(Libraries.Game.Shapes.Rectangle rectangle)
This action tests if the given Rectangle overlaps with this Rectangle. If it is, this action will return true. Otherwise, it will return false.
Parameters
Return
boolean:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle1
Rectangle rectangle2
action Main
StartGame()
end
action CreateGame
rectangle1:SetRectangle(50, 50, 100, 100)
rectangle2:SetRectangle(100, 100, 100, 100)
boolean overlap = rectangle1:Overlaps(rectangle2)
end
end
Perimeter()
This action returns the perimeter of the Rectangle.
Return
number:
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(0, 0, 200, 100)
number perimeter = rectangle:Perimeter()
end
end
SetCenter(number centerX, number centerY)
This action will set the x, y coordinates of the Rectangle so that the center of the Rectangle is at the given x, y coordinates.
Parameters
- number centerX
- number centerY
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(200, 100)
rectangle:SetCenter(200, 150)
end
end
SetHeight(number newHeight)
This action sets the current height of the Rectangle.
Parameters
- number newHeight
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetHeight(100)
end
end
SetPosition(number newX, number newY)
This action sets the x and y coordinates of the Rectangle.
Parameters
- number newX
- number newY
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetPosition(80, 100)
end
end
SetRectangle(number newX, number newY, number newWidth, number newHeight)
This action sets the x and y coordinates of the Rectangle, along with the width and height.
Parameters
- number newX
- number newY
- number newWidth
- number newHeight
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetRectangle(20, 20, 200, 80)
end
end
SetSize(number newWidth, number newHeight)
This action sets the width and height of the Rectangle.
Parameters
- number newWidth
- number newHeight
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSize(40, 70)
end
end
SetSquare(number scale)
This action sets the width and height of the rectangle to be the given value, making it into a square.
Parameters
- number scale
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetSquare(60)
end
end
SetWidth(number newWidth)
This action sets the current width of the Rectangle.
Parameters
- number newWidth
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetWidth(100)
end
end
SetX(number newX)
This action sets the current x coordinate of the Rectangle.
Parameters
- number newX
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetX(40)
end
end
SetY(number newY)
This action sets the current y coordinate of the Rectangle.
Parameters
- number newY
Example
use Libraries.Game.Shapes.Rectangle
use Libraries.Game.Game
class Main is Game
Rectangle rectangle
action Main
StartGame()
end
action CreateGame
rectangle:SetY(75)
end
end
On this page
Variables TableAction Documentation- Area()
- Compare(Libraries.Language.Object object)
- Contains(number testX, number testY)
- Contains(Libraries.Game.Shapes.Rectangle rectangle)
- CopyRectangle(Libraries.Game.Shapes.Rectangle rectangle)
- Equals(Libraries.Language.Object object)
- FitInside(Libraries.Game.Shapes.Rectangle rectangle)
- FitOutside(Libraries.Game.Shapes.Rectangle rectangle)
- GetAspectRatio()
- GetHashCode()
- GetHeight()
- GetWidth()
- GetX()
- GetY()
- Merge(Libraries.Game.Shapes.Rectangle rectangle)
- Merge(number pointX, number pointY)
- Overlaps(Libraries.Game.Shapes.Rectangle rectangle)
- Perimeter()
- SetCenter(number centerX, number centerY)
- SetHeight(number newHeight)
- SetPosition(number newX, number newY)
- SetRectangle(number newX, number newY, number newWidth, number newHeight)
- SetSize(number newWidth, number newHeight)
- SetSquare(number scale)
- SetWidth(number newWidth)
- SetX(number newX)
- SetY(number newY)