Examples (audio, button,camera), and docs

Created some examples (audio, button,camera), and documented the source
code along the way
This commit is contained in:
Webeled
2013-09-16 16:37:30 +02:00
parent 17e208a95e
commit fc584cf6bc
15 changed files with 393 additions and 8 deletions
+76
View File
@@ -0,0 +1,76 @@
<?php
$title = "Following the player";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
var baddie,
keys=Phaser.Keyboard;
function preload() {
game.load.image('background','assets/misc/starfield.jpg');
game.load.image('ufo','assets/sprites/ufo.png');
game.load.image('baddie','assets/sprites/space-baddie.png');
}
function create() {
game.add.tileSprite(0, 0, 2000, 2000, 'background');
game.world.setSize(1400,1400);
for(var i=0,nb=10;i<nb;i++){
game.add.sprite(game.world.randomX,game.world.randomY,'ufo');
}
baddie=game.add.sprite(150,320,'baddie');
game.camera.follow(baddie);
}
function update() {
baddie.body.velocity.x=baddie.body.velocity.y=0;
if(game.input.keyboard.isDown(keys.LEFT) && !game.input.keyboard.isDown(keys.RIGHT)){
baddie.body.velocity.x=-155;
}
else if(game.input.keyboard.isDown(keys.RIGHT) && !game.input.keyboard.isDown(keys.LEFT)){
baddie.body.velocity.x=155;
}
else if(game.input.keyboard.isDown(keys.UP) && !game.input.keyboard.isDown(keys.DOWN)){
baddie.angle=90;
baddie.body.velocity.y=-155;
}
else if(game.input.keyboard.isDown(keys.DOWN) && !game.input.keyboard.isDown(keys.UP)){
baddie.angle=90;
baddie.body.velocity.y=155;
}
}
})();
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,60 @@
<?php
$title = "Moving the game camera with the keyboard";
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.tilemap('snes', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
}
function create() {
//setting the size of the game world larger than the tilemap's size
game.world.setSize(2000,2000);
// game.camera.width=150;
// game.camera.height=150;
game.stage.backgroundColor = '#255d3b';
// adding the tilemap
game.add.tilemap(0, 168, 'snes');
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 8;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 8;
}
}
})();
</script>
<?php
require('../foot.php');
?>