Skip to content

Commit 54d9894

Browse files
committed
Mummy attack :)
1 parent e77f5da commit 54d9894

6 files changed

Lines changed: 113 additions & 54 deletions

File tree

examples/sprite2.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,26 @@ function preload() {
2525

2626
function create() {
2727

28-
bunny = game.add.sprite(-40, 100, 'ms');
28+
bunny = game.add.sprite(40, 100, 'ms');
2929

3030
bunny.animations.add('walk');
3131

3232
bunny.animations.play('walk', 50, true);
3333

34-
// bunny.scale.x = 8;
35-
// bunny.scale.y = 8;
36-
3734
game.add.tween(bunny).to({ x: game.width }, 10000, Phaser.Easing.Linear.None, true);
3835

3936
}
4037

38+
// update isn't called until 'create' has completed. If you need to process stuff before that point (i.e. while the preload is still happening)
39+
// then create a function called loadUpdate() and use that
4140
function update() {
42-
bunny.postUpdate();
41+
42+
if (bunny.x >= 300)
43+
{
44+
bunny.scale.x += 0.01;
45+
bunny.scale.y += 0.01;
46+
}
47+
4348
}
4449

4550
})();

examples/sprite3.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
16+
17+
var timer = 0;
18+
var total = 0;
19+
20+
function preload() {
21+
// 37x45 is the size of each frame
22+
// There are 18 frames in the PNG - you can leave this value blank if the frames fill up the entire PNG, but in this case there are some
23+
// blank frames at the end, so we tell the loader how many to load
24+
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
25+
}
26+
27+
function create() {
28+
29+
releaseMummy();
30+
31+
}
32+
33+
function releaseMummy() {
34+
35+
var mummy = game.add.sprite(-(Math.random() * 800), game.world.randomY, 'mummy');
36+
37+
mummy.animations.add('walk');
38+
mummy.animations.play('walk', 50, true);
39+
40+
game.add.tween(mummy).to({ x: game.width + (1600 + mummy.x) }, 20000, Phaser.Easing.Linear.None, true);
41+
42+
total++;
43+
timer = game.time.now + 100;
44+
45+
}
46+
47+
function update() {
48+
49+
if (total < 200 && game.time.now > timer)
50+
{
51+
releaseMummy();
52+
}
53+
54+
}
55+
56+
})();
57+
58+
</script>
59+
60+
</body>
61+
</html>

src/core/Game.js

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ Phaser.Game.prototype = {
243243
return;
244244
}
245245

246-
if (!document.body) {
246+
if (!document.body)
247+
{
247248
window.setTimeout(this._onBoot, 20);
248249
}
249250
else
@@ -351,42 +352,13 @@ Phaser.Game.prototype = {
351352
// this.stage.update();
352353
// this.sound.update();
353354
// this.physics.update();
354-
// this.world.update();
355-
355+
this.world.update();
356+
this.state.update();
356357
this.plugins.update();
357358

358-
if (this._loadComplete)
359-
{
360-
this.state.update();
361-
362-
// this.world.postUpdate();
363-
this.plugins.postUpdate();
364-
this.plugins.preRender();
365-
366-
this.state.preRender();
367-
368-
this.renderer.render(this.world._stage);
369-
370-
this.plugins.render();
371-
372-
this.state.render();
373-
374-
this.plugins.postRender();
375-
}
376-
else
377-
{
378-
// Still loading assets
379-
this.state.loadUpdate();
380-
381-
// this.world.postUpdate();
382-
this.plugins.postUpdate();
383-
384-
this.plugins.preRender();
385-
this.renderer.render(this.world._stage);
386-
this.plugins.render();
387-
this.state.loadRender();
388-
this.plugins.postRender();
389-
}
359+
this.renderer.render(this.world._stage);
360+
361+
this.plugins.postRender();
390362

391363
},
392364

src/core/StateManager.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Phaser.StateManager.prototype = {
2424
*/
2525
_pendingState: null,
2626

27+
/**
28+
* Flag that sets if the State has been created or not.
29+
* @type {Boolean}
30+
*/
31+
_created: false,
32+
2733
/**
2834
* The state to be switched to in the next frame.
2935
* @type {Object}
@@ -257,6 +263,8 @@ Phaser.StateManager.prototype = {
257263
{
258264
this.onCreateCallback.call(this.callbackContext);
259265
}
266+
267+
this._created = true;
260268
}
261269
else
262270
{
@@ -275,6 +283,8 @@ Phaser.StateManager.prototype = {
275283
this.onCreateCallback.call(this.callbackContext);
276284
}
277285

286+
this._created = true;
287+
278288
this.game.loadComplete();
279289
}
280290

@@ -336,6 +346,7 @@ Phaser.StateManager.prototype = {
336346
this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
337347

338348
this.current = key;
349+
this._created = false;
339350

340351
this.onInitCallback.call(this.callbackContext);
341352

@@ -345,22 +356,15 @@ Phaser.StateManager.prototype = {
345356

346357
// console.log('Phaser.StateManager.loadComplete');
347358

348-
if (this.onCreateCallback) {
359+
if (this._created == false && this.onCreateCallback)
360+
{
349361
// console.log('Create callback found');
350362
this.onCreateCallback.call(this.callbackContext);
363+
this._created = true;
351364
}
352365

353366
},
354367

355-
loadUpdate: function () {
356-
357-
if (this.onLoadUpdateCallback)
358-
{
359-
this.onLoadUpdateCallback.call(this.callbackContext);
360-
}
361-
362-
},
363-
364368
loadRender: function () {
365369

366370
if (this.onLoadRenderCallback)
@@ -372,9 +376,16 @@ Phaser.StateManager.prototype = {
372376

373377
update: function () {
374378

375-
if (this.onUpdateCallback)
376-
{
377-
this.onUpdateCallback.call(this.callbackContext);
379+
if (this._created && this.onUpdateCallback)
380+
{
381+
this.onUpdateCallback.call(this.callbackContext);
382+
}
383+
else
384+
{
385+
if (this.onLoadUpdateCallback)
386+
{
387+
this.onLoadUpdateCallback.call(this.callbackContext);
388+
}
378389
}
379390

380391
},

src/core/World.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Phaser.World.prototype = {
1616

1717
_stage: null,
1818
_container: null,
19+
_length: 0,
1920

2021
bounds: null,
2122

@@ -38,6 +39,15 @@ Phaser.World.prototype = {
3839
return gameobject;
3940
},
4041

42+
update: function () {
43+
44+
for (var child in this._container.children)
45+
{
46+
this._container.children[child].update();
47+
}
48+
49+
},
50+
4151
/**
4252
* Updates the size of this world.
4353
*

src/gameobjects/Sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite;
109109
/**
110110
* Automatically called after update() by the game loop for all 'alive' objects.
111111
*/
112-
Phaser.Sprite.prototype.postUpdate = function() {
112+
Phaser.Sprite.prototype.update = function() {
113113

114114
this.animations.update();
115115
// this.checkBounds();

0 commit comments

Comments
 (0)