canvasengine 1.3.0 → 2.0.0-beta.2
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/package.json +51 -17
- package/src/components/Canvas.ts +134 -0
- package/src/components/Container.ts +46 -0
- package/src/components/DisplayObject.ts +458 -0
- package/src/components/DrawMap/index.ts +65 -0
- package/src/components/Graphic.ts +147 -0
- package/src/components/NineSliceSprite.ts +46 -0
- package/src/components/ParticleEmitter.ts +39 -0
- package/src/components/Scene.ts +6 -0
- package/src/components/Sprite.ts +493 -0
- package/src/components/Text.ts +145 -0
- package/src/components/Tilemap/Tile.ts +79 -0
- package/src/components/Tilemap/TileGroup.ts +207 -0
- package/src/components/Tilemap/TileLayer.ts +163 -0
- package/src/components/Tilemap/TileSet.ts +41 -0
- package/src/components/Tilemap/index.ts +80 -0
- package/src/components/TilingSprite.ts +39 -0
- package/src/components/Viewport.ts +159 -0
- package/src/components/index.ts +13 -0
- package/src/components/types/DisplayObject.ts +69 -0
- package/src/components/types/MouseEvent.ts +3 -0
- package/src/components/types/Spritesheet.ts +389 -0
- package/src/components/types/index.ts +4 -0
- package/src/directives/Drag.ts +84 -0
- package/src/directives/KeyboardControls.ts +922 -0
- package/src/directives/Scheduler.ts +101 -0
- package/src/directives/Sound.ts +91 -0
- package/src/directives/Transition.ts +45 -0
- package/src/directives/ViewportCull.ts +40 -0
- package/src/directives/ViewportFollow.ts +26 -0
- package/src/directives/index.ts +7 -0
- package/src/engine/animation.ts +113 -0
- package/src/engine/bootstrap.ts +19 -0
- package/src/engine/directive.ts +23 -0
- package/src/engine/reactive.ts +379 -0
- package/src/engine/signal.ts +138 -0
- package/src/engine/trigger.ts +40 -0
- package/src/engine/utils.ts +135 -0
- package/src/hooks/addContext.ts +6 -0
- package/src/hooks/useProps.ts +155 -0
- package/src/hooks/useRef.ts +21 -0
- package/src/index.ts +13 -0
- package/src/utils/Ease.ts +33 -0
- package/src/utils/RadialGradient.ts +86 -0
- package/.gitattributes +0 -22
- package/.npmignore +0 -163
- package/canvasengine-1.3.0.all.min.js +0 -21
- package/canvasengine.js +0 -5802
- package/core/DB.js +0 -24
- package/core/ModelServer.js +0 -348
- package/core/Users.js +0 -190
- package/core/engine-common.js +0 -952
- package/doc/cocoonjs.md +0 -36
- package/doc/doc-lang.yml +0 -43
- package/doc/doc-router.yml +0 -14
- package/doc/doc-tuto.yml +0 -9
- package/doc/doc.yml +0 -39
- package/doc/element.md +0 -37
- package/doc/entity.md +0 -90
- package/doc/extend.md +0 -47
- package/doc/get_started.md +0 -19
- package/doc/images/entity.png +0 -0
- package/doc/multitouch.md +0 -58
- package/doc/nodejs.md +0 -142
- package/doc/scene.md +0 -44
- package/doc/text.md +0 -156
- package/examples/server/client.html +0 -31
- package/examples/server/server.js +0 -16
- package/examples/tiled_server/client.html +0 -52
- package/examples/tiled_server/images/tiles_spritesheet.png +0 -0
- package/examples/tiled_server/server/map.json +0 -50
- package/examples/tiled_server/server/map.tmx +0 -16
- package/examples/tiled_server/server/server.js +0 -16
- package/extends/Animation.js +0 -910
- package/extends/Effect.js +0 -252
- package/extends/Gleed2d.js +0 -252
- package/extends/Hit.js +0 -1509
- package/extends/Input.js +0 -699
- package/extends/Marshal.js +0 -716
- package/extends/Scrolling.js +0 -388
- package/extends/Soundmanager2.js +0 -5466
- package/extends/Spritesheet.js +0 -196
- package/extends/Text.js +0 -366
- package/extends/Tiled.js +0 -403
- package/extends/Window.js +0 -575
- package/extends/gamepad.js +0 -397
- package/extends/socket.io.min.js +0 -2
- package/extends/swf/soundmanager2.swf +0 -0
- package/extends/swf/soundmanager2_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash9.swf +0 -0
- package/extends/swf/soundmanager2_flash9_debug.swf +0 -0
- package/extends/swf/soundmanager2_flash_xdomain.zip +0 -0
- package/extends/workers/transition.js +0 -43
- package/index.js +0 -46
- package/license.txt +0 -19
- package/readme.md +0 -483
package/doc/cocoonjs.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Export natively game on iOS and Android
|
|
2
|
-
|
|
3
|
-
CocoonJS technology allows you to export your game natively on iOS and Android and accelerate the performance of HTML5 Canvas
|
|
4
|
-
|
|
5
|
-
You explanations on the following link : [Documentation](http://wiki.ludei.com/).
|
|
6
|
-
|
|
7
|
-
## Use with Canvas Engine
|
|
8
|
-
|
|
9
|
-
Create a file `index.html` including the lastest version of Canvas Engine :
|
|
10
|
-
|
|
11
|
-
<!DOCTYPE html>
|
|
12
|
-
<script src="js/canvasengine-X.Y.Z.all.min.js"></script>
|
|
13
|
-
<script src="js/main.js"></script>
|
|
14
|
-
|
|
15
|
-
* The main code of your game is in `main.js`
|
|
16
|
-
* It is normal not to have the `canvas` tag in HTML
|
|
17
|
-
|
|
18
|
-
During initialization of the canvas (in `main.js`), use the property `cocoonjs` and specify the width and height:
|
|
19
|
-
|
|
20
|
-
var canvas = CE.defines("canvas_id", {
|
|
21
|
-
cocoonjs: {width: 640, height: 480}
|
|
22
|
-
}).
|
|
23
|
-
ready(function() {
|
|
24
|
-
// start game
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## Start using CocoonJS
|
|
29
|
-
The best way to start using CocoonJS is by following these easy steps:
|
|
30
|
-
|
|
31
|
-
1. Download the CocoonJS Launcher App to your device (iOS or Android). Read how to install and use it for each platform.
|
|
32
|
-
2. [Register as a CocoonJS developer](http://cocoonjsservice.ludei.com/cocoonjslaunchersvr/). It is a very simple process and you will get a registration code that will grant you access to the launcher and the cloud compilation system as well.
|
|
33
|
-
3. Try your application in the CocoonJS Launcher App to see how it runs. Check if CocoonJS supports all your code, and check the messages in our debug console. You can either ZIP you application and upload it to the launcher or access the same ZIP file through a URL to a web service. The CocoonJS Launcher App also allows you to access your application directly from a remote URL, so you can also specify the URL to the folder where your code is or to the common index.html file. Check the CocoonJS Launcher App tutorial for more information.
|
|
34
|
-
4. Once you see that your application runs correctly in the CocoonJS Launcher App, go to our Cloud Compilation System to get the final files that you will be able to upload to the markets.
|
|
35
|
-
|
|
36
|
-
> Source : [Documentation](http://wiki.ludei.com/)
|
package/doc/doc-lang.yml
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
engine: Engine
|
|
2
|
-
core: Core
|
|
3
|
-
editor: Editors
|
|
4
|
-
|
|
5
|
-
element: Element
|
|
6
|
-
canvas: Canvas
|
|
7
|
-
scene: Scene
|
|
8
|
-
server: Server
|
|
9
|
-
traversing: Traversing
|
|
10
|
-
draw: Draw
|
|
11
|
-
manipulate: Manipulate
|
|
12
|
-
events: Events
|
|
13
|
-
materials: Materials
|
|
14
|
-
sound: Sound
|
|
15
|
-
extends: Extends
|
|
16
|
-
utilities: Utilities
|
|
17
|
-
class: Class
|
|
18
|
-
ajax: Ajax
|
|
19
|
-
|
|
20
|
-
animation: Animation
|
|
21
|
-
spritesheet: SpriteSheet
|
|
22
|
-
timeline: Timeline
|
|
23
|
-
scrolling: Scrolling
|
|
24
|
-
save: Save/Load
|
|
25
|
-
input: Input
|
|
26
|
-
collision: Collision
|
|
27
|
-
box: Window
|
|
28
|
-
text: Text
|
|
29
|
-
effect: Effect
|
|
30
|
-
|
|
31
|
-
hit: Entity
|
|
32
|
-
entity: Entity Model
|
|
33
|
-
grid: Grid
|
|
34
|
-
|
|
35
|
-
keyboard: Keyboard
|
|
36
|
-
gamepad: Gamepad
|
|
37
|
-
accelerometer: Accelerometer
|
|
38
|
-
|
|
39
|
-
window: Dialog Box
|
|
40
|
-
cursor: Cursor
|
|
41
|
-
|
|
42
|
-
tiled: Tiled Map Editor
|
|
43
|
-
gleed2d: Gleed2D
|
package/doc/doc-router.yml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
- canvasengine.js
|
|
2
|
-
- core/engine-common.js
|
|
3
|
-
- core/ModelServer.js
|
|
4
|
-
- extends/Animation.js
|
|
5
|
-
- extends/Gleed2d.js
|
|
6
|
-
- extends/Input.js
|
|
7
|
-
- extends/Marshal.js
|
|
8
|
-
- extends/Scrolling.js
|
|
9
|
-
- extends/Spritesheet.js
|
|
10
|
-
- extends/Tiled.js
|
|
11
|
-
- extends/Hit.js
|
|
12
|
-
- extends/Window.js
|
|
13
|
-
- extends/Text.js
|
|
14
|
-
- extends/Effect.js
|
package/doc/doc-tuto.yml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
- get_started: Get Started
|
|
2
|
-
- scene: Create Scene
|
|
3
|
-
- element: Create Element
|
|
4
|
-
- extend: Extend Features
|
|
5
|
-
- entity: Collision and Entities
|
|
6
|
-
- text: Text and fonts
|
|
7
|
-
- multitouch: MultiTouch with Hammer.js
|
|
8
|
-
- nodejs: Multiplayer Model
|
|
9
|
-
- cocoonjs: Export natively
|
package/doc/doc.yml
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
core:
|
|
2
|
-
class:
|
|
3
|
-
engine:
|
|
4
|
-
server:
|
|
5
|
-
scene:
|
|
6
|
-
canvas:
|
|
7
|
-
element:
|
|
8
|
-
traversing:
|
|
9
|
-
draw:
|
|
10
|
-
manipulate:
|
|
11
|
-
events:
|
|
12
|
-
materials:
|
|
13
|
-
sound:
|
|
14
|
-
ajax:
|
|
15
|
-
utilities:
|
|
16
|
-
|
|
17
|
-
extends:
|
|
18
|
-
animation:
|
|
19
|
-
timeline:
|
|
20
|
-
spritesheet:
|
|
21
|
-
scrolling:
|
|
22
|
-
collision:
|
|
23
|
-
hit:
|
|
24
|
-
entity:
|
|
25
|
-
grid:
|
|
26
|
-
save:
|
|
27
|
-
input:
|
|
28
|
-
keyboard:
|
|
29
|
-
gamepad:
|
|
30
|
-
accelerometer:
|
|
31
|
-
box:
|
|
32
|
-
window:
|
|
33
|
-
cursor:
|
|
34
|
-
text:
|
|
35
|
-
effect:
|
|
36
|
-
|
|
37
|
-
editor:
|
|
38
|
-
tiled:
|
|
39
|
-
gleed2d:
|
package/doc/element.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Create an element
|
|
2
|
-
|
|
3
|
-
Elements are created in the scene :
|
|
4
|
-
|
|
5
|
-
var canvas = CE.defines("canvas_id").
|
|
6
|
-
ready(function() {
|
|
7
|
-
canvas.Scene.call("MyScene");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
canvas.Scene.new({
|
|
11
|
-
name: "MyScene", // Obligatory
|
|
12
|
-
materials: {
|
|
13
|
-
images: {
|
|
14
|
-
img_id: "path/to/img.png"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
ready: function(stage) {
|
|
18
|
-
this.element = this.createElement();
|
|
19
|
-
this.element.drawImage("img_id");
|
|
20
|
-
stage.append(this.element);
|
|
21
|
-
},
|
|
22
|
-
render: function(stage) {
|
|
23
|
-
this.element.x += 1;
|
|
24
|
-
stage.refresh();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
In the `ready` method :
|
|
29
|
-
|
|
30
|
-
1. We create an element with the `createElement` method of this scene
|
|
31
|
-
2. `drawImage` method displays an image in the element. We assign the identifier of preloaded image of the `materials` property
|
|
32
|
-
3. We add to the `append` method in the main element
|
|
33
|
-
|
|
34
|
-
In the `render` method :
|
|
35
|
-
|
|
36
|
-
1. We manipulate the element (here, we move it `x`)
|
|
37
|
-
2. We refresh the main element (`stage`) with the `refresh` method
|
package/doc/entity.md
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# Collision and Entities
|
|
2
|
-
|
|
3
|
-
You must distinguish between entity and element but if the concept is very similar.
|
|
4
|
-
|
|
5
|
-
* Element for the visual.
|
|
6
|
-
* An entity is only used to calculate the positions or collisions in the background
|
|
7
|
-
|
|
8
|
-

|
|
9
|
-
|
|
10
|
-
1. The entity called model to know the positions or collisions
|
|
11
|
-
2. Model returns the data
|
|
12
|
-
3. The entity displays the element based on the data model
|
|
13
|
-
|
|
14
|
-
## Code ##
|
|
15
|
-
|
|
16
|
-
First, initialize
|
|
17
|
-
|
|
18
|
-
var canvas = CE.defines("canvas_id").
|
|
19
|
-
extend(Hit).
|
|
20
|
-
ready(function() {
|
|
21
|
-
canvas.Scene.call("MyScene");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
Create the scene :
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
canvas.Scene.new({
|
|
28
|
-
name: "MyScene",
|
|
29
|
-
ready: function(stage) {
|
|
30
|
-
|
|
31
|
-
function addEntities(x, y) {
|
|
32
|
-
var entity = Class.New("Entity", [stage]);
|
|
33
|
-
entity.rect(100); // square
|
|
34
|
-
entity.position(x, y);
|
|
35
|
-
entity.el.fillStyle = "red";
|
|
36
|
-
entity.el.fillRect(0, 0, 100, 100);
|
|
37
|
-
stage.append(entity.el);
|
|
38
|
-
return entity;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.entityA = addEntities(0, 10);
|
|
42
|
-
this.entityB = addEntities(300, 10);
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
render: function(stage) {
|
|
46
|
-
this.entityA.move(5); // x += 5;
|
|
47
|
-
this.entityA.hit([this.entityB], function(state, el) {
|
|
48
|
-
if (state == "over") {
|
|
49
|
-
el.fillStyle = "green";
|
|
50
|
-
el.fillRect(0, 0, 100, 100);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
stage.refresh();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
1. Create an entity (#1 on the diagram)
|
|
58
|
-
|
|
59
|
-
Class.New("Entity", [stage]);
|
|
60
|
-
|
|
61
|
-
2. Assign it a polygon (here, a square 100px)
|
|
62
|
-
|
|
63
|
-
entity.rect(100);
|
|
64
|
-
|
|
65
|
-
3. Assign him his position
|
|
66
|
-
|
|
67
|
-
entity.position(x, y);
|
|
68
|
-
|
|
69
|
-
4. Change its appearance (element) and place it on the stage
|
|
70
|
-
|
|
71
|
-
entity.el.fillStyle = "red";
|
|
72
|
-
entity.el.fillRect(0, 0, 100, 100);
|
|
73
|
-
stage.append(entity.el);
|
|
74
|
-
|
|
75
|
-
In the `render` method :
|
|
76
|
-
|
|
77
|
-
1. Moving entity 5px in the right
|
|
78
|
-
|
|
79
|
-
this.entityA.move(5);
|
|
80
|
-
|
|
81
|
-
2. Test the collision between two entities.
|
|
82
|
-
|
|
83
|
-
this.entityA.hit([this.entityB], function(state, el) {
|
|
84
|
-
if (state == "over") {
|
|
85
|
-
el.fillStyle = "green";
|
|
86
|
-
el.fillRect(0, 0, 100, 100);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
> You also have to test `out` if the entity is no longer in collision
|
package/doc/extend.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Extend Canvas Engine
|
|
2
|
-
|
|
3
|
-
Canvas Engine can be extended to have more features :
|
|
4
|
-
|
|
5
|
-
var canvas = CE.defines("canvas_id").
|
|
6
|
-
extend(Input).
|
|
7
|
-
ready(function() {
|
|
8
|
-
canvas.Scene.call("MyScene");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
canvas.Scene.new({
|
|
12
|
-
name: "MyScene", // Obligatory
|
|
13
|
-
ready: function(stage) {
|
|
14
|
-
canvas.Input.keyDown(Input.A, function(e) {
|
|
15
|
-
console.log("A is pressed");
|
|
16
|
-
});
|
|
17
|
-
},
|
|
18
|
-
render: function(stage) {
|
|
19
|
-
stage.refresh();
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
1. Use the `extend` method to add class. If multiple, create a chain :
|
|
25
|
-
|
|
26
|
-
var canvas = CE.defines("canvas_id").
|
|
27
|
-
extend(Input).
|
|
28
|
-
extend(Animation).
|
|
29
|
-
ready(function() {
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
2. If the class is not static, use the initialized variable (`canvas` here) and the name of the class then
|
|
34
|
-
3. In the menu of this documentation, click functionality extended to read more details on its use
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
> Note: For editors, add the JS file, presents in the folder `extends`, in your page
|
|
39
|
-
|
|
40
|
-
<script src="extends/Tiled.js"></script>
|
|
41
|
-
<script>
|
|
42
|
-
var canvas = CE.defines("canvas_id").
|
|
43
|
-
extend(Tiled).
|
|
44
|
-
ready(function() {
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
</script>
|
package/doc/get_started.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Get Started
|
|
2
|
-
|
|
3
|
-
Follow the steps below to start:
|
|
4
|
-
|
|
5
|
-
1. Download the code `canvasengine-X.Y.Z.all.min.js` on Github or this website
|
|
6
|
-
2. Add this code in your page :
|
|
7
|
-
|
|
8
|
-
<!DOCTYPE html>
|
|
9
|
-
<script src="canvasengine-X.Y.Z.all.min.js"></script>
|
|
10
|
-
<canvas id="canvas_id" width="640" height="480"></canvas>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
3. Initialize the canvas in your JS file :
|
|
14
|
-
|
|
15
|
-
var canvas = CE.defines("canvas_id").ready(function() {
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
Method `ready` is called when the canvas is ready (DOM loaded)
|
package/doc/images/entity.png
DELETED
|
Binary file
|
package/doc/multitouch.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# MultiTouch with Hammer.js #
|
|
2
|
-
|
|
3
|
-
HammerJS is a javascript library for multi-touch gestures : http://eightmedia.github.com/hammer.js
|
|
4
|
-
|
|
5
|
-
It has been implemented in CanvasEngine for a greater experience of touchpads and smartphones
|
|
6
|
-
|
|
7
|
-
The use is very simple, you must use the method `on` an element
|
|
8
|
-
|
|
9
|
-
var el = this.createElement();
|
|
10
|
-
el.fillStyle = "red";
|
|
11
|
-
el.fillRect(0, 0, 100, 100);
|
|
12
|
-
|
|
13
|
-
el.on("drag", function(e, mouse) {
|
|
14
|
-
console.log("is drag");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
Of course, this code is in the `ready` method of scene. Here, when the element is moved with the mouse, the callback function is called
|
|
18
|
-
|
|
19
|
-
Here are all the possibilities :
|
|
20
|
-
|
|
21
|
-
* hold
|
|
22
|
-
* tap
|
|
23
|
-
* doubletap
|
|
24
|
-
* drag, dragstart, dragend, dragup, dragdown, dragleft, dragright
|
|
25
|
-
* swipe, swipeup, swipedown, swipeleft, swiperight
|
|
26
|
-
* transform, transformstart, transformend
|
|
27
|
-
* rotate
|
|
28
|
-
* pinch, pinchin, pinchout
|
|
29
|
-
* touch (gesture detection starts)
|
|
30
|
-
* release (gesture detection ends)
|
|
31
|
-
|
|
32
|
-
> Notice that `touch` is equivalent to the `click` event
|
|
33
|
-
|
|
34
|
-
See [https://github.com/EightMedia/hammer.js/wiki/Getting-Started](https://github.com/EightMedia/hammer.js/wiki/Getting-Started)
|
|
35
|
-
|
|
36
|
-
## Full example ##
|
|
37
|
-
|
|
38
|
-
var canvas = CE.defines("canvas_id").
|
|
39
|
-
ready(function() {
|
|
40
|
-
canvas.Scene.call("MyScene");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
canvas.Scene.new({
|
|
44
|
-
name: "MyScene",
|
|
45
|
-
ready: function(stage) {
|
|
46
|
-
|
|
47
|
-
var el = this.createElement();
|
|
48
|
-
el.fillStyle = "red";
|
|
49
|
-
el.fillRect(0, 0, 100, 100);
|
|
50
|
-
|
|
51
|
-
el.on("dragright", function(e, mouse) {
|
|
52
|
-
this.x = e.gesture.deltaX;
|
|
53
|
-
this.y = e.gesture.deltaY;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
stage.append(el);
|
|
57
|
-
}
|
|
58
|
-
});
|
package/doc/nodejs.md
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# Multiplayer
|
|
2
|
-
|
|
3
|
-
CanvasEngine implements a multiplayer game using NodeJS and Socket.io
|
|
4
|
-
|
|
5
|
-
1. Install [Node.js](http://nodejs.org) and [NPM](https://npmjs.org/)
|
|
6
|
-
2. Open the Shell :
|
|
7
|
-
|
|
8
|
-
npm install canvasengine
|
|
9
|
-
|
|
10
|
-
3. Create a. Js file in your project for the server
|
|
11
|
-
|
|
12
|
-
## Example
|
|
13
|
-
|
|
14
|
-
Here is an example of a client code :
|
|
15
|
-
|
|
16
|
-
<!DOCTYPE html>
|
|
17
|
-
<html>
|
|
18
|
-
<head>
|
|
19
|
-
<script src="canvasengine-X.Y.Z.all.min.js"></script>
|
|
20
|
-
<script src="extends/Socket.js"></script>
|
|
21
|
-
|
|
22
|
-
<script>
|
|
23
|
-
var canvas = CE.defines("canvas").
|
|
24
|
-
ready(function() {
|
|
25
|
-
canvas.Scene.call("MyScene");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
canvas.Scene.new({
|
|
29
|
-
name: "MyScene",
|
|
30
|
-
events: ["load"],
|
|
31
|
-
ready: function(stage) {
|
|
32
|
-
CE.connectServer('http://127.0.0.1', 8333);
|
|
33
|
-
this.loadEvents();
|
|
34
|
-
CE.io.emit("load");
|
|
35
|
-
},
|
|
36
|
-
load: function(text) {
|
|
37
|
-
console.log(text);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
</script>
|
|
42
|
-
</head>
|
|
43
|
-
<body>
|
|
44
|
-
<canvas id="canvas" width="675px" height="506px"></canvas>
|
|
45
|
-
</body>
|
|
46
|
-
</html>
|
|
47
|
-
|
|
48
|
-
And server code :
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var CE = require("canvasengine").listen(8333);
|
|
52
|
-
CE.Model.init("Main", ["start"], {
|
|
53
|
-
|
|
54
|
-
initialize: function(socket) {
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
start: function() {
|
|
58
|
-
this.socket.emit("MyScene.load", "Hello");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
1. We make a connection with `connectServer()` method
|
|
64
|
-
2. Since the scene is already loaded and the connection after, load events with
|
|
65
|
-
1. The client sends data to the server with the `emit` of `CE.io` property `loadEvents()`. If we connect before the opening of the scene, no need to call this method:
|
|
66
|
-
|
|
67
|
-
CE.connectServer('http://127.0.0.1', 8333);
|
|
68
|
-
|
|
69
|
-
canvas.Scene.new({
|
|
70
|
-
name: "MyScene",
|
|
71
|
-
events: ["load"],
|
|
72
|
-
ready: function(stage) {
|
|
73
|
-
CE.io.emit("load");
|
|
74
|
-
},
|
|
75
|
-
load: function(text) {
|
|
76
|
-
console.log(text);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
3. Conversely, data is sent to the scene with the `emit` method `CE.Core.io` property. Note that you can call methods of a particular scene, by prefixing the name of the event by the name of the scene
|
|
82
|
-
4. Here, the `load` method is executed and defined in the `events` property
|
|
83
|
-
|
|
84
|
-
> `CE.io` and `CE.Core.io` methods are the same as Socket.io
|
|
85
|
-
|
|
86
|
-
## Create a module
|
|
87
|
-
|
|
88
|
-
Server side, create a JS file
|
|
89
|
-
|
|
90
|
-
var CE = require("canvasengine").listen(),
|
|
91
|
-
Class = CE.Class;
|
|
92
|
-
|
|
93
|
-
CE.Model.create("Player", ["start"], {
|
|
94
|
-
|
|
95
|
-
initialize: function(user_id, username) {
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
start: function() {
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
exports.New = function(socket, user_id, username) {
|
|
106
|
-
return CE.Model.new("Player", [user_id, username], socket);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
1. Load CanvasEngine. No need to put the port.
|
|
110
|
-
2. Create a class with events
|
|
111
|
-
3. The function of `export.New()` created a new instance of the `Player` class with two parameters.
|
|
112
|
-
4. The socket parameter is essential if you want the user invokes events class. Because here we have a player, we assign the socket of the user class
|
|
113
|
-
|
|
114
|
-
Our main class :
|
|
115
|
-
|
|
116
|
-
var CE = require("canvasengine").listen(8333),
|
|
117
|
-
Class = CE.Class;
|
|
118
|
-
|
|
119
|
-
CE.Model.init("Main", {
|
|
120
|
-
|
|
121
|
-
initialize: function(socket) {
|
|
122
|
-
var player = require("./player").New(1, "Foo", socket);
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
If the class is common to all the world (a map by example)
|
|
128
|
-
|
|
129
|
-
var Map = require("./map").New(null); // socket is null. It indicates that not assign an event to sockets
|
|
130
|
-
|
|
131
|
-
CE.Model.init("Main", {
|
|
132
|
-
|
|
133
|
-
enterMap: function() {
|
|
134
|
-
CE.Model.assignEvents(Map, this.socket);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
Here we take into account that the `Map` object is global. In addition, it refers to a previously instantiated class (not written in the code above, imagine). Since the class has already been instantiated, we assign events to the user of the class when he gets on the map
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
package/doc/scene.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Create a scene
|
|
2
|
-
|
|
3
|
-
Scenes can prepare the elements and display them on the screen
|
|
4
|
-
|
|
5
|
-
var canvas = CE.defines("canvas_id").
|
|
6
|
-
ready(function() {
|
|
7
|
-
canvas.Scene.call("MyScene");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
canvas.Scene.new({
|
|
11
|
-
name: "MyScene", // Obligatory
|
|
12
|
-
materials: {
|
|
13
|
-
images: {
|
|
14
|
-
img_id: "path/to/img.png"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
preload: function(stage, pourcent) {
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
ready: function(stage) {
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
render: function(stage) {
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
exit: function(stage) {
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
The scene is composed of several methods. All methods are optional.
|
|
32
|
-
|
|
33
|
-
* `preload` : Method called at each resource loaded in the `materials` property
|
|
34
|
-
* `ready`: Method called when resources are loaded
|
|
35
|
-
* `render` : Method called at each render (60 FPS)
|
|
36
|
-
* `exit` :Method called when this scene is quitted (or another scene is called)
|
|
37
|
-
|
|
38
|
-
To call the scene:
|
|
39
|
-
|
|
40
|
-
canvas.Scene.call("MyScene");
|
|
41
|
-
|
|
42
|
-
The name of the scene is set in the `name` parameter.
|
|
43
|
-
|
|
44
|
-
The `stage` parameter is the main element. Child elements will be added to the `stage` element
|