目录

Web API

Based on the JavaScript running environment on virtual machine (VMs), HUAWEI Quick Game provides a series of common web APIs based on JavaScript to adapt web games to quick games. The APIs function the same in both quick games and the web environment.

Document

Quick Game simulates some document APIs using adapters to adapt web games to quick games.

[h2]Parameters

Global Document Object

Parameter

Description

document

readyState

Document loading status.

visibilityState

Visibility of the document object.

documentElement

Root element of the document object.

hidden

Indicates whether to hide a document. The value is of the Boolean type. The options are true (yes) and false (no).

location

Location object that contains document URL information.

head

Head element in the current document.

body

Body element in the current document.

scripts

Collection of all script elements in the current document.

[h2]Methods

Method

Description

createElementNS(namespaceURI, qualifiedName, options)

Creates an element with the specified namespace URI and qualified name.

createElement(tagName)

Creates an element of a specified type.

getElementById(id)

Obtains an element of a specified ID.

getElementsByTagName(tagName)

Obtains a collection of HTML elements with all the given tags.

getElementsByName(tagName)

Obtains a collection of elements with given tag names.

querySelector(query)

Obtains the first HTML element within the document that matches the specified selector or group of selectors.

querySelectorAll(query)

Obtains a list of elements within the document that match the specified group of selectors.

createTextNode()

Creates a text element.

window[type] createEvent(type)

Creates an event of a specified type.

[h2]HTMLElement createElementNS(namespaceURI, qualifiedName, options)

[h2]HTMLElement createElement(tagName)

[h2]HTMLElement getElementById(id)

[h2]HTMLElement getElementsByTagName(tagName)

[h2]HTMLElement getElementsByName(tagName)

[h2]HTMLElement querySelector(query)

[h2]HTMLElement querySelectorAll(query)

[h2]HTMLElement createTextNode()

[h2]window[type] createEvent(type)

LocalStorage

Quick Game implements standard web local storage. For details, please refer to Local Storage API Reference.

[h2]Restrictions

  1. The upper limit of the data cache is 10 MB.
  2. The upper limit size of the data that can be stored in the cache at a time is 1 MB.
  3. A HUAWEI ID has been used for sign-in to use local storage.

A maximum of 9 data records, each with a size of 1 MB, can be written to the data cache because the data keys and table structure in the data cache also occupy some storage space. The tenth data record will fail to be written because the storage space is exceeded.

[h2]Methods

Method

Description

window.localStorage.setItem(keyName, keyValue)

Modifies the content stored in the app database.

window.localStorage.getItem(keyName)

Reads the content stored in the app database.

window.localStorage.removeItem(keyName)

Deletes the content stored in the app database.

window.localStorage.clear()

Clears the content stored in the app database.

[h2]window.localStorage.setItem(keyName, keyValue)

[h2]window.localStorage.getItem(keyName)

[h2]window.localStorage.removeItem(keyName)

[h2]window.localStorage.clear()

Canvas 2D

Quick Game implements only a small number of Canvas 2D APIs for offscreen rendering of text and lines. To call any Canvas 2D API, create an offscreen canvas object in advance (let canvas = document.createElement('canvas');), and specify the width and height of the canvas (canvas.width = 100; and canvas.height = 100;) so that the drawing buffer size can be allocated.

[h2]Parameters

Parameter

Description

width

Width of the canvas, that is, the width of the drawing buffer.

height

Height of the canvas, that is, the height of the drawing buffer.

lineWidth

Line width. When a parameter value is obtained, the current value is returned. The default value is 1.0. Values such as 0, negative values, Infinity, and NaN are ignored when assigned to this parameter.

font

Font style, for example, oblique small-caps 18px Arial. The default font is Arial and the default font size is 30.

  • font-weight: A value (1–1000) cannot be directly specified for this attribute.
  • line-height: It is not supported.

A canvas supports only single-line font drawing. Setting the line height does not affect the font display. Therefore, line-height is not supported.

textAlign

Horizontal alignment. The options are as follows:

  • left: The text is left-aligned.
  • right: The text is right-aligned.
  • center: The text is horizontally centered.

textBaseline

Vertical alignment. The options are as follows:

  • top: The text is aligned on the top.
  • bottom: The text is aligned at the bottom.
  • middle: The text is vertically centered.

fillStyle

Fill color. When the fillText API is called, the text is filled with the solid color.

strokeStyle

Stroke color. When the strokeText API is called, this color is used as the text outline color.

[h2]Methods

Method

Description

void beginPath()

Creates a path by deleting the subpath list.

void moveTo(x, y)

Moves the start point of a subpath.

void closePath()

Returns from the current point to the start point of the current subpath.

void quadraticCurveTo(cpx, cpy, x, y)

Creates a quadratic Bezier curve.

void stroke()

Draws the current path.

void fill()

Fills the current drawing (path).

void rect(x, y, width, height)

Creates a rectangle.

void clearRect(x, y, width, height)

Clears the rectangle area, and sets all pixels in a rectangle area to be transparent. The rectangle starts from (x, y) and has the size specified by (width, height).

void fillRect(x, y, width, height)

Draws and fills a rectangle. The default fill color is black.

TextMetrics measureText(text)

Measures and returns the dimensions of the text.

void strokeText(text, x, y [, maxWidth])

Draws the text at a specified position.

void fillText(text, x, y [, maxWidth])

Fills a text with a solid color.

void scale(scalewidth, scaleheight)

Zooms in or out on the current drawing.

void rotate(angle)

Rotates the current drawing.

void translate(x, y)

Remaps the point (0, 0) on the canvas.

void transform(a, b, c, d, e, f)

Replaces the current transformation matrix.

void resetTransform()

Resets the current transformation matrix to an identity matrix.

void save()

Saves the current environment status to the stack.

void restore()

Pops up the environment status on the top of the stack and restores the context to the status.

ImageData createImageData(width, height)

Quick Game implements the standard createImageData method of web APIs. For details, please refer to createImageData API Reference.

ImageData createImageData(imagedata)

Quick Game implements the standard createImageData method of web APIs. For details, please refer to createImageData API Reference.

ImageData getImageData(x,y,width,height)

Quick Game implements the standard getImageData method of web APIs. For details, please refer to getImageData API Reference.

void putImageData(imagedata, dx, dy)

Quick Game implements the standard putImageData method of web APIs. For details, please refer to putImageData API Reference.

void putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)

Quick Game implements the standard putImageData method of web APIs. For details, please refer to putImageData API Reference.

[h2]void beginPath()

[h2]void moveTo(x, y)

[h2]void closePath()

[h2]void quadraticCurveTo(cpx, cpy, x, y)

[h2]void stroke()

[h2]void fill()

[h2]void rect(x, y, width, height)

[h2]void clearRect(x, y, width, height)

[h2]void fillRect(x, y, width, height)

[h2]TextMetrics measureText(text)

[h2]void strokeText(text, x, y [, maxWidth])

[h2]void fillText(text, x, y [, maxWidth])

[h2]void scale(scalewidth, scaleheight)

[h2]void rotate(angle)

[h2]void translate(x, y)

[h2]void transform(a, b, c, d, e, f)

[h2]void resetTransform()

[h2]void save()

[h2]void restore()

[h2]ImageData createImageData(width, height) and ImageData createImageData(imagedata)

[h2]ImageData getImageData(x,y,width,height)

[h2]void putImageData(imagedata, dx, dy) and void putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)

Touch

Quick Game implements the standard web API Touch. For details, please refer to Touch API Reference.

Attributes not supported by Touch:

When a game is played in full screen, the values of screenX and screenY equal those of clientX and clientY, respectively.