Updating examples with new runner and menu system.

This commit is contained in:
Richard Davey
2013-09-13 17:48:47 +01:00
parent ad0d32b7aa
commit 70233b7508
155 changed files with 2377 additions and 104 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
$title = "Display a Sprite";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
function create() {
var test = game.add.sprite(200, 200, 'mushroom');
}
function update() {
}
})();
</script>
<?php
require('../foot.php');
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
$title = "Sprite Sheet";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var bunny;
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('ms', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
function create() {
bunny = game.add.sprite(40, 100, 'ms');
bunny.animations.add('walk');
bunny.animations.play('walk', 50, true);
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() {
if (bunny.x >= 300)
{
bunny.scale.x += 0.01;
bunny.scale.y += 0.01;
}
}
})();
</script>
<?php
require('../foot.php');
?>
+61
View File
@@ -0,0 +1,61 @@
<?php
$title = "Sprite Sheet and Scale";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }, false, false);
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.scale.setTo(2, 2);
// If you prefer to work in degrees rather than radians then you can use Phaser.Sprite.angle
// otherwise use Phaser.Sprite.rotation
mummy.angle = game.rnd.angle();
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>
<?php
require('../foot.php');
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
$title = "Sprite Animation";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
}
var s;
function create() {
// game.world._stage.backgroundColorString = '#182d3b';
s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot');
// s.anchor.setTo(0.5, 0.5);
s.scale.setTo(2, 2);
s.animations.add('run');
s.animations.play('run', 10, true);
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
s.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
s.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
s.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
s.y += 4;
}
}
function render() {
game.debug.renderSpriteCorners(s, false, false);
game.debug.renderSpriteInfo(s, 20, 32);
}
})();
</script>
<?php
require('../foot.php');
?>
+52
View File
@@ -0,0 +1,52 @@
<?php
$title = "Custom Sprite";
require('../head.php');
?>
<script type="text/javascript">
// Here is a custom game object
MonsterBunny = function (game, x, y) {
Phaser.Sprite.call(this, game, x, y, 'bunny');
};
MonsterBunny.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Sprite.prototype);
MonsterBunny.prototype.constructor = MonsterBunny;
/**
* Automatically called by World.update
*/
MonsterBunny.prototype.update = function() {
this.angle++;
};
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.image('bunny', 'assets/sprites/bunny.png');
}
function create() {
var wabbit = new MonsterBunny(game, 400, 300);
wabbit.lifespan = 3000;
wabbit.anchor.setTo(0.5, 0.5);
game.add.existing(wabbit);
}
})();
</script>
<?php
require('../foot.php');
?>