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
+48
View File
@@ -0,0 +1,48 @@
<?php
$title = "Clicking on a button ";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
game.load.image('background','assets/misc/starfield.jpg');
}
var button,
background;
function create() {
game.stage.backgroundColor = '#182d3b';
background=game.add.tileSprite(0, 0, 800, 600, 'background');
button = game.add.button(game.world.centerX, 400, 'button', actionOnClick, this, 2, 1, 0);
}
function actionOnClick () {
background.visible=!background.visible;
}
})();
</script>
<?php
require('../foot.php');
?>
+55
View File
@@ -0,0 +1,55 @@
<?php
$title = "Programmatically changing the frames";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.spritesheet('button', 'assets/buttons/number-buttons-90x90.png', 90,90);
game.load.image('background','assets/misc/starfield.jpg');
}
var button,
background;
function create() {
//setting the background colour
game.stage.backgroundColor = '#182d3b';
// the numbers given in parameters are the indexes of the frames, in this order :
// over,out,down
button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 1, 0, 2);
//setting the anchor to the center
button.anchor.setTo(0.5,0.5);
}
function actionOnClick () {
//manually changing the frames of the button, i.e, how it will look when you play with it
button.setFrames(4,3,5);
console.log('You clicked on the button');
}
})();
</script>
<?php
require('../foot.php');
?>
+56
View File
@@ -0,0 +1,56 @@
<?php
$title = "Rotating a button";
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.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
game.load.image('background','assets/misc/starfield.jpg');
}
var button,
background;
function create() {
game.stage.backgroundColor = '#cccccc';
// the numbers given in parameters are the indexes of the frames, in this order :
// over,out,down
button = game.add.button(game.world.centerX, game.world.centerY, 'button', actionOnClick, this, 1, 0, 2);
//set the anchor of the sprite in the center, otherwise it would rotate around the top-left corner
button.anchor.setTo(0.5,0.5);
}
function actionOnClick () {
alert("Though I'm turning around, you can still click on me");
}
function update () {
button.angle+=1;
}
})();
</script>
<?php
require('../foot.php');
?>