angry-pixel 2.0.9 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -22
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +17 -6
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## What is Angry Pixel Engine?
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Angry Pixel Engine is a 2D game engine for browser written in Typescript.
|
|
11
11
|
|
|
12
12
|
Main features:
|
|
13
13
|
|
|
@@ -15,9 +15,11 @@ Main features:
|
|
|
15
15
|
- WebGL rendering
|
|
16
16
|
- Sprite-based graphics and frame-by-frame animations
|
|
17
17
|
- Text rendering based on bitmap fonts
|
|
18
|
-
-
|
|
19
|
-
- Polygonal
|
|
18
|
+
- Basic 2D lightning system
|
|
19
|
+
- Polygonal collision detection and physical responses based on speed and acceleration.
|
|
20
20
|
- Keyboard, mouse, gamepad and touch screen input support
|
|
21
|
+
- Ability to create desktop/mobile games using frameworks such as Electron.js
|
|
22
|
+
- Tilemaps: rendering based on comma separated values, and automatic collider generation. Support for JSON files exported from Tiled.
|
|
21
23
|
- Dependency Injection
|
|
22
24
|
|
|
23
25
|
## Getting Started
|
|
@@ -68,7 +70,7 @@ import { Scene } from "angry-pixel";
|
|
|
68
70
|
|
|
69
71
|
class MainScene extends Scene {
|
|
70
72
|
// within this method we load the assets
|
|
71
|
-
|
|
73
|
+
loadAssets(): void {
|
|
72
74
|
this.assetManager.loadImage("logo.png");
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -77,7 +79,7 @@ class MainScene extends Scene {
|
|
|
77
79
|
And we add this scene to our game:
|
|
78
80
|
|
|
79
81
|
```typescript
|
|
80
|
-
// arguments: the scene class, the scene name,
|
|
82
|
+
// arguments: the scene class, the scene name, opening scene = true
|
|
81
83
|
game.addScene(MainScene, "MainScene", true);
|
|
82
84
|
```
|
|
83
85
|
|
|
@@ -103,7 +105,7 @@ Once we have created our component, we will need a system that executes the busi
|
|
|
103
105
|
import { GameSystem, Transform } from "angry-pixel";
|
|
104
106
|
|
|
105
107
|
class MoveAndBounceSystem extends GameSystem {
|
|
106
|
-
|
|
108
|
+
onUpdate(): void {
|
|
107
109
|
this.entityManager.search(MoveAndBounce).forEach(({ component, entity }) => {
|
|
108
110
|
const transform = this.entityManager.getComponent(entity, Transform);
|
|
109
111
|
const { boundaries, direction, speed } = component;
|
|
@@ -129,45 +131,47 @@ Once the system is created, we can add it to the scene
|
|
|
129
131
|
import { Scene } from "angry-pixel";
|
|
130
132
|
|
|
131
133
|
class MainScene extends Scene {
|
|
132
|
-
|
|
133
|
-
public systems: SystemType<System>[] = [MoveAndBounceSystem];
|
|
134
|
-
|
|
135
|
-
public loadAssets(): void {
|
|
134
|
+
loadAssets(): void {
|
|
136
135
|
this.assetManager.loadImage("logo.png");
|
|
137
136
|
}
|
|
137
|
+
|
|
138
|
+
// within this method we load the systems of the scene
|
|
139
|
+
loadSystems(): void {
|
|
140
|
+
this.systems.push(MoveAndBounceSystem);
|
|
141
|
+
}
|
|
138
142
|
}
|
|
139
143
|
```
|
|
140
144
|
|
|
141
145
|
### Create the entities
|
|
142
146
|
|
|
143
|
-
Finally, we need to create two entities, one that represents our logo, to which we want to apply the behavior of moving and bouncing, and another one that represents the camera of our game. For
|
|
147
|
+
Finally, we need to create two entities, one that represents our logo, to which we want to apply the behavior of moving and bouncing, and another one that represents the camera of our game. For this we will use the `EntityManager`, specifically the `createEntity` method. This method accepts an array of components, the components can be concrete instances (this is useful when it is necessary to pass parameters by constructor) or classes (if it is not necessary to pass parameters by constructor, we can pass only the class).
|
|
144
148
|
|
|
145
149
|
```typescript
|
|
146
150
|
import { Camera, Scene, SpriteRenderer, Transform } from "angry-pixel";
|
|
147
151
|
|
|
148
152
|
class MainScene extends Scene {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
public loadAssets(): void {
|
|
153
|
+
loadAssets(): void {
|
|
152
154
|
this.assetManager.loadImage("logo.png");
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
loadSystems(): void {
|
|
158
|
+
this.systems.push(MoveAndBounceSystem);
|
|
159
|
+
}
|
|
160
|
+
|
|
155
161
|
// within this method we create the entities
|
|
156
|
-
|
|
162
|
+
setup(): void {
|
|
157
163
|
// camera
|
|
158
|
-
|
|
159
|
-
this.entityManager.createEntity(camera);
|
|
164
|
+
this.entityManager.createEntity([new Transform(), new Camera({ layers: ["Logo"] })]);
|
|
160
165
|
|
|
161
166
|
// logo
|
|
162
|
-
|
|
163
|
-
Transform,
|
|
164
|
-
MoveAndBounce,
|
|
167
|
+
this.entityManager.createEntity([
|
|
168
|
+
new Transform(),
|
|
169
|
+
new MoveAndBounce(),
|
|
165
170
|
new SpriteRenderer({
|
|
166
171
|
layer: "Logo",
|
|
167
172
|
image: this.assetManager.getImage("logo.png"),
|
|
168
173
|
}),
|
|
169
|
-
];
|
|
170
|
-
this.entityManager.createEntity(logo);
|
|
174
|
+
]);
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
```
|