Lots of new examples :)

Lots of new examples, the wip/examples folder can be destoryed I think
This commit is contained in:
Webeled
2013-09-30 17:31:03 +01:00
parent 4b177e0a9b
commit bdc8edea9d
15 changed files with 807 additions and 11 deletions
@@ -0,0 +1,77 @@
<?php
$title = "Group length and sub groups";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
// Groups for storing friends and enemies, may use for collision later.
var friendAndFoe,
enemies;
// Groups for teaming up stuff.
var normalBaddies,
purpleBaddies;
function preload() {
game.load.image('ufo', 'assets/sprites/ufo.png');
game.load.image('baddie', 'assets/sprites/space-baddie.png');
game.load.image('purple-baddie', 'assets/sprites/space-baddie-purple.png');
}
function create() {
// Create some local groups for later use.
friendAndFoe = game.add.group();
enemies = game.add.group();
normalBaddies = game.add.group();
purpleBaddies = game.add.group();
// Add both teams to enemies group, using the Pixi container otherwise it's impossible
enemies.add(normalBaddies._container);
enemies.add(purpleBaddies._container);
// Create a ufo as a friend sprite.
friendAndFoe.create(200, 240, 'ufo');
// Create some enemies.
for (var i = 0; i < 16; i++) {
createBaddie();
}
// Tap to create new baddie sprites.
game.input.onTap.add(createBaddie, this);
}
function createBaddie() {
var baddie;
// Of course, the baddies created will belong to their respective groups
if (Math.random() > 0.5) {
baddie = purpleBaddies.create(360 + Math.random() * 200, 120 + Math.random() * 200,
'purple-baddie');
}
else {
baddie = normalBaddies.create(360 + Math.random() * 200, 120 + Math.random() * 200,
'baddie');
}
}
function render() {
game.debug.renderStyle = '#fff';
game.debug.renderText('Tap screen or click to create new baddies.', 16, 24);
game.debug.renderText('enemies: ' + enemies.length + ' (actually ' + enemies.length + ' groups)', 16, 48);
game.debug.renderText('normal baddies: ' + normalBaddies.length, 16, 60);
game.debug.renderText('purple baddies: ' + purpleBaddies.length, 16, 72);
game.debug.renderText('friends: ' + friendAndFoe.length, 16, 96);
}
})();
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,52 @@
<?php
$title = "Swap children inside a group";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
}
var atari1;
var atari2;
function create() {
// Items are rendered in the depth order in which they are added to the Group
atari1 = game.add.sprite(100, 100, 'atari1');
atari2 = game.add.sprite(250, 90, 'atari2');
game.input.onTap.add(swapSprites, this);
}
function swapSprites() {
// The 2 Sprites are in the global world Group, but this will work for any Group:
game.world.group.swap(atari1, atari2);
}
function render () {
game.debug.renderText('Tap screen to swap the children and therefore swap their indexes.', 10, 280);
}
})();
</script>
<?php
require('../foot.php');
?>