Skip to content

Commit 6651f6c

Browse files
committed
Tutorial updated for Phaser 2
1 parent 7eee1ea commit 6651f6c

11 files changed

Lines changed: 125 additions & 39 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ Beyond version 2.2
327327
* DragonBones support.
328328
* Cache to localStorage using If-Modified-Since. [See github request](https://github.com/photonstorm/phaser/issues/495)
329329
* Allow for complex assets like Bitmap Fonts to be stored within a texture atlas.
330+
* Look at XDomainRequest for IE9 CORs issues.
330331

331332

332333
Nadion

tutorials/02 Making your first game/js/phaser.min.js

Lines changed: 22 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tutorials/02 Making your first game/part4.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@
2929

3030
function create() {
3131

32+
// We're going to be using physics, so enable the Arcade Physics system
33+
game.physics.startSystem(Phaser.Physics.ARCADE);
34+
3235
// A simple background for our game
3336
game.add.sprite(0, 0, 'sky');
3437

3538
// The platforms group contains the ground and the 2 ledges we can jump on
3639
platforms = game.add.group();
3740

41+
// We will enable physics for any object that is created in this group
42+
platforms.enableBody = true;
43+
3844
// Here we create the ground.
3945
var ground = platforms.create(0, game.world.height - 64, 'ground');
4046

@@ -46,9 +52,11 @@
4652

4753
// Now let's create two ledges
4854
var ledge = platforms.create(400, 400, 'ground');
55+
4956
ledge.body.immovable = true;
5057

5158
ledge = platforms.create(-150, 250, 'ground');
59+
5260
ledge.body.immovable = true;
5361

5462
}

tutorials/02 Making your first game/part5.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@
2929

3030
function create() {
3131

32+
// We're going to be using physics, so enable the Arcade Physics system
33+
game.physics.startSystem(Phaser.Physics.ARCADE);
34+
3235
// A simple background for our game
3336
game.add.sprite(0, 0, 'sky');
3437

3538
// The platforms group contains the ground and the 2 ledges we can jump on
3639
platforms = game.add.group();
3740

41+
// We will enable physics for any object that is created in this group
42+
platforms.enableBody = true;
43+
3844
// Here we create the ground.
3945
var ground = platforms.create(0, game.world.height - 64, 'ground');
4046

@@ -54,9 +60,12 @@
5460
// The player and its settings
5561
player = game.add.sprite(32, game.world.height - 150, 'dude');
5662

63+
// We need to enable physics on the player
64+
game.physics.arcade.enable(player);
65+
5766
// Player physics properties. Give the little guy a slight bounce.
5867
player.body.bounce.y = 0.2;
59-
player.body.gravity.y = 6;
68+
player.body.gravity.y = 300;
6069
player.body.collideWorldBounds = true;
6170

6271
// Our two animations, walking left and right.

tutorials/02 Making your first game/part6.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@
3030

3131
function create() {
3232

33+
// We're going to be using physics, so enable the Arcade Physics system
34+
game.physics.startSystem(Phaser.Physics.ARCADE);
35+
3336
// A simple background for our game
3437
game.add.sprite(0, 0, 'sky');
3538

3639
// The platforms group contains the ground and the 2 ledges we can jump on
3740
platforms = game.add.group();
3841

42+
// We will enable physics for any object that is created in this group
43+
platforms.enableBody = true;
44+
3945
// Here we create the ground.
4046
var ground = platforms.create(0, game.world.height - 64, 'ground');
4147

@@ -55,9 +61,12 @@
5561
// The player and its settings
5662
player = game.add.sprite(32, game.world.height - 150, 'dude');
5763

64+
// We need to enable physics on the player
65+
game.physics.arcade.enable(player);
66+
5867
// Player physics properties. Give the little guy a slight bounce.
5968
player.body.bounce.y = 0.2;
60-
player.body.gravity.y = 6;
69+
player.body.gravity.y = 300;
6170
player.body.collideWorldBounds = true;
6271

6372
// Our two animations, walking left and right.
@@ -69,7 +78,7 @@
6978
function update() {
7079

7180
// Collide the player and the stars with the platforms
72-
game.physics.collide(player, platforms);
81+
game.physics.arcade.collide(player, platforms);
7382

7483
}
7584

tutorials/02 Making your first game/part7.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@
3131

3232
function create() {
3333

34+
// We're going to be using physics, so enable the Arcade Physics system
35+
game.physics.startSystem(Phaser.Physics.ARCADE);
36+
3437
// A simple background for our game
3538
game.add.sprite(0, 0, 'sky');
3639

3740
// The platforms group contains the ground and the 2 ledges we can jump on
3841
platforms = game.add.group();
3942

43+
// We will enable physics for any object that is created in this group
44+
platforms.enableBody = true;
45+
4046
// Here we create the ground.
4147
var ground = platforms.create(0, game.world.height - 64, 'ground');
4248

@@ -56,9 +62,12 @@
5662
// The player and its settings
5763
player = game.add.sprite(32, game.world.height - 150, 'dude');
5864

65+
// We need to enable physics on the player
66+
game.physics.arcade.enable(player);
67+
5968
// Player physics properties. Give the little guy a slight bounce.
6069
player.body.bounce.y = 0.2;
61-
player.body.gravity.y = 6;
70+
player.body.gravity.y = 300;
6271
player.body.collideWorldBounds = true;
6372

6473
// Our two animations, walking left and right.
@@ -73,7 +82,7 @@
7382
function update() {
7483

7584
// Collide the player and the stars with the platforms
76-
game.physics.collide(player, platforms);
85+
game.physics.arcade.collide(player, platforms);
7786

7887
// Reset the players velocity (movement)
7988
player.body.velocity.x = 0;

tutorials/02 Making your first game/part8.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@
3333

3434
function create() {
3535

36+
// We're going to be using physics, so enable the Arcade Physics system
37+
game.physics.startSystem(Phaser.Physics.ARCADE);
38+
3639
// A simple background for our game
3740
game.add.sprite(0, 0, 'sky');
3841

3942
// The platforms group contains the ground and the 2 ledges we can jump on
4043
platforms = game.add.group();
4144

45+
// We will enable physics for any object that is created in this group
46+
platforms.enableBody = true;
47+
4248
// Here we create the ground.
4349
var ground = platforms.create(0, game.world.height - 64, 'ground');
4450

@@ -58,9 +64,12 @@
5864
// The player and its settings
5965
player = game.add.sprite(32, game.world.height - 150, 'dude');
6066

67+
// We need to enable physics on the player
68+
game.physics.arcade.enable(player);
69+
6170
// Player physics properties. Give the little guy a slight bounce.
6271
player.body.bounce.y = 0.2;
63-
player.body.gravity.y = 6;
72+
player.body.gravity.y = 300;
6473
player.body.collideWorldBounds = true;
6574

6675
// Our two animations, walking left and right.
@@ -70,14 +79,17 @@
7079
// Finally some stars to collect
7180
stars = game.add.group();
7281

82+
// We will enable physics for any star that is created in this group
83+
stars.enableBody = true;
84+
7385
// Here we'll create 12 of them evenly spaced apart
7486
for (var i = 0; i < 12; i++)
7587
{
7688
// Create a star inside of the 'stars' group
7789
var star = stars.create(i * 70, 0, 'star');
7890

7991
// Let gravity do its thing
80-
star.body.gravity.y = 6;
92+
star.body.gravity.y = 300;
8193

8294
// This just gives each star a slightly random bounce value
8395
star.body.bounce.y = 0.7 + Math.random() * 0.2;
@@ -91,11 +103,11 @@
91103
function update() {
92104

93105
// Collide the player and the stars with the platforms
94-
game.physics.collide(player, platforms);
95-
game.physics.collide(stars, platforms);
106+
game.physics.arcade.collide(player, platforms);
107+
game.physics.arcade.collide(stars, platforms);
96108

97109
// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
98-
game.physics.overlap(player, stars, collectStar, null, this);
110+
game.physics.arcade.overlap(player, stars, collectStar, null, this);
99111

100112
// Reset the players velocity (movement)
101113
player.body.velocity.x = 0;

tutorials/02 Making your first game/part9.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@
3535

3636
function create() {
3737

38+
// We're going to be using physics, so enable the Arcade Physics system
39+
game.physics.startSystem(Phaser.Physics.ARCADE);
40+
3841
// A simple background for our game
3942
game.add.sprite(0, 0, 'sky');
4043

4144
// The platforms group contains the ground and the 2 ledges we can jump on
4245
platforms = game.add.group();
4346

47+
// We will enable physics for any object that is created in this group
48+
platforms.enableBody = true;
49+
4450
// Here we create the ground.
4551
var ground = platforms.create(0, game.world.height - 64, 'ground');
4652

@@ -60,9 +66,12 @@
6066
// The player and its settings
6167
player = game.add.sprite(32, game.world.height - 150, 'dude');
6268

69+
// We need to enable physics on the player
70+
game.physics.arcade.enable(player);
71+
6372
// Player physics properties. Give the little guy a slight bounce.
6473
player.body.bounce.y = 0.2;
65-
player.body.gravity.y = 6;
74+
player.body.gravity.y = 300;
6675
player.body.collideWorldBounds = true;
6776

6877
// Our two animations, walking left and right.
@@ -72,14 +81,17 @@
7281
// Finally some stars to collect
7382
stars = game.add.group();
7483

84+
// We will enable physics for any star that is created in this group
85+
stars.enableBody = true;
86+
7587
// Here we'll create 12 of them evenly spaced apart
7688
for (var i = 0; i < 12; i++)
7789
{
7890
// Create a star inside of the 'stars' group
7991
var star = stars.create(i * 70, 0, 'star');
8092

8193
// Let gravity do its thing
82-
star.body.gravity.y = 6;
94+
star.body.gravity.y = 300;
8395

8496
// This just gives each star a slightly random bounce value
8597
star.body.bounce.y = 0.7 + Math.random() * 0.2;
@@ -96,11 +108,11 @@
96108
function update() {
97109

98110
// Collide the player and the stars with the platforms
99-
game.physics.collide(player, platforms);
100-
game.physics.collide(stars, platforms);
111+
game.physics.arcade.collide(player, platforms);
112+
game.physics.arcade.collide(stars, platforms);
101113

102114
// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
103-
game.physics.overlap(player, stars, collectStar, null, this);
115+
game.physics.arcade.overlap(player, stars, collectStar, null, this);
104116

105117
// Reset the players velocity (movement)
106118
player.body.velocity.x = 0;
@@ -142,7 +154,7 @@
142154

143155
// Add and update the score
144156
score += 10;
145-
scoreText.content = 'Score: ' + score;
157+
scoreText.text = 'Score: ' + score;
146158

147159
}
148160

101 KB
Binary file not shown.
58.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)