Skip to content

Commit 6731373

Browse files
committed
Merge branch 'feature/tutorial_update' of https://github.com/Anzumana/phaser into feature/tutorial_update
2 parents 8bf3c83 + 0d7f07f commit 6731373

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

v2/resources/tutorials/02 Making your first game/tutorial.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,18 @@ <h3>The Body and Velocity: A world of physics</h3>
170170

171171
<img src="http://www.photonstorm.com/wp-content/uploads/2013/12/part5.png" alt="part5" width="800" height="600" class="alignnone size-full wp-image-13608" />
172172

173-
The reason for this is that we're not yet testing for collision between the ground and the player. We already told Phaser that our ground and ledges would be immovable. Had we not done that when the player collided with them it would stop for a moment and then everything would have collapsed. This is because unless told otherwise, the ground sprite is a moving physical object (also known as a dynamic body) and when the player hits it, the resulting force of the collision is applied to the ground, therefore, the two bodies exchange their velocities and ground starts falling as well.
174-
173+
The reason for this is that we're not yet testing for collision between the ground and the player. <br>
175174
So to allow the player to collide and take advantage of the physics properties we need to introduce a collision check in the update function:
176-
175+
177176
<pre class="lang:js decode:true " >function update() {
178177

179178
// Collide the player and the stars with the platforms
180179
game.physics.arcade.collide(player, platforms);
181180

182181
}
183182
</pre>
183+
We already told Phaser that our ground and ledges would be immovable. Had we not done that when the player collided with them it would stop for a moment and then everything would have collapsed. This is because unless told otherwise, the ground sprite is a moving physical object (also known as a dynamic body) and when the player hits it, the resulting force of the collision is applied to the ground, therefore, the two bodies exchange their velocities and ground starts falling as well.
184+
184185

185186
The update function is called by the core game loop every frame. The <a href="http://docs.phaser.io/Phaser.Physics.Arcade.html#toc22">Physics.collide</a> function is the one that performs the magic. It takes two objects and tests for collision and performs separation against them. In this case we're giving it the player sprite and the platforms Group. It's clever enough to run collision against all Group members, so this one call will collide against the ground and both ledges. The result is a firm platform:
186187

0 commit comments

Comments
 (0)