Constructor
new Screen(element, width, height)
| Name | Type | Description |
|---|---|---|
element | HTMLElement | The canvas to draw the screen to |
width | number | The width of the Screen |
height | number | The height of the Screen |
- Source
// Get the canvas element
let canvas = document.querySelector("#my-canvas");
// Create a Screen that is 600 by 400
let myScreen = new gameify.Screen(canvas, 600, 400);Members
audio :gameify.audio.AudioManager
This screen's default AudioManager.
- Source
camera :gameify.Camera
This screen's default Camera.
- Source
context
The Canvas Context
- Source
currentScene
The current game scene
- Source
element :HTMLElement
The HTML5 Canvas element the Screen is attached to
- HTMLElement
- Source
height :Number
The height of the Screen
- Number
- Source
keyboard :gameify.KeyboardEventManager
Keyboard events for the Screen. Used to see what keys are pressed.
- Source
mouse :gameify.MouseEventManager
Mouse events for the Screen. Used to what mouse buttons are pressed, and other mouse events (eg scroll)
- Source
updateInterval
The game's update interval
- Source
width :Number
The width of the Screen
- Number
- Source
Methods
add(obj)
Add a Sprite to the Screen. This makes it so that sprite.draw(); draws to this screen.
| Name | Type | Description |
|---|---|---|
obj | gameify. | The object to add to the screen |
- Source
clear(coloropt)
Clear the screen
| Name | Type | Attributes | Description |
|---|---|---|---|
color | String | <optional> | The color to clear to, e.g. #472d3c or rgb(123, 123, 123). Default is transparent |
- Source
fromJSON(data, ref) → {gameify.Screen}
Creates a object from JSON data
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Source
- Type:
- gameify.
Screen
getAntialiasing() → {Boolean}
Check if antialising is enabled (Note, also checks and corrects if the canvas element has the correct antialiasing setting)
- Source
- Whether antialising is enabled or not
- Type:
- Boolean
getContext() → {CanvasRenderingContext2D}
Get the screen's HTML5 canvas context
- Source
- The canvas context
- Type:
- CanvasRenderingContext2D
getScene() → {gameify.Scene}
Returns the game's active scene
- Source
The active scene
- Type:
- gameify.
Scene
getSize() → {gameify.Vector2d}
Get the width and height of the screen
- Source
A vector representing the size of the screen
- Type:
- gameify.
Vector2d
setAntialiasing(enable)
Turn antialiasing on or off (set to off for pixel art)
| Name | Type | Description |
|---|---|---|
enable | Boolean | Whether antialiasing should be enabled. |
- Source
setHeight(height)
Changes the height of the Screen
| Name | Type | Description |
|---|---|---|
height | Number | The new height of the screen |
- Source
setScene(scene)
Sets the game's scene
| Name | Type | Description |
|---|---|---|
scene | gameify. | The scene to set the game to. |
- Source
setSize(width, height)
Changes the size of the Screen
| Name | Type | Description |
|---|---|---|
width | Number | The new width of the screen |
height | Number | The new height of the screen |
- Source
setSize(size)
Changes the size of the Screen
| Name | Type | Description |
|---|---|---|
size | gameify. | The new size of the screen |
- Source
setSmoothImages(enable)
Alias for setAntialiasing
| Name | Type | Description |
|---|---|---|
enable | Boolean | Whether smoothing should be enabled or not (true/false) |
- Deprecated
- Yes
- Source
- See
- {gameify.Screen.setAntialiasing}
setWidth(width)
Changes the width of the Screen
| Name | Type | Description |
|---|---|---|
width | Number | The new width of the Screen |
- Source
startGame()
Starts the game.
- Source
stopGame()
Stops (pauses) the game
- Source
toJSON(keyopt, ref) → {Object}
Convert the object to JSON
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Source
- Type:
- Object