API
Basics
bn.getSystemInfo
Return Values
Object res
Property | Type | Example | Description |
---|---|---|---|
brand | string | "Apple" "Xiaomi" | Device brand |
model | string | Device model | |
pixelRatio | number | Device's pixel ratio | |
screenWidth | number | Screen width in px | |
screenHeight | number | Screen height in px | |
windowWidth | number | Available window width in px | |
windowHeight | number | Available window height in px | |
statusBarHeight | number | Status bar height in px | |
language | string | Language set in App | |
version | string | App version | |
SDKVersion | string | Base library version for the App version | |
system | string | Operating system and version | |
platform | string | "ios" "android" | Client platform |
safeArea | Object | Safe area when the screen is in vertical orientation platform |
res.safeArea
Property | Type | Description |
---|---|---|
left | number | The x-coordinate of the top-left corner of the safe area |
right | number | The x-coordinate of the bottom-right corner of the safe area |
top | number | The y-coordinate of the top-left corner of the safe area |
bottom | number | The y-coordinate of the bottom-right corner of the safe area |
width | number | Safe area width in logical pixels |
height | number | Safe area height in logical pixels |
bn.getLaunchOptionsSync
Obtains the parameters upon Mini Game startup.
Return Values
Object res Startup parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
scene | number | - | - | The scene value for Mini Game startup |
query | Object | - | - | The query parameter for Mini Game startup |
referrerInfo | Object | - | - | The source information. This is returned when a user enters the Mini Program from another Mini Program, Official Account, or app. Otherwise, {} is returned. (see the Note below for details.) |
referrerInfo is composed as follows
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
appId | string | - | - | The appId of the source Mini Program, Official Account, or app. |
extraData | Object | - | - |
bn.getEnterOptionsSync
Gets the parameters when the applet starts. If the current startup is cold, the return value is the same as the callback parameter for bn.getLaunchOptionsSync
; If the current is a hot start, the return value is the same as bn.onShow
.
Return Values
Object res Startup parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
scene | number | - | - | The scene value for Mini Game startup |
query | Object | - | - | The query parameter for Mini Game startup |
referrerInfo | Object | - | - | The source information. This is returned when a user enters the Mini Program from another Mini Program, Official Account, or app. Otherwise, {} is returned. (see the Note below for details) |
referrerInfo is composed as follows
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
appId | string | - | - | The appId of the source Mini Program, Official Account, or app. |
extraData | Object | - | - |
bn.onUnhandledRejection
Listen for unhandled Promise
rejection events.
Parameters
function callback
Callback function for unhandled Promise
rejection event.
function parameters
Object res
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
reason | string | - | Reason for rejection, usually an Error object | |
promise | Promise.<any> | - | scene code |
Notes
All unhandledRejection
can be captured by this monitor, but only the Error
type will trigger an alarm in the background of the applet.
bn.onError
Listens on the Mini Game error event. This event is triggered as a result of script error or failed API call.
Parameters
function callback
The callback function for the Mini Game error event.
Parameters
string error Error message, including stacks.
bn.onShow
Listens on the event that Mini Game is switched to foreground.
Parameters
function callback
The callback function for the event that Mini Game is switched to foreground.
Parameters
Object res
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
scene | number | - | - | The scene value for Mini Game startup |
query | Object | - | - | The query parameter for Mini Game startup |
referrerInfo | Object | - | - | The source information. This is returned when a user enters the Mini Program from another Mini Program, Official Account, or app. Otherwise, {} is returned. (see the Note below for details.) |
referrerInfo is composed as follows
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
appId | string | - | - | The appId of the source Mini Program, Official Account, or app. |
extraData | Object | - | - |
Notes
In some versions, when there is no referrerInfo
, the value undefined is returned. You can use options.referrerInfo && options.referrerInfo.appId
to make a judgment.
bn.offHide
Listens on the event that Mini Game is switched to background.
Parameters
function callback
The callback function for the event that Mini Game is switched to background.
bn.offUnhandledRejection
Cancel listening for unhandled Promise rejection events.
Parameters
function callback
Callback function for unhandled Promise rejection event.
bn.offError
Un-listens on Mini Game error event.
Parameters
function callback
The callback function for the Mini Game error event.
bn.offShow
Un-listens on the event that Mini Game is switched to foreground.
Parameters
function callback
The callback function for the event that Mini Game is switched to foreground.
bn.offHide
Un-listens on the event that Mini Game is switched to background.
Parameters
function callback
The callback function for the event that Mini Game is switched to background.
bn.loadSubpackage(payload)
Triggers subpackage loading.
Parameters
Object payload
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
name | string | ✓ | The name of the subpackage, which can be name or root. | |
success | function | The callback event that the subpackage loading succeeds. | ||
fail | function | CThe callback event that the subpackage loading fails. | ||
complete | function | The callback event that the subpackage loading completed (always executed whether the loading succeeds or fails) |
Return Values
LoadSubpackageTask
Loads subpackage task instances to obtain the subpackage loading status.
LoadSubpackageTask.onProgressUpdate(function callback)
Listens on the subpackage loading progress change event.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. ({ progress }) => void |
Parameters object of callback function
Property | Type | Description |
---|---|---|
progress | number | Subpackage download progress percentage |
totalBytesWritten | number | The length of downloaded data, in bytes |
totalBytesExpectedToWrite | number | The length of data expected to be downloaded, in bytes |
Example
const loadTask = bn.loadSubpackage({
name: 'subpackage1', // could be value of name or root
success: function (res) {},
fail: function (res) {},
})
loadTask.onProgressUpdate(res => {
console.log(res.progress)
console.log(res.totalBytesWritten)
console.log(res.totalBytesExpectedToWrite)
})
Rendering
bn.createCanvas
Creates a canvas object. When this API is called the first time, an on-screen canvas is created, and thereafter, off-screen canvases are created.
Return Values
Canvas
The canvas object.
Canvas.getContext(string contextType, Object contextAttributes)
Gets the drawing context of a canvas object.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
contextType | string | - | ✓ | drawing context (2d or webgl) |
contextAttributes | Object | - | - | The WebGL context property, which is valid only when contextType is WebGL. |
Object contextAttributes
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
antialias | boolean | false | - | Indicates whether to enable antialiasing. |
preserveDrawingBuffer | boolean | false | - | Indicates whether to preserve drawing buffer when drawing is finished. |
antialiasSamples | number | - | - | The number of antialiasing samples. |
Return Values
RenderingContext
The drawing context.
bn.createImage
Creates an image object.
Return Values
Image
The image object.
string src
The image URL.
number width
The actual width of the image.
number height
The actual height of the image.
function onload
The callback function triggered after the image is loaded.
function onerror
The callback function triggered after an error occurred during image loading.
Touch Events
bn.onTouchStart
listens on the event that the user starts to touch the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
Parameters object of callback function
Property | Type | Description |
---|---|---|
touches | Array.<Touch> | List of all current touch points |
changedTouches | Array.<Touch> | List of touch points that triggered this event |
timeStamp | number | Timestamp when the event was triggered |
bn.onTouchMove
listens on the event that the user moves a finger on the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
Parameters object of callback function
Property | Type | Description |
---|---|---|
touches | Array.<Touch> | List of all current touch points |
changedTouches | Array.<Touch> | List of touch points that triggered this event |
timeStamp | number | Timestamp when the event was triggered |
bn.onTouchEnd
listens on the event that the user releases a finger from the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
Parameters object of callback function
Property | Type | Description |
---|---|---|
touches | Array.<Touch> | List of all current touch points |
changedTouches | Array.<Touch> | List of touch points that triggered this event |
timeStamp | number | Timestamp when the event was triggered |
bn.onTouchCancel
listens on the event that the user cancels a touch event.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
Parameters object of callback function
Property | Type | Description |
---|---|---|
touches | Array.<Touch> | List of all current touch points |
changedTouches | Array.<Touch> | List of touch points that triggered this event |
timeStamp | number | Timestamp when the event was triggered |
bn.offTouchStart
un-listens on the event that the user starts to touch the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
bn.offTouchMove
un-listens on the event that the user moves a finger on the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
bn.offTouchEnd
un-listens on the event that the user releases a finger from the screen.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
bn.offTouchCancel
un-listens on the event that the user cancels a touch event.
Parameters
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
callback | function | - | ✓ | The callback function. |
Touch
Touch object indicates a touch point on a touch-controlled device. Usually refers to an operation by a finger or pen on a touchscreen device or touchpad.
number identifier
Touch object's unique identifier (read-only). In the whole process of a touch action (finger touch) moving on the screen, this identifier does not change. Can be used to determine whether it is the same touch that is being tracked.
number pageX
The X coordinate of the touch point relative to the left edge of the screen.
number pageY
The Y coordinate of the touch point relative to the top edge of the screen.
number clientX
The X coordinate of the touch point relative to the left edge of the viewport.
number clientY
The Y coordinate of the touch point relative to the top edge of the viewport.
File System Manager
bn.getFileSystemManager
Get the file system manager instance which is a singleton. On Android devices, file system api will save file on external storage by default.
Return Values
Object res
Property | Type | Description |
---|---|---|
readFile | Function | Read files in local directory. |
var fs = bn.getFileSystemManager() // FileSystemManager