gameify. Screen

A Screen to draw things to and get events from, the base of every game.

Constructor

new Screen(element, width, height)

Parameters:
NameTypeDescription
elementHTMLElement

The canvas to draw the screen to

widthnumber

The width of the Screen

heightnumber

The height of the Screen

Example
// 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.

camera :gameify.Camera

This screen's default Camera.

context

The Canvas Context

currentScene

The current game scene

element :HTMLElement

The HTML5 Canvas element the Screen is attached to

Type:
  • HTMLElement

height :Number

The height of the Screen

Type:
  • Number

keyboard :gameify.KeyboardEventManager

Keyboard events for the Screen. Used to see what keys are pressed.

mouse :gameify.MouseEventManager

Mouse events for the Screen. Used to what mouse buttons are pressed, and other mouse events (eg scroll)

updateInterval

The game's update interval

width :Number

The width of the Screen

Type:
  • Number

Methods

add(obj)

Add a Sprite to the Screen. This makes it so that sprite.draw(); draws to this screen.

Parameters:
NameTypeDescription
objgameify.Sprite | gameify.Tilemap

The object to add to the screen

clear(coloropt)

Clear the screen

Parameters:
NameTypeAttributesDescription
colorString<optional>

The color to clear to, e.g. #472d3c or rgb(123, 123, 123). Default is transparent

fromJSON(data, ref) → {gameify.Screen}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
gameify.Screen

getAntialiasing() → {Boolean}

Check if antialising is enabled (Note, also checks and corrects if the canvas element has the correct antialiasing setting)

Returns:
  • Whether antialising is enabled or not
Type: 
Boolean

getContext() → {CanvasRenderingContext2D}

Get the screen's HTML5 canvas context

Returns:
  • The canvas context
Type: 
CanvasRenderingContext2D

getScene() → {gameify.Scene}

Returns the game's active scene

Returns:

The active scene

Type: 
gameify.Scene

getSize() → {gameify.Vector2d}

Get the width and height of the screen

Returns:

A vector representing the size of the screen

Type: 
gameify.Vector2d

setAntialiasing(enable)

Turn antialiasing on or off (set to off for pixel art)

Parameters:
NameTypeDescription
enableBoolean

Whether antialiasing should be enabled.

setHeight(height)

Changes the height of the Screen

Parameters:
NameTypeDescription
heightNumber

The new height of the screen

setScene(scene)

Sets the game's scene

Parameters:
NameTypeDescription
scenegameify.Scene

The scene to set the game to.

setSize(width, height)

Changes the size of the Screen

Parameters:
NameTypeDescription
widthNumber

The new width of the screen

heightNumber

The new height of the screen

setSize(size)

Changes the size of the Screen

Parameters:
NameTypeDescription
sizegameify.Vector2d

The new size of the screen

setSmoothImages(enable)

Alias for setAntialiasing

Parameters:
NameTypeDescription
enableBoolean

Whether smoothing should be enabled or not (true/false)

Deprecated
  • Yes
See
  • {gameify.Screen.setAntialiasing}

setWidth(width)

Changes the width of the Screen

Parameters:
NameTypeDescription
widthNumber

The new width of the Screen

startGame()

Starts the game.

stopGame()

Stops (pauses) the game

toJSON(keyopt, ref) → {Object}

Convert the object to JSON

Parameters:
NameTypeAttributesDescription
keystring<optional>

Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
Object