gs.Graphics Class
This class manages the graphics system. It needs to be initializes before any graphical operations can be executed. It initializes the necessary graphic contexts allocates necessary resources.
It manages all graphic objects and renders them automatically on screen ordered by the z-index of each object.
Constructor
gs.Graphics
()
final
static
Item Index
Methods
- addGraphicObject static
- clear static
- dispose static
- enterFullscreen static
- freeze static
- initialize static
- isFullscreen static
- leaveFullscreen static
- removeGraphicObject static
- setCursorBitmap static
- snapshot static
- snapshotAsData static
- transition static
- update static
Properties
- @onFocusLost static
- @onFocusReceive static
- canvas static
- context static
- frameRate static
- height static
- keepRatio static
- renderer static
- viewport static
- width static
Methods
addGraphicObject
-
object
Adds a graphic object to the graphic system. The graphic object will be automatically rendered and sorted by z-index.
Parameters:
-
object
gs.GraphicObject- The graphic object to add.
clear
()
static
Clears the screen.
dispose
()
static
Disposes the graphic system and frees resources/memory. Should be called before the game quits. After that, no graphic objects should be created and no other graphical operations should be executed.
enterFullscreen
()
static
Enters fullscreen mode.
freeze
()
static
Freezes the current screen. Prepares for transition.
initialize
-
width
-
height
-
parent
-
keepRatio
Initializes the graphics system. Must be called before any graphic object are created or any other graphic operations are executed.
Parameters:
-
width
Number- The width of the game's resolution.
-
height
Number- The height of the game's resolution.
-
parent
HTMLElement- The HTML element to which the canvas should be added.
-
keepRatio
Boolean- Indicates if the canvas should keep the ratio of the resolution on scaling.
isFullscreen
()
Boolean
static
Indiciates if the game runs currently in fullscreen mode.
Returns:
Returns true if the game runs in fullscreen mode. Otherwise false.
leaveFullscreen
()
static
Leaves fullscreen mode.
removeGraphicObject
-
object
Removes a graphic object from the graphic system. The graphic object is no longer rendered then.
Parameters:
-
object
gs.GraphicObject- The graphic object to remove.
setCursorBitmap
-
bitmap
-
hotspotX
-
hotspotY
Sets the current pointer/cursor image. The cursor's hotspot/click-point starts at the top-left corner of the image like 0, 0 means the top-left corner as hotspot/click-point.
Parameters:
-
bitmap
gs.Bitmap- The bitmap used to display the current pointer/cursor.
-
hotspotX
Number- The x-coordinate of the cursor's hotspot/click-point.
-
hotspotY
Number- The y-coordinate of the cursor's hotspot/click-point.
snapshot
()
gs.Bitmap
static
Creates a snapshot from the current screen.
Returns:
A snapshot from the current screen.
snapshotAsData
()
Uint8Array
static
Creates a snapshot from the current screen.
Returns:
A snapshot from the current screen a uint8 pixel data array.
transition
-
duration
-
[transitionBitmap=null]
-
[vague=null]
Executes a transition from the frozen state to the current state. If no frozen state exists, no transition is executed. To freeze the current state use gs.Graphics.freeze method.
Parameters:
-
duration
Number- The transition duration in frames.
-
[transitionBitmap=null]
gs.Bitmap optional- The mask-bitmap used for the transition. If null a simple transition using blending is executed.
-
[vague=null]
Number optional- The vague of the masking if a mask-bitmap is specified.
update
()
static
Updates the screen. Renders all graphic objects. Should be called once per frame.
Properties
@onFocusLost
Function
static
A callback function called whenever the game screen loses input focus.
@onFocusReceive
Function
static
A callback function called whenever the game screen receives input focus.
canvas
Object
static
The canvas/screen object. On most platforms that is an HTMLCanvasElement but there is no guarantee. Accessing the canvas directly is not recommended, it should only be done if really necessary.
context
Object
static
The graphic context. This in regular is an OpenGL context but it depends on the platform. The graphic context should only be accessed if really necessary.
frameRate
Number
static
The target frame-rate. This is property doesn't reflect the actual current frame-rate of the running game.
Default: 60
height
Number
static
The width of the game's resolution.
keepRatio
Boolean
static
Indicates if the canvas/screen should keep the ratio of the resolution on scaling.
viewport
gs.Viewport
static
The top-level viewport. Adding/Removing objects from that viewport is equivalent to gs.Graphics.addGraphicObject/gs.Graphics.removeGraphicObject methods.
width
Number
static
The width of the game's resolution.