|
1 | 1 | # @nativescript/canvas-phaser |
2 | 2 |
|
3 | | -Tools for using Phaser3 to build native 2D games in NativeScript 👾👾 |
4 | | - |
5 | | -- [Installation](#installation) |
6 | | -- [Usage](#usage) |
7 | | -- [Functions](#functions) |
| 3 | +Tools for using Phaser to build native 2D games in NativeScript 👾👾 |
8 | 4 |
|
9 | 5 | ### Installation |
10 | 6 |
|
11 | 7 | ```bash |
12 | 8 | npm i @nativescript/canvas-phaser |
13 | 9 | ``` |
14 | 10 |
|
15 | | -### Usage |
16 | | - |
17 | | -Import the library into your JavaScript file: |
18 | | - |
19 | | -```js |
20 | | -import TNSPhaser from "@nativescript/canvas-phaser"; |
21 | | -``` |
22 | | - |
23 | | -## Functions |
24 | | - |
25 | | -### `TNSPhaser.game({ canvas, renderer: Phaser.WEBGL || Phaser.CANVAS, ...extras })` |
26 | | - |
27 | | -Given a `canvas` from a |
28 | | -[`Canvas`](https://github.com/nativescript/canvas), return a |
29 | | -[`Phaser.Game`](https://photonstorm.github.io/phaser3-docs/Phaser.Game.html) |
30 | | -that draws into it. |
31 | | - |
32 | | -#### Props |
33 | | - |
34 | | -| Property | Type | Description | Default Value | |
35 | | -| ----------- | :-------------------: | --------------------------------------------------------------------------- | :---------------------------: | |
36 | | -| canvas | TNSCanvas| Required: canvas that the `Phaser.Game` will render to | `null` | |
37 | | -| renderer | number?| Optional: choose the renderer type e.g Phaser.CANVAS (1) , Phaser.WEBGL(2) | `1` | |
38 | | -| width | number? | Optional: height of the `Phaser.Game` | `canvas height` | |
39 | | -| height | number? | Optional: width of the `Phaser.Game` | `canvas width` | |
40 | | -| title | string? | Optional: title of the `Phaser.Game` | `"tns-phaser-game"` | |
41 | | - |
42 | | -#### Returns |
43 | | - |
44 | | -| Property | Type | Description | |
45 | | -| -------- | :------------------------------------------------------------: | ------------------------------------------------ | |
46 | | -| game | [`Phaser.Game`](https://photonstorm.github.io/phaser3-docs/Phaser.Game.html) | The Phaser3 game used for rendering game logic | |
47 | | - |
48 | | -## Example |
49 | | - |
50 | | -```js |
51 | | -const game = TNSPhaser.game({ canvas }); |
52 | | -``` |
53 | | - |
54 | | -## What does it do? |
55 | | - |
56 | | -Under the hood, TNSPhaser is maintaining global instances of a few libraries. |
57 | | - |
58 | | -- [Phaser3](https://github.com/photonstorm/phaser) |
59 | | - |
60 | | -```js |
61 | | -window.Phaser = require("phaser"); |
62 | | -``` |
63 | | - |
64 | | -Finally when a new instance of `TNSPhaser.Game` is created, we set the `document.readyState` to `'complete'` |
65 | | - |
66 | | -```js |
67 | | -global.document.readyState = "complete"; |
68 | | -``` |
69 | | - |
70 | 11 | ## License |
71 | 12 |
|
72 | 13 | Apache License Version 2.0, January 2004 |
0 commit comments