Skip to main content

Class: Game

Implements

Constructors

new Game()

new Game(options): Game

The base class for all games. New games should extend this class.

Parameters

options: GameOptions

GameOptions

Returns

Game

Source

Game.ts:136

Properties

_canvasKit?

optional _canvasKit: CanvasKit

Source

Game.ts:95


_dataStores?

private optional _dataStores: IDataStore[]

Source

Game.ts:117


_eventMaterializer?

private optional _eventMaterializer: EventMaterializer

Source

Game.ts:127


_fontManager?

private optional _fontManager: FontManager

Source

Game.ts:121


_imageManager?

private optional _imageManager: ImageManager

Source

Game.ts:122


_soundManager?

private optional _soundManager: SoundManager

Source

Game.ts:123


additionalParameters?

optional additionalParameters: unknown

Additional activity parameters that were set.

Implementation of

Activity.additionalParameters

Source

Game.ts:119


animationFramesRequested

private animationFramesRequested: number = 0

Source

Game.ts:852


automaticTrialSchema

private readonly automaticTrialSchema: TrialSchema

The m2c2kit engine will automatically include these schema and their values in the trial data.

Source

Game.ts:1936


beginIso8601Timestamp

beginIso8601Timestamp: string = ""

The value of new Date().toISOString() immediately before the activity begins

Implementation of

Activity.beginIso8601Timestamp

Source

Game.ts:107


beginTimestamp

beginTimestamp: number = NaN

The value of performance.now() immediately before the activity begins

Implementation of

Activity.beginTimestamp

Source

Game.ts:106


bodyBackgroundColor?

private optional bodyBackgroundColor: RgbaColor

Source

Game.ts:842


canvasCssHeight

canvasCssHeight: number = 0

Source

Game.ts:858


canvasCssWidth

canvasCssWidth: number = 0

Source

Game.ts:857


canvasKitWasmVersion

readonly canvasKitWasmVersion: "__CANVASKITWASM_VERSION__" = "__CANVASKITWASM_VERSION__"

Source

Game.ts:104


currentScene?

optional currentScene: Scene

Source

Game.ts:844


currentSceneSnapshot?

private optional currentSceneSnapshot: Image

Source

Game.ts:866


data

data: GameData

Source

Game.ts:834


drawnFrames

private drawnFrames: number = 0

Source

Game.ts:848


entryScene?

optional entryScene: string | Scene

The scene, or its name as a string, to be presented when the game is started. If this is undefined, the game will start with the first scene that has been added

Source

Game.ts:833


eventListeners

private eventListeners: ActivityEventListener<ActivityEvent>[]

Source

Game.ts:108


eventStore

eventStore: EventStore

Source

Game.ts:125


fpsMetricReportThreshold

private fpsMetricReportThreshold: number

Source

Game.ts:110


fpsRate

private fpsRate: number = 0

Source

Game.ts:851


fpsTextFont?

private optional fpsTextFont: Font

Source

Game.ts:846


fpsTextPaint?

private optional fpsTextPaint: Paint

Source

Game.ts:847


freeNodesScene

freeNodesScene: Scene

Source

Game.ts:861


gameMetrics

private gameMetrics: GameMetric[]

Source

Game.ts:109


gameStopRequested

private gameStopRequested: boolean = false

Source

Game.ts:854


htmlCanvas?

private optional htmlCanvas: HTMLCanvasElement

Source

Game.ts:839


i18n?

optional i18n: I18n

Source

Game.ts:114


id

id: string

Short identifier of this activity

Implementation of

Activity.id

Source

Game.ts:99


incomingSceneTransitions

private incomingSceneTransitions: SceneTransition[]

Source

Game.ts:865


lastFpsUpdate

private lastFpsUpdate: number = 0

Source

Game.ts:849


limitFps

private limitFps: boolean = false

Source

Game.ts:853


manifest?

optional manifest: Manifest

Source

Game.ts:124


materializedNodes

materializedNodes: M2Node[]

Nodes created during event replay

Source

Game.ts:129


maximumRecordedActivityMetrics

private maximumRecordedActivityMetrics: number

Source

Game.ts:111


moduleMetadata

moduleMetadata: ModuleMetadata

Source

Game.ts:103


name

name: string

Human-friendly name of this activity

Implementation of

Activity.name

Source

Game.ts:98


nextFpsUpdate

private nextFpsUpdate: number = 0

Source

Game.ts:850


nodeFactory

private nodeFactory: M2NodeFactory

Source

Game.ts:126


options

options: GameOptions

Source

Game.ts:105


pendingScreenshot?

private optional pendingScreenshot: PendingScreenshot

Source

Game.ts:867


plugins

private plugins: Plugin[] = []

Source

Game.ts:118


priorUpdateTime?

private optional priorUpdateTime: number

Source

Game.ts:845


publishUuid

publishUuid: string = ""

Persistent unique identifier (UUID) of the activity. Required for games. Optional or empty string if a survey.

Implementation of

Activity.publishUuid

Source

Game.ts:100


replayEventsButtonEnabled

private replayEventsButtonEnabled: boolean = true

Source

Game.ts:1290


scenes

scenes: Scene[]

Source

Game.ts:860


sessionUuid

sessionUuid: string = ""

The activity's parent session unique identifier. This is newly generated each session.

Implementation of

Activity.sessionUuid

Source

Game.ts:96


showFps?

private optional showFps: boolean

Source

Game.ts:841


snapshots

snapshots: Image[]

Source

Game.ts:2512


staticTrialSchema

staticTrialSchema: object

Index signature

[key: string]: JsonSchemaDataTypeScriptTypes

Source

Game.ts:120


stepCount

private stepCount: number = 0

Source

Game.ts:112


steppingNow

private steppingNow: number = 0

Source

Game.ts:113


studyId?

optional studyId: string

The ID of the study (protocol, experiment, or other aggregate) that contains the repeated administrations of this activity. The ID should be short, url-friendly, human-readable text (no spaces, special characters, or slashes), e.g., nyc-aging-cohort.

Implementation of

Activity.studyId

Source

Game.ts:101


studyUuid?

optional studyUuid: string

Unique identifier (UUID) of the study (protocol, experiment, or other aggregate) that contains the administration of this activity.

Implementation of

Activity.studyUuid

Source

Game.ts:102


surface?

optional surface: Surface

Source

Game.ts:840


trialIndex

trialIndex: number = 0

The 0-based index of the current trial

Source

Game.ts:838


type

readonly type: Game = ActivityType.Game

The type of activity: Game or Survey

Implementation of

Activity.type

Source

Game.ts:94


uuid

uuid: string

The activity's unique identifier. This is newly generated each session. The UUID for an activity will vary across sessions.

Implementation of

Activity.uuid

Source

Game.ts:97


warmupFinished

private warmupFinished: boolean = false

Source

Game.ts:116


warmupFunctionQueue

private warmupFunctionQueue: WarmupFunctionQueue[]

Source

Game.ts:115


webGlRendererInfo

private webGlRendererInfo: string = ""

Source

Game.ts:855

Accessors

canvasKit

get canvasKit(): CanvasKit

set canvasKit(canvasKit): void

Parameters

canvasKit: CanvasKit

Returns

CanvasKit

Source

Game.ts:821


dataStores

get dataStores(): IDataStore[]

Optional stores to use for saving data. The implementation of the store is not provided by the @m2c2kit/core library.

set dataStores(dataStores): void

Optional stores to use for saving data. The implementation of the store is not provided by the @m2c2kit/core library.

Parameters

dataStores: IDataStore[]

Returns

IDataStore[]

Source

Game.ts:674


entities

get entities(): M2Node[]

Deprecated

use Game.nodes instead

Returns

M2Node[]

Source

Game.ts:3113


eventMaterializer

get eventMaterializer(): EventMaterializer

set eventMaterializer(eventMaterializer): void

Parameters

eventMaterializer: EventMaterializer

Returns

EventMaterializer

Source

Game.ts:503


fontManager

get fontManager(): FontManager

set fontManager(fontManager): void

Parameters

fontManager: FontManager

Returns

FontManager

Source

Game.ts:470


freeEntities

get freeEntities(): M2Node[]

Deprecated

Use Game.freeEntities instead

Returns

M2Node[]

Source

Game.ts:953


freeNodes

get freeNodes(): M2Node[]

Returns array of free nodes that have been added to the game.

Returns

M2Node[]

array of free nodes

Source

Game.ts:946


imageManager

get imageManager(): ImageManager

set imageManager(imageManager): void

Parameters

imageManager: ImageManager

Returns

ImageManager

Source

Game.ts:481


nodes

get nodes(): M2Node[]

Returns array of all nodes that have been added to the game object.

Returns

M2Node[]

Source

Game.ts:3097


soundManager

get soundManager(): SoundManager

set soundManager(soundManager): void

Parameters

soundManager: SoundManager

Returns

SoundManager

Source

Game.ts:492

Methods

IsCanvasPointWithinNodeBounds()

private IsCanvasPointWithinNodeBounds(node, x, y): boolean

Checks if the given canvas point is within the node's bounds.

Parameters

node: M2Node

node to check bounds for

x: number

x coordinate of the canvas point

y: number

y coordinate of the canvas point

Returns

boolean

true if x, y point is within the node's bounds

Source

Game.ts:3927


addEventControlsToDom()

private addEventControlsToDom(): void

Returns

void

Source

Game.ts:1317


addEventListener()

private addEventListener<T>(type, callback, options?): void

Type parameters

T extends ActivityEvent

Parameters

type: M2EventType

callback

options?: CallbackOptions

Returns

void

Source

Game.ts:3801


addFreeEntity()

addFreeEntity(node): void

Parameters

node: M2Node

Returns

void

Deprecated

Use addFreeNode() instead

Source

Game.ts:890


addFreeNode()

addFreeNode(node): void

Adds a node as a free node (a node that is not part of a scene) to the game.

Parameters

node: M2Node

node to add as a free node

Returns

void

Remarks

Once added to the game, a free node will always be drawn, and it will not be part of any scene transitions. This is useful if a node must persistently be drawn and not move with scene transitions. The appearance of the free node must be managed by the programmer. Note: internally, the free nodes are part of a special scene (named "__freeNodesScene"), but this scene is handled apart from regular scenes in order to achieve the free node behavior.

Source

Game.ts:883


addLocalizationParametersToGameParameters()

private addLocalizationParametersToGameParameters(): void

Returns

void

Source

Game.ts:225


addNodeEvents()

private addNodeEvents(node): void

Adds events from a node and its children to the game's event store.

Parameters

node: M2Node

node that contains events to add

Returns

void

Remarks

This method is first called when a scene is added to the game. If the scene or any of its descendants was constructed or had its properties changed before it was added to the game, these events were stored within the node (because the game event store was not yet available). This method retrieves these events from the node and adds them to the game's event store.

Source

Game.ts:983


addPrefixesToKey()

private addPrefixesToKey(key): string

Adds prefixes to a key to ensure that keys are unique across activities and studies.

Parameters

key: string

item key to add prefixes to

Returns

string

the item key with prefixes added

Remarks

When a value is saved to the key-value data store, the key must be prefixed with additional information to ensure that keys are unique. The prefixes will include the activity id and publish UUID, and possibly the study id and study UUID, if they are set (this is so that keys are unique across different studies that might use the same activity).

Source

Game.ts:526


addScene()

addScene(scene): void

Adds a scene to the game.

Parameters

scene: Scene

Returns

void

Remarks

A scene, and its children nodes, cannot be presented unless it has been added to the game object.

Source

Game.ts:964


addScenes()

addScenes(scenes): void

Adds multiple scenes to the game.

Parameters

scenes: Scene[]

Returns

void

Source

Game.ts:996


addStaticTrialData()

addStaticTrialData(variableName, value): void

Sets the value of a variable that will be the same for all trials.

Parameters

variableName: string

variable to be set

value: JsonSchemaDataTypeScriptTypes

value of the variable to set

Returns

void

Remarks

This sets the value of a variable that is the same across all trials ("static"). This is useful for variables that are not part of the trial schema, but that you want to save for each trial in your use case. For example, you might want to save the subject's participant ID for each trial, but this is not part of the trial schema. Rather than modify the source code for the game, you can do the following to ensure that the participant ID is saved for each trial:

game.addTrialSchema(&#123 participant_id: &#123 type: "string", description: "ID of the participant", } }); game.addStaticTrialData("participant_id", "12345");

When Game.trialComplete() is called, the participant_id variable will be saved for the trial with the value "12345".

Source

Game.ts:1867


addTimeSteppingControlsToDom()

private addTimeSteppingControlsToDom(): void

Returns

void

Source

Game.ts:1372


addTrialData()

addTrialData(variableName, value): void

Adds data to the game's TrialData object.

Parameters

variableName: string

variable to be set

value: JsonSchemaDataTypeScriptTypes

value of the variable to set

Returns

void

Remarks

The variableName must be previously defined in the trialSchema object passed in during game initialization through GameInitOptions.trialSchema. The type of the value must match what was defined in the trialSchema, otherwise an error is thrown.

Source

Game.ts:1748


addTrialSchema()

addTrialSchema(schema): void

Adds custom trial schema to the game's trialSchema object.

Parameters

schema: TrialSchema

Trial schema to add

Returns

void

Remarks

This is useful if you want to add custom trial variables. This must be done before Session.start() is called, because Session.start() will call Game.start(), which will initialize the trial schema.

Source

Game.ts:1832


advanceStepsHandler()

private advanceStepsHandler(mouseEvent): void

Parameters

mouseEvent: MouseEvent

Returns

void

Source

Game.ts:1433


animateSceneTransition()

private animateSceneTransition(incomingScene, transition, outgoingScene): void

Parameters

incomingScene: Scene

transition: Transition

outgoingScene: Scene

Returns

void

Source

Game.ts:2838


calculateFps()

private calculateFps(): void

Returns

void

Source

Game.ts:2722


calculatePointWithinNodeFromDomPointerEvent()

private calculatePointWithinNodeFromDomPointerEvent(node, domPointerEvent): Point

Parameters

node: M2Node

domPointerEvent: PointerEvent

Returns

Point

Source

Game.ts:3668


cancel()

cancel(): void

Should be called when current game has been canceled by a user action.

Returns

void

Remarks

This will send an ActivityCancel event to any listeners, such as a function provided to Game.onCancel() or a callback defined in SessionOptions.activityCallbacks.onActivityLifecycle. This is how the game can communicate changes in activity state to the parent session. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Source

Game.ts:2151


configureI18n()

private configureI18n(localizationOptions): Promise<void>

Parameters

localizationOptions: LocalizationOptions

Returns

Promise<void>

Source

Game.ts:336


createEventListener()

createEventListener(type, nodeName, callback, callbackOptions?): void

Creates an event listener for a node based on the node name

Parameters

type: M2EventType

the type of event to listen for, e.g., "tapDown"

nodeName: string

the node name for which an event will be listened

callback

the callback to be invoked when the event occurs

callbackOptions?: CallbackOptions

Returns

void

Remarks

Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with node name.

Source

Game.ts:3067


createFreeNodesScene()

private createFreeNodesScene(): void

Returns

void

Source

Game.ts:194


createOutgoingScene()

private createOutgoingScene(outgoingSceneImage): Scene

Creates a scene that has a screen shot of the current scene.

Parameters

outgoingSceneImage: Image

an image of the current scene

Returns

Scene

  • the scene with the screen shot

Source

Game.ts:2592


dispose()

dispose(): void

Frees up resources that were allocated to run the game.

Returns

void

Remarks

This will be done automatically by the m2c2kit library; the end-user must not call this. FOR INTERNAL USE ONLY.

Source

Game.ts:1642


draw()

private draw(canvas): void

Parameters

canvas: Canvas

Returns

void

Source

Game.ts:2710


drawFps()

private drawFps(canvas): void

Parameters

canvas: Canvas

Returns

void

Source

Game.ts:3040


end()

end(): void

Should be called when current game has ended successfully.

Returns

void

Remarks

This will send an ActivityEnd event to any listeners, such as a function provided to Game.onEnd() or a callback defined in SessionOptions.activityCallbacks.onActivityLifecycle. This is how the game can communicate changes in activity state to the parent session. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Source

Game.ts:2121


executeAfterUpdatePlugins()

private executeAfterUpdatePlugins(): void

Executes all active plugins after scenes have been updated.

Returns

void

Source

Game.ts:2700


executeBeforeUpdatePlugins()

private executeBeforeUpdatePlugins(): void

Executes all active plugins before scenes are updated.

Returns

void

Source

Game.ts:2685


getDeviceMetadata()

private getDeviceMetadata(): DeviceMetadata

Returns

DeviceMetadata

Source

Game.ts:1699


getImportedModuleBaseUrl()

private getImportedModuleBaseUrl(packageName, moduleUrl): string

Parameters

packageName: string

moduleUrl: string

Returns

string

Source

Game.ts:214


getLocalizationOptionsFromGameParameters()

private getLocalizationOptionsFromGameParameters(): LocalizationOptions

Returns

LocalizationOptions

Source

Game.ts:689


getParameter()

getParameter<T>(parameterName): T

Gets the value of the game parameter. If parameterName is not found, then throw exception.

Type parameters

T

Parameters

parameterName: string

the name of the game parameter whose value is requested

Returns

T

Source

Game.ts:1102


getParameterOrFallback()

getParameterOrFallback<T, U>(parameterName, fallbackValue): T | U

Gets the value of the game parameter. If parameterName is not found, then return fallback value

Type parameters

T

U

Parameters

parameterName: string

the name of the game parameter whose value is requested

fallbackValue: U

the value to return if parameterName is not found

Returns

T | U

Source

Game.ts:1121


handleIncomingSceneTransitions()

private handleIncomingSceneTransitions(incomingSceneTransitions): void

Parameters

incomingSceneTransitions: SceneTransition[]

Returns

void

Source

Game.ts:2528


handlePendingScreenshot()

private handlePendingScreenshot(pendingScreenshot): void

Parameters

pendingScreenshot: PendingScreenshot

Returns

void

Source

Game.ts:2759


hasDataStores()

hasDataStores(): boolean

Returns

boolean

Source

Game.ts:685


hasParameter()

hasParameter(parameterName): boolean

Returns true if a game parameter exists for the given string.

Parameters

parameterName: string

the name of the game parameter whose existence is queried

Returns

boolean

Source

Game.ts:1138


htmlCanvasPointerDownHandler()

private htmlCanvasPointerDownHandler(domPointerEvent): void

Receives callback from DOM PointerDown event

Parameters

domPointerEvent: PointerEvent

PointerEvent from the DOM

Returns

void

Source

Game.ts:3123


htmlCanvasPointerLeaveHandler()

private htmlCanvasPointerLeaveHandler(domPointerEvent): void

Parameters

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3189


htmlCanvasPointerMoveHandler()

private htmlCanvasPointerMoveHandler(domPointerEvent): void

Parameters

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3173


htmlCanvasPointerUpHandler()

private htmlCanvasPointerUpHandler(domPointerEvent): void

Parameters

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3157


init()

init(): Promise<void>

Initializes the activity.

Returns

Promise<void>

Implementation of

Activity.init

Remarks

All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the Game class, this method will be overridden, but the base method must still be called with await super.init().

Deprecated

use Game.initialize() instead.

Source

Game.ts:232


initData()

private initData(): void

Returns

void

Source

Game.ts:1649


initialize()

initialize(): Promise<void>

Initializes the activity.

Returns

Promise<void>

Implementation of

Activity.initialize

Remarks

All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the Game class, this method will be overridden, but the base method must still be called with await super.initialize().

Source

Game.ts:370


interceptWebGlCalls()

private interceptWebGlCalls(): void

Returns

void

Source

Game.ts:2274


isLocalizationRequested()

private isLocalizationRequested(): boolean

Returns

boolean

Source

Game.ts:713


loadCanvasKit()

Internal

loadCanvasKit(canvasKitWasmUrl): Promise<CanvasKit>

Loads the canvaskit wasm binary.

For m2c2kit library use only

Parameters

canvasKitWasmUrl: string

URL to the canvaskit wasm binary

Returns

Promise<CanvasKit>

a promise that resolves to a CanvasKit object

Remarks

The CanvasKit object is initialized with this method, rather than calling CanvasKitInit() directly, so that this method can be easily mocked in tests.

Source

Game.ts:248


loadManifest()

Internal

loadManifest(manifestJsonUrl): Promise<Manifest>

Returns the manifest, if manifest.json was created during the build.

For m2c2kit library use only

Parameters

manifestJsonUrl: string= "__NO_M2C2KIT_MANIFEST_JSON_URL__"

Do not use this parameter. Allow the default.

Returns

Promise<Manifest>

a promise that resolves to the manifest object, or an empty object if there is no manifest

Remarks

This should be called without any parameters. The manifestJsonUrl parameter's default value will be modified during the build step, if the build was configured to include the manifest.json

Source

Game.ts:441


loop()

private loop(canvas): void

Parameters

canvas: Canvas

Returns

void

Source

Game.ts:2404


makeGameActivityConfiguration()

private makeGameActivityConfiguration(parameters): unknown

GameParameters combines default parameters values and JSON Schema to describe what the parameters are. The next two functions extract GameParameters's two parts (the default values and the schema) so they can be returned separately in the activityData event

Parameters

parameters: GameParameters

Returns

unknown

Source

Game.ts:2048


makeGameActivityConfigurationSchema()

private makeGameActivityConfigurationSchema(parameters): JsonSchema

Parameters

parameters: GameParameters

Returns

JsonSchema

Source

Game.ts:2069


makeGameDataSchema()

private makeGameDataSchema(): JsonSchema

Returns

JsonSchema

Source

Game.ts:2012


makeNewGameDataSchema()

private makeNewGameDataSchema(): JsonSchema

Returns

JsonSchema

Source

Game.ts:1996


onCancel()

onCancel(callback, options?): void

Executes a callback when the game is canceled.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onCancel

Source

Game.ts:3738


onData()

onData(callback, options?): void

Executes a callback when the game generates data.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onData

Source

Game.ts:3764


onEnd()

onEnd(callback, options?): void

Executes a callback when the game ends.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onEnd

Source

Game.ts:3751


onStart()

onStart(callback, options?): void

Executes a callback when the game starts.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onStart

Source

Game.ts:3725


onWarmupEnd()

Internal

onWarmupEnd(callback, options?): void

Executes a callback when the game ends its warmup.

For m2c2kit library use only

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

Game.ts:3794


onWarmupStart()

Internal

onWarmupStart(callback, options?): void

Executes a callback when the game begins its warmup.

For m2c2kit library use only

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

Game.ts:3779


playEventsHandler()

playEventsHandler(mouseEvent): void

Parameters

mouseEvent: MouseEvent

Returns

void

Source

Game.ts:1256


presentScene()

presentScene(scene, transition?): void

Specifies the scene that will be presented upon the next frame draw.

Parameters

scene: string | Scene

the scene, its string name, or UUID

transition?: Transition

Returns

void

Source

Game.ts:1033


processDomPointerDown()

private processDomPointerDown(node, nodeEvent, domPointerEvent): void

Determines if/how m2c2kit nodes respond to the DOM PointerDown event

Parameters

node: M2Node

node that might be affected by the DOM PointerDown event

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3220


processDomPointerLeave()

private processDomPointerLeave(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3438


processDomPointerMove()

private processDomPointerMove(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3345


processDomPointerUp()

private processDomPointerUp(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3266


propertySchemaDataTypeIsValid()

private propertySchemaDataTypeIsValid(propertySchemaType): boolean

Parameters

propertySchemaType: JsonSchemaDataType | JsonSchemaDataType[]

Returns

boolean

Source

Game.ts:1671


raiseActivityEventOnListeners()

private raiseActivityEventOnListeners(activityEvent, extra?): void

Parameters

activityEvent: ActivityEvent

extra?: unknown

Returns

void

Source

Game.ts:3826


raiseEventOnListeningNodes()

private raiseEventOnListeningNodes<T>(node, nodeEvent, domEvent): void

Type parameters

T extends M2NodeEvent

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domEvent: Event

Returns

void

Source

Game.ts:3844


raiseM2DragEndEvent()

private raiseM2DragEndEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3640


raiseM2DragEvent()

private raiseM2DragEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3626


raiseM2DragStartEvent()

private raiseM2DragStartEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3612


raiseM2PointerDownEvent()

private raiseM2PointerDownEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3516


raiseM2PointerLeaveEvent()

private raiseM2PointerLeaveEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3598


raiseM2PointerMoveEvent()

private raiseM2PointerMoveEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3584


raiseM2PointerUpEvent()

private raiseM2PointerUpEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3550


raiseSceneEvent()

private raiseSceneEvent(scene, eventType): void

Parameters

scene: Scene

eventType: "SceneSetup" | "SceneAppear"

Returns

void

Source

Game.ts:3654


raiseTapDownEvent()

private raiseTapDownEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3530


raiseTapLeaveEvent()

private raiseTapLeaveEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3540


raiseTapUpAny()

private raiseTapUpAny(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3574


raiseTapUpEvent()

private raiseTapUpEvent(node, nodeEvent, domPointerEvent): void

Parameters

node: M2Node

nodeEvent: M2NodeEvent

domPointerEvent: PointerEvent

Returns

void

Source

Game.ts:3564


registerPlugin()

registerPlugin(plugin): Promise<void>

Registers a plugin with the game.

Parameters

plugin: Plugin

Plugin to register

Returns

Promise<void>

Remarks

Upon registration, the plugin's optional asynchronous initialize() method will be called.

Source

Game.ts:2642


removeAllFreeEntities()

removeAllFreeEntities(): void

Returns

void

Deprecated

Use removeAllFreeNodes() instead

Source

Game.ts:937


removeAllFreeNodes()

removeAllFreeNodes(): void

Removes all free nodes from the game.

Returns

void

Source

Game.ts:928


removeFreeEntity()

removeFreeEntity(node): void

Parameters

node: string | M2Node

Returns

void

Deprecated

Use removeFreeNode() instead

Source

Game.ts:921


removeFreeNode()

removeFreeNode(node): void

Removes a free node from the game.

Parameters

node: string | M2Node

the free node to remove or its name as a string

Returns

void

Remarks

Throws exception if the node to remove is not currently added to the game as a free node

Source

Game.ts:902


removeScene()

removeScene(scene): void

Removes a scene from the game.

Parameters

scene: string | Scene

the scene to remove or its name as a string

Returns

void

Source

Game.ts:1007


removeTimeSteppingControlsFromDom()

private removeTimeSteppingControlsFromDom(): void

Returns

void

Source

Game.ts:1444


resolveGameBaseUrls()

Internal

resolveGameBaseUrls(game): Promise<GameBaseUrls>

Resolves base URL locations for game assets and CanvasKit wasm binary.

For m2c2kit library use only

Parameters

game: Game

game to resolve base URLs for

Returns

Promise<GameBaseUrls>

base URLs for game assets and CanvasKit wasm binary

Source

Game.ts:260


sceneCanReceiveUserInteraction()

private sceneCanReceiveUserInteraction(scene): boolean

Parameters

scene: Scene

Returns

boolean

Source

Game.ts:3906


setParameters()

setParameters(additionalParameters): void

Sets additional activity parameters if defaults are not sufficient.

Parameters

additionalParameters: unknown

Returns

void

Implementation of

Activity.setParameters

Source

Game.ts:743


setReplayEventsButtonEnabled()

private setReplayEventsButtonEnabled(enable): void

Parameters

enable: boolean

Returns

void

Source

Game.ts:1291


setStopReplayButtonEnabled()

private setStopReplayButtonEnabled(enable): void

Parameters

enable: boolean

Returns

void

Source

Game.ts:1305


setupCanvasDomEventHandlers()

private setupCanvasDomEventHandlers(): void

Returns

void

Source

Game.ts:2370


setupCanvasKitSurface()

private setupCanvasKitSurface(): void

Returns

void

Source

Game.ts:2241


setupFpsFont()

private setupFpsFont(): void

Returns

void

Source

Game.ts:2353


setupHtmlCanvases()

private setupHtmlCanvases(canvasId, width, height, stretch): void

Parameters

canvasId: undefined | string

width: number

height: number

stretch: undefined | boolean

Returns

void

Source

Game.ts:2171


start()

start(entryScene?): Promise<void>

Starts the game loop.

Parameters

entryScene?: string | Scene

The scene (Scene object or its string name) to display when the game starts

Returns

Promise<void>

Implementation of

Activity.start

Remarks

If entryScene is undefined, the game will start with scene defined in the game object's entryScene property. If that is undefined, the game will start with the first scene in the game object's scenes. If there are no scenes in the game object's scenes, it will throw an error. Although the method has no awaitable calls, we will likely do so in the future. Thus this method is async.

Source

Game.ts:1162


stop()

stop(): void

Stops the activity

Returns

void

Implementation of

Activity.stop

Source

Game.ts:1627


storeClearItems()

storeClearItems(): Promise<void>

Deletes all items from the activity's key-value store.

Returns

Promise<void>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:627


storeDeleteItem()

storeDeleteItem(key, globalStore): Promise<void>

Deletes an item value from the activity's key-value store.

Parameters

key: string

item key

globalStore: boolean= false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<void>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:610


storeGetItem()

storeGetItem<T>(key, globalStore): Promise<T>

Gets an item value from the activity's key-value store.

Type parameters

T extends undefined | null | string | number | boolean | object

Parameters

key: string

item key

globalStore: boolean= false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<T>

value of the item

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:586


storeItemExists()

storeItemExists(key, globalStore): Promise<boolean>

Determines if a key exists in the activity's key-value store.

Parameters

key: string

item key

globalStore: boolean= false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<boolean>

true if the key exists, false otherwise

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:669


storeItemsKeys()

storeItemsKeys(globalStore): Promise<string[]>

Returns keys of all items in the activity's key-value store.

Parameters

globalStore: boolean= false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<string[]>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:646


storeSetItem()

storeSetItem(key, value, globalStore): Promise<string>

Saves an item to the activity's key-value store.

Parameters

key: string

item key

value: undefined | null | string | number | boolean | object

item value

globalStore: boolean= false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<string>

key

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Source

Game.ts:556


takeCurrentSceneSnapshot()

private takeCurrentSceneSnapshot(): Image

Returns

Image

Source

Game.ts:2752


takeScreenshot()

takeScreenshot(sx?, sy?, sw?, sh?): Promise<null | Uint8Array>

Takes screenshot of canvas

Parameters

sx?: number

Upper left coordinate of screenshot

sy?: number

Upper right coordinate of screenshot

sw?: number

width of area to screenshot

sh?: number

height of area to screenshot

Returns

Promise<null | Uint8Array>

Promise of Uint8Array of image data

Remarks

Coordinates should be provided unscaled; that is, the method will handle any scaling that happened due to device pixel ratios not equal to 1. This returns a promise because the screenshot request must be queued and completed once a draw cycle has completed. See the loop() method.

Source

Game.ts:2794


trialComplete()

trialComplete(): void

Should be called when the current trial has completed. It will also increment the trial index.

Returns

void

Remarks

Calling will trigger the onActivityResults callback function, if one was provided in SessionOptions. This is how the game communicates trial data to the parent session, which can then save or process the data. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Source

Game.ts:1890


update()

private update(): void

Updates active scenes and executes plugins.

Returns

void

Source

Game.ts:2666


updateGameTime()

private updateGameTime(): void

Returns

void

Source

Game.ts:2514


updateScenes()

private updateScenes(): void

Updates all active scenes and their children.

Returns

void

Source

Game.ts:2675


updateTimeSteppingOutput()

private updateTimeSteppingOutput(): void

Returns

void

Source

Game.ts:1418


waitForErudaInitialization()

private waitForErudaInitialization(maxWaitDurationMs): Promise<void>

Parameters

maxWaitDurationMs: number= 5000

Returns

Promise<void>

Source

Game.ts:350


warmupShadersWithPrimitives()

private warmupShadersWithPrimitives(canvas, positionOffset): void

Warms up the Skia-based shaders underlying canvaskit by drawing primitives.

Parameters

canvas: Canvas

the canvaskit-canvas to draw on

positionOffset: number= 0

an offset to add to the position of each primitive. Different shaders may be compiled depending on if the position was fractional or not. This offset allows us to warmup both cases.

Returns

void

Remarks

Some canvaskit methods take extra time the first time they are called because a WebGL shader must be compiled. If the method is part of an animation, then this may cause frame drops or "jank." To alleviate this, we can "warm up" the shader associated with the method by calling it at the beginning of our game. Thus, all warmup operations will be concentrated at the beginning and will not be noticeable. This warmup function draws a series of primitives to the canvas. From testing, the actual WebGl shaders compiled by canvaskit vary depending on the device hardware. Thus, warmup functions that might call all relevant WebGL shaders on desktop hardware may not be sufficient for mobile.

Source

Game.ts:1471


warmupShadersWithScenes()

private warmupShadersWithScenes(canvas): void

Warms up the Skia-based shaders underlying canvaskit by drawing m2c2kit nodes.

Parameters

canvas: Canvas

the canvaskit-canvas to draw on

Returns

void

Remarks

While warmupShadersWithPrimitives draws a predefined set of primitives, this function initializes and draws all canvaskit objects that have been defined as m2c2kit nodes. This not only is another opportunity for shader warmup, it also does the node initialization.

Source

Game.ts:1584