-
Notifications
You must be signed in to change notification settings - Fork 0
/
index01.js
executable file
·50 lines (39 loc) · 1.52 KB
/
index01.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* This example show how to load complex shapes created with PhysicsEditor (https://www.codeandweb.com/physicseditor)
*/
var config = {
type: Phaser.AUTO,
width: 1200,
height: 960,
parent: 'game',
scene: {
preload: preload,
create: create
},
physics: {
default: "matter",
matter: {
debug: true
}
}
};
var game = new Phaser.Game(config);
function preload() {
// Load sprite sheet generated with TexturePacker
this.load.atlas('sheet', 'assets/fruit-sprites.png', 'assets/fruit-sprites.json');
// Load body shapes from JSON file generated using PhysicsEditor
this.load.json('shapes', 'assets/fruit-shapes.json');
}
function create() {
var shapes = this.cache.json.get('shapes');
this.matter.world.setBounds(0, 0, game.config.width, game.config.height);
this.add.image(0, 0, 'sheet', 'background').setOrigin(0, 0);
// sprites are positioned at their center of mass
var ground = this.matter.add.sprite(0, 0, 'sheet', 'ground', {shape: shapes.ground});
ground.setPosition(0 + ground.centerOfMass.x, 280 + ground.centerOfMass.y); // corrected position: (0,280)
this.matter.add.sprite(200, 50, 'sheet', 'crate', {shape: shapes.crate});
this.matter.add.sprite(250, 250, 'sheet', 'banana', {shape: shapes.banana});
this.matter.add.sprite(360, 50, 'sheet', 'orange', {shape: shapes.orange});
this.matter.add.sprite(400, 250, 'sheet', 'cherries', {shape: shapes.cherries});
this.matter.add.mouseSpring();
}