gs.Viewport Class
A viewport manages a list of graphic objects and automatically renders them ordered by z-index. All graphic object outside of the viewport's bounds are clipped.
Constructor
gs.Viewport
-
x|rect
-
[y=null]
-
[width=null]
-
[height=null]
Parameters:
-
x|rect
Number | gs.Rect- The x-coordinate of the viewport's rect OR the whole viewport-rect.
-
[y=null]
Number optional- The y-coordinate of the viewport's rect.
-
[width=null]
Number optional- The width of the viewport's rect.
-
[height=null]
Number optional- The height of the viewport's rect.
Item Index
Methods
addGraphicObject
-
object
Adds a graphic object to the viewport.
Parameters:
-
object
gs.GraphicObject- The graphic object to add.
dispose
()
Disposes the viewport. All graphic objects which are part of the viewport are disposed too.
draw
()
Draws the viewport with all its graphic objects.
initialize
()
protected
Initializes the graphic object.
removeGraphicObject
-
object
Removes a graphic object from the viewport.
Parameters:
-
object
gs.GraphicObject- The graphic object to remove.
update
()
Updates the viewport.
Properties
anchor
gs.Point
The anchor point. For example: An anchor-point with 0,0 rotates the object around its top-left corner but with an 0.5, 0.5 anchor-point the object rotates around its center. An anchor-point of 1,1 rotates the object around its lower-right corner. It has not effect on the object's positioning. For positioning, take a look at positionAnchor property.
angle
Number
The rotation-angle in degrees. Rotates all objects assigned to this viewport around the viewport's anchor-point.
disposed
Boolean
Indicates if the object is disposed. A disposed object is not rendered.
effects
gs.EffectCollection
The effect settings for different kind of visual effect like wobble, etc.
id
Number
The unique identifier of the graphic object.
index
Number
The current index in the global rendering list. This property is read-only and automatically calculated at runtime depending on z-property.
onIndexChange
Function
Fired if the graphic object's current index in the global rendering list was changed.
Default: null
ox
Number
The x-coordinate of the origin.
oy
Number
The y-coordinate of the origin.
positionAnchor
gs.Point
The position anchor point. For example: An anchor-point with 0,0 places the object with its top-left corner at its position but with an 0.5, 0.5 anchor-point the object will be placed with its center. An anchor-point of 1,1 will place the object with its lower-right corner. It has not effect on the object's rotation/zoom anchor. For that, take a look at anchor property.
rect
gs.Rect
A rectangle defining the area of the viewport. All graphic objects outside of the rect are clipped.
transform
Mat2d
The transformation matrix of the graphic object.
visible
Boolean
Indicates if the object is rendered.
z
Number
The z-index controls rendering-order/image-overlapping. An object with a smaller z-index is rendered before an object with a larger index. For example: To make sure a graphic object is always on top of the screen, it should have the largest z-index of all graphic objects.
zoomX
Number
The zoom on x-axis.
zoomY
Number
The zoom on y-axis.