mirror of
https://github.com/wassname/phaser.git
synced 2026-06-28 16:20:37 +08:00
Mummy attack :)
This commit is contained in:
+10
-5
@@ -25,21 +25,26 @@
|
||||
|
||||
function create() {
|
||||
|
||||
bunny = game.add.sprite(-40, 100, 'ms');
|
||||
bunny = game.add.sprite(40, 100, 'ms');
|
||||
|
||||
bunny.animations.add('walk');
|
||||
|
||||
bunny.animations.play('walk', 50, true);
|
||||
|
||||
// bunny.scale.x = 8;
|
||||
// bunny.scale.y = 8;
|
||||
|
||||
game.add.tween(bunny).to({ x: game.width }, 10000, Phaser.Easing.Linear.None, true);
|
||||
|
||||
}
|
||||
|
||||
// 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)
|
||||
// then create a function called loadUpdate() and use that
|
||||
function update() {
|
||||
bunny.postUpdate();
|
||||
|
||||
if (bunny.x >= 300)
|
||||
{
|
||||
bunny.scale.x += 0.01;
|
||||
bunny.scale.y += 0.01;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>phaser.js - a new beginning</title>
|
||||
<?php
|
||||
require('js.php');
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||
|
||||
var timer = 0;
|
||||
var total = 0;
|
||||
|
||||
function preload() {
|
||||
// 37x45 is the size of each frame
|
||||
// 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
|
||||
// blank frames at the end, so we tell the loader how many to load
|
||||
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
releaseMummy();
|
||||
|
||||
}
|
||||
|
||||
function releaseMummy() {
|
||||
|
||||
var mummy = game.add.sprite(-(Math.random() * 800), game.world.randomY, 'mummy');
|
||||
|
||||
mummy.animations.add('walk');
|
||||
mummy.animations.play('walk', 50, true);
|
||||
|
||||
game.add.tween(mummy).to({ x: game.width + (1600 + mummy.x) }, 20000, Phaser.Easing.Linear.None, true);
|
||||
|
||||
total++;
|
||||
timer = game.time.now + 100;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (total < 200 && game.time.now > timer)
|
||||
{
|
||||
releaseMummy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+6
-34
@@ -243,7 +243,8 @@ Phaser.Game.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.body) {
|
||||
if (!document.body)
|
||||
{
|
||||
window.setTimeout(this._onBoot, 20);
|
||||
}
|
||||
else
|
||||
@@ -351,42 +352,13 @@ Phaser.Game.prototype = {
|
||||
// this.stage.update();
|
||||
// this.sound.update();
|
||||
// this.physics.update();
|
||||
// this.world.update();
|
||||
|
||||
this.world.update();
|
||||
this.state.update();
|
||||
this.plugins.update();
|
||||
|
||||
if (this._loadComplete)
|
||||
{
|
||||
this.state.update();
|
||||
|
||||
// this.world.postUpdate();
|
||||
this.plugins.postUpdate();
|
||||
this.plugins.preRender();
|
||||
this.renderer.render(this.world._stage);
|
||||
|
||||
this.state.preRender();
|
||||
|
||||
this.renderer.render(this.world._stage);
|
||||
|
||||
this.plugins.render();
|
||||
|
||||
this.state.render();
|
||||
|
||||
this.plugins.postRender();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Still loading assets
|
||||
this.state.loadUpdate();
|
||||
|
||||
// this.world.postUpdate();
|
||||
this.plugins.postUpdate();
|
||||
|
||||
this.plugins.preRender();
|
||||
this.renderer.render(this.world._stage);
|
||||
this.plugins.render();
|
||||
this.state.loadRender();
|
||||
this.plugins.postRender();
|
||||
}
|
||||
this.plugins.postRender();
|
||||
|
||||
},
|
||||
|
||||
|
||||
+24
-13
@@ -24,6 +24,12 @@ Phaser.StateManager.prototype = {
|
||||
*/
|
||||
_pendingState: null,
|
||||
|
||||
/**
|
||||
* Flag that sets if the State has been created or not.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
_created: false,
|
||||
|
||||
/**
|
||||
* The state to be switched to in the next frame.
|
||||
* @type {Object}
|
||||
@@ -257,6 +263,8 @@ Phaser.StateManager.prototype = {
|
||||
{
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
|
||||
this._created = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -275,6 +283,8 @@ Phaser.StateManager.prototype = {
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
|
||||
this._created = true;
|
||||
|
||||
this.game.loadComplete();
|
||||
}
|
||||
|
||||
@@ -336,6 +346,7 @@ Phaser.StateManager.prototype = {
|
||||
this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
|
||||
|
||||
this.current = key;
|
||||
this._created = false;
|
||||
|
||||
this.onInitCallback.call(this.callbackContext);
|
||||
|
||||
@@ -345,22 +356,15 @@ Phaser.StateManager.prototype = {
|
||||
|
||||
// console.log('Phaser.StateManager.loadComplete');
|
||||
|
||||
if (this.onCreateCallback) {
|
||||
if (this._created == false && this.onCreateCallback)
|
||||
{
|
||||
// console.log('Create callback found');
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
this._created = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
loadUpdate: function () {
|
||||
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
loadRender: function () {
|
||||
|
||||
if (this.onLoadRenderCallback)
|
||||
@@ -372,9 +376,16 @@ Phaser.StateManager.prototype = {
|
||||
|
||||
update: function () {
|
||||
|
||||
if (this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext);
|
||||
if (this._created && this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -16,6 +16,7 @@ Phaser.World.prototype = {
|
||||
|
||||
_stage: null,
|
||||
_container: null,
|
||||
_length: 0,
|
||||
|
||||
bounds: null,
|
||||
|
||||
@@ -38,6 +39,15 @@ Phaser.World.prototype = {
|
||||
return gameobject;
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
for (var child in this._container.children)
|
||||
{
|
||||
this._container.children[child].update();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the size of this world.
|
||||
*
|
||||
|
||||
@@ -109,7 +109,7 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite;
|
||||
/**
|
||||
* Automatically called after update() by the game loop for all 'alive' objects.
|
||||
*/
|
||||
Phaser.Sprite.prototype.postUpdate = function() {
|
||||
Phaser.Sprite.prototype.update = function() {
|
||||
|
||||
this.animations.update();
|
||||
// this.checkBounds();
|
||||
|
||||
Reference in New Issue
Block a user