16 Commits
Author SHA1 Message Date
Richard Davey 8c41b3253c 1.0.5 package 2013-09-20 14:00:49 +01:00
Richard Davey a415e779d1 Final 1.0.5 release. 2013-09-20 13:55:33 +01:00
Richard Davey 9e88da5c66 Multiple animation fixes in place. 2013-09-19 23:47:50 +01:00
Richard Davey e938e41c73 Merge pull request #54 from webeled/master
Lots of JSDdocs done, and some camera examples
2013-09-19 12:15:26 -07:00
Webeled 1b5c1f18fe More camera examples 2013-09-19 17:47:12 +02:00
Webeled 26a595cd44 JSDocs update ;) 2013-09-19 16:34:48 +02:00
Richard Davey 3f1cafe21f Put the famous idnetityMatrix typo back in so it doesn't break Pixi 2013-09-19 13:33:51 +01:00
Richard Davey 7dd63df087 Merge pull request #52 from cocoademon/master
Make Phaser.Text play nicely with scrolling, by using an explicit x, y
2013-09-19 05:26:22 -07:00
Webeled 78a062dfb6 Updated my files and the documentation checklist 2013-09-19 13:17:49 +02:00
Webeled 6e4631a849 First commit of the day 2013-09-19 10:36:15 +02:00
Cameron Foale 6fde862f61 Make Phaser.Text play nicely with scrolling, by using an explicit x, y 2013-09-19 16:57:19 +10:00
Cameron FoaleandCameron Foale 4f969901da Fixed typo 'indetityMatrix' in RenderTexture 2013-09-19 16:41:34 +10:00
Richard Davey c5fc5e3394 Fixed various issues in the TweenManager, added length property to Group and improved the build script. 2013-09-19 04:45:08 +01:00
Richard Davey cf26f68693 Added Math.numberArray 2013-09-18 14:08:26 +01:00
Richard Davey 47834ad478 Fixed issue in FrameData.getFrameIndexes where the input array was being ignored. 2013-09-18 14:02:31 +01:00
Richard Davey 91c07ea37d Animation delay put back to normal 2013-09-18 06:41:41 +01:00
40 changed files with 2171 additions and 879 deletions
Binary file not shown.
+20 -1
View File
@@ -5,7 +5,7 @@ Phaser 1.0
Phaser is a fast, free and fun open source game framework for making desktop and mobile browser HTML5 games. It uses [Pixi.js](https://github.com/GoodBoyDigital/pixi.js/) internally for fast 2D Canvas and WebGL rendering. Phaser is a fast, free and fun open source game framework for making desktop and mobile browser HTML5 games. It uses [Pixi.js](https://github.com/GoodBoyDigital/pixi.js/) internally for fast 2D Canvas and WebGL rendering.
Version: 1.0.4 - Released: September 18th 2013 Version: 1.0.5 - Released: September 20th 2013
By Richard Davey, [Photon Storm](http://www.photonstorm.com) By Richard Davey, [Photon Storm](http://www.photonstorm.com)
@@ -35,6 +35,25 @@ Phaser is everything we ever wanted from an HTML5 game framework. It will power
Change Log Change Log
---------- ----------
Version 1.0.5 (September 20th 2013)
* Fixed issue in FrameData.getFrameIndexes where the input array was being ignored.
* Added Math.numberArray - Returns an Array containing the numbers from min to max (inclusive), useful for animation frame construction.
* Fixed a horrendously sneaky bug: If a new tween was created in the onComplete callback of a tween about to be deleted, it would get automatically spliced.
* Added a pendingDelete property to Tween to stop tweens that were removed during a callback from causing update errors during the TweenManager loop.
* Added Group.length property.
* Added explicit x/y attributes to Phaser.Text to make it work with the camera system (thanks cocoademon).
* Fixed issue stopping multiple animations from playing, only the most recent would play (frames array was being overwritten, thanks Legrandk)
* Updated Debug.renderSpriteBounds() so it doesn't use the deprecated Sprite.worldView any more (thanks MikeMnD)
* Added 2 new properties to the Text object: Text.text and Text.style, both are getter/setters and don't flag dirty unless changed, so safe for core loop use.
* Removed the exists check from Group.callAll, it now runs on all children (as the name implies)
* Added Group.callAllExists - you can now call a function on all children who have exists = the provided boolean.
* Finished off the Breakout example game - now fully playable, proper rebound, scoring, lives, etc.
* Removed Group.sort dummy entry until it's working.
* Removed ArcadePhysics.postUpdate.
* Updated Sprite.update to set renderable to false when the object goes out of Camera, not 'visible' false, otherwise it stops the transform being updated by Pixi.
* BUG: There is a known issue where the wrong rect coordinates are given to the QuadTree if the Sprite is a child of a Group or another Sprite which has an x/y offset.
Version 1.0.4 (September 18th 2013) Version 1.0.4 (September 18th 2013)
* Small fix to Phaser.Canvas to stop it from setting overflow hidden if the parent DOM element doesn't exist. * Small fix to Phaser.Canvas to stop it from setting overflow hidden if the parent DOM element doesn't exist.
+13 -2
View File
@@ -2,7 +2,13 @@
<textarea style="width: 800px; height: 800px"> <textarea style="width: 800px; height: 800px">
<?php <?php
// Get the version number
// VERSION: '1.0.5',
$vf = file_get_contents('../src/Phaser.js');
$version = substr($vf, strpos($vf, 'VERSION: ') + 10, 5);
echo "Building version $version \n\n";
$js = file('../examples/js.php'); $js = file('../examples/js.php');
$output = ""; $output = "";
@@ -15,16 +21,21 @@
{ {
$line = str_replace('<script src="', '', $line); $line = str_replace('<script src="', '', $line);
$line = str_replace('"></script>', '', $line); $line = str_replace('"></script>', '', $line);
$filename = substr($line, strrpos($line, '/') + 1);
echo $line . "\n"; echo $line . "\n";
// echo $filename . "\n";
// Read the file in // Read the file in
$source = file_get_contents($line); $source = file_get_contents($line);
if ($i == 4) if ($filename == 'Intro.js')
{ {
// Built at: {buildDate} // Built at: {buildDate}
$source = str_replace('{buildDate}', date('r'), $source); $source = str_replace('{buildDate}', date('r'), $source);
// {version}
$source = str_replace('{version}', $version, $source);
} }
$output .= $source . "\n"; $output .= $source . "\n";
+801 -307
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
+36
View File
@@ -0,0 +1,36 @@
<?php
$title = "Multiple Animations";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create });
function preload() {
game.load.atlas('bot', 'assets/misc/NumberSprite.png', 'assets/misc/NumberSprite.json');
}
function create() {
var bot = game.add.sprite(200, 200, 'bot');
bot.animations.add('num1', ['num10000','num10001','num10002','num10003','num10004','num10005'], 24, false, false);
bot.animations.add('num2', ['num20000','num20001','num20002','num20003','num20004','num20005'], 24, false, false);
bot.animations.add('num3', ['num30000','num30001','num30002','num30003','num30004','num30005'], 24, false, false);
// bot.animations.play('num1', 15, true);
bot.animations.play('num2', 15, true);
// bot.animations.play('num3', 15, true);
}
})();
</script>
<?php
require('../foot.php');
?>
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

-236
View File
@@ -1,236 +0,0 @@
{"frames": [
{
"filename": "ball_1.png",
"frame": {"x":218,"y":38,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "ball_2.png",
"frame": {"x":218,"y":20,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "ball_3.png",
"frame": {"x":218,"y":2,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "ball_4.png",
"frame": {"x":200,"y":38,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "ball_5.png",
"frame": {"x":200,"y":20,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "brick_1_1.png",
"frame": {"x":98,"y":21,"w":32,"h":17},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
"sourceSize": {"w":32,"h":17}
},
{
"filename": "brick_1_2.png",
"frame": {"x":98,"y":2,"w":32,"h":17},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
"sourceSize": {"w":32,"h":17}
},
{
"filename": "brick_1_3.png",
"frame": {"x":270,"y":17,"w":30,"h":13},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":1,"w":30,"h":13},
"sourceSize": {"w":32,"h":17}
},
{
"filename": "brick_1_4.png",
"frame": {"x":54,"y":52,"w":24,"h":9},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":4,"w":24,"h":9},
"sourceSize": {"w":32,"h":17}
},
{
"filename": "brick_2_1.png",
"frame": {"x":236,"y":19,"w":32,"h":15},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
"sourceSize": {"w":32,"h":15}
},
{
"filename": "brick_2_2.png",
"frame": {"x":236,"y":2,"w":32,"h":15},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
"sourceSize": {"w":32,"h":15}
},
{
"filename": "brick_2_3.png",
"frame": {"x":270,"y":2,"w":30,"h":13},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":13},
"sourceSize": {"w":32,"h":15}
},
{
"filename": "brick_2_4.png",
"frame": {"x":236,"y":50,"w":24,"h":11},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":11},
"sourceSize": {"w":32,"h":15}
},
{
"filename": "brick_3_1.png",
"frame": {"x":166,"y":20,"w":32,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_3_2.png",
"frame": {"x":166,"y":2,"w":32,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_3_3.png",
"frame": {"x":236,"y":36,"w":30,"h":12},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_3_4.png",
"frame": {"x":28,"y":52,"w":24,"h":10},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "one.png",
"frame": {"x":66,"y":2,"w":30,"h":48},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
"sourceSize": {"w":32,"h":64}
},
{
"filename": "paddle_big.png",
"frame": {"x":98,"y":40,"w":48,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":48,"h":16},
"sourceSize": {"w":48,"h":16}
},
{
"filename": "paddle_small.png",
"frame": {"x":148,"y":38,"w":32,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "power_down.png",
"frame": {"x":200,"y":2,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "power_up.png",
"frame": {"x":182,"y":38,"w":16,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
"sourceSize": {"w":16,"h":16}
},
{
"filename": "brick_4_1.png",
"frame": {"x":132,"y":20,"w":32,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_4_2.png",
"frame": {"x":132,"y":2,"w":32,"h":16},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_4_3.png",
"frame": {"x":270,"y":32,"w":30,"h":12},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "brick_4_4.png",
"frame": {"x":2,"y":52,"w":24,"h":10},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
"sourceSize": {"w":32,"h":16}
},
{
"filename": "three.png",
"frame": {"x":34,"y":2,"w":30,"h":48},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":48},
"sourceSize": {"w":32,"h":48}
},
{
"filename": "two.png",
"frame": {"x":2,"y":2,"w":30,"h":48},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
"sourceSize": {"w":32,"h":64}
}],
"meta": {
"app": "http://www.texturepacker.com",
"version": "1.0",
"image": "breakout.png",
"format": "RGBA8888",
"size": {"w":302,"h":64},
"scale": "1",
"smartupdate": "$TexturePacker:SmartUpdate:c510ff2f709e8d175b059cd1cbe64773$"
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

+139
View File
@@ -0,0 +1,139 @@
<?php
$title = "Follow Styles";
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 });
var ufo,
Keys=Phaser.Keyboard,
speed=4,
style='default';
function preload() {
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
game.load.image('ufo','assets/sprites/ufo.png');
game.load.image('baddie','assets/sprites/space-baddie.png');
game.load.spritesheet('button', 'assets/buttons/follow-style-button.png', 224, 70);
}
function create() {
//make the world larger than the actual canvas
game.world.setSize(1400,1400);
for(var i=0,nb=10;i<nb;i++){
game.add.sprite(game.world.randomX,game.world.randomY,'baddie');
}
// background images
game.add.sprite(0, 0, 'sky')
.scrollFactor.setTo(0, 0);
game.add.sprite(0, 360, 'ground')
.scrollFactor.setTo(0.5, 0.1);
game.add.sprite(0, 400, 'river')
.scrollFactor.setTo(1.3, 0.16);
game.add.sprite(200, 120, 'cloud0')
.scrollFactor.setTo(0.3, 0.1);
game.add.sprite(-60, 120, 'cloud1')
.scrollFactor.setTo(0.5, 0.1);
game.add.sprite(900, 170, 'cloud2')
.scrollFactor.setTo(0.7, 0.1);
// ufo sprite
ufo = game.add.sprite(300, 240, 'ufo');
//registration point
ufo.anchor.setTo(0.5, 0.5);
game.camera.follow(ufo);
// follow style switch buttons
btn0 = game.add.button(6, 40, 'button', lockonFollow,this, 0, 0, 0);
btn1 = game.add.button(6, 120, 'button', platformerFollow,this, 1, 1, 1);
btn2 = game.add.button(6, 200, 'button', topdownFollow,this, 2, 2, 2);
btn3 = game.add.button(6, 280, 'button', topdownTightFollow,this, 3, 3, 3);
}
function lockonFollow() {
game.camera.follow(ufo, Phaser.Camera.FOLLOW_LOCKON);
style = 'STYLE_LOCKON';
}
function platformerFollow() {
game.camera.follow(ufo, Phaser.Camera.FOLLOW_PLATFORMER);
style = 'STYLE_PLATFORMER';
}
function topdownFollow() {
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN);
style = 'STYLE_TOPDOWN';
}
function topdownTightFollow() {
game.camera.follow(ufo, Phaser.Camera.FOLLOW_TOPDOWN_TIGHT);
style = 'STYLE_TOPDOWN_TIGHT';
}
function update() {
if (game.input.keyboard.isDown(Keys.LEFT)) {
ufo.x -= speed;
ufo.angle = -15;
}
else if (game.input.keyboard.isDown(Keys.RIGHT)) {
ufo.x += speed;
ufo.angle = 15;
}
else if (game.input.keyboard.isDown(Keys.UP)) {
ufo.y -= speed;
}
else if (game.input.keyboard.isDown(Keys.DOWN)) {
ufo.y += speed;
}
else {
ufo.angle = 0;
}
}
function render () {
game.context.fillStyle = '#fff';
game.context.font="24px Courier";
game.context.fillText('Click buttons to switch between different styles.', 60, 220);
game.context.fillText('Current style: ' + style, 60, 250);
}
})();
</script>
<?php
require('../foot.php');
?>
+2 -4
View File
@@ -21,13 +21,11 @@
//setting the size of the game world larger than the tilemap's size //setting the size of the game world larger than the tilemap's size
game.world.setSize(2000,2000); game.world.setSize(2000,2000);
// game.camera.width=150;
// game.camera.height=150;
game.stage.backgroundColor = '#255d3b'; game.stage.backgroundColor = '#255d3b';
// adding the tilemap // adding the tilemap
game.add.tilemap(0, 168, 'snes'); game.add.tilemap(0, 150, 'snes');
} }
+70
View File
@@ -0,0 +1,70 @@
<?php
$title = "World Sprite";
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.world.setSize(1920, 1200);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('card', 'assets/sprites/mana_card.png');
}
var card,
Keys=Phaser.Keyboard;
function create() {
game.add.sprite(0, 0, 'backdrop');
card = game.add.sprite(200, 200, 'card');
card.body.velocity.x = 50;
card.scale.setTo(2, 2);
}
function update() {
if (game.input.keyboard.isDown(Keys.LEFT)){
card.x -= 4;
}
else if (game.input.keyboard.isDown(Keys.RIGHT)){
card.x += 4;
}
if (game.input.keyboard.isDown(Keys.UP)){
card.y -= 4;
}
else if (game.input.keyboard.isDown(Keys.DOWN)){
card.y += 4;
}
}
function render() {
// debug are now accessed using game.debug instead of the Static DebugUtils class
game.debug.renderCameraInfo(game.camera, 32, 32);
game.debug.renderSpriteInfo(card, 32, 200);
}
})();
</script>
<?php
require('../foot.php');
?>
+5 -2
View File
@@ -55,8 +55,11 @@
function render() { function render() {
game.debug.renderRectangle(sprite1.body); game.debug.renderSpriteInfo(sprite1, 32, 32);
game.debug.renderRectangle(sprite2.body); game.debug.renderSpriteCollision(sprite1, 32, 400);
game.debug.renderSpriteBody(sprite1);
game.debug.renderSpriteBody(sprite2);
} }
+7 -3
View File
@@ -7,7 +7,7 @@
(function () { (function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }); var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create });
function preload() { function preload() {
@@ -21,17 +21,21 @@
function create() { function create() {
// For browsers that support it, this keeps our pixel art looking crisp // For browsers that support it, this keeps our pixel art looking crisp
//Phaser.Canvas.setSmoothingEnabled(game.stage.canvas.context, false); // This only works when you use Phaser.CANVAS as the renderer
Phaser.Canvas.setSmoothingEnabled(game.context, false);
boss = game.add.sprite(game.world.centerX, game.world.centerY, 'boss'); boss = game.add.sprite(game.world.centerX, game.world.centerY, 'boss');
boss.anchor.setTo(0.5, 0.5); boss.anchor.setTo(0.5, 0.5);
// Zoom in each time we press it
// Zoom in each time we press the button
button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0); button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0);
} }
function clickedIt() { function clickedIt() {
boss.scale.x += 0.5; boss.scale.x += 0.5;
boss.scale.y += 0.5; boss.scale.y += 0.5;
} }
})(); })();
+134 -14
View File
@@ -7,21 +7,37 @@
(function () { (function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() { function preload() {
game.load.atlas('breakout', 'assets/sprites/breakout.png', 'assets/sprites/breakout.json'); game.load.atlas('breakout', 'assets/games/breakout/breakout.png', 'assets/games/breakout/breakout.json');
game.load.image('starfield', 'assets/misc/starfield.jpg');
} }
var ball; var ball;
var paddle; var paddle;
var bricks; var bricks;
var ballOnPaddle = true; var ballOnPaddle = true;
var lives = 3;
var score = 0;
var scoreText;
var livesText;
var introText;
var s;
function create() { function create() {
// We do this so the ball can still rebound with the world bounds, but it will look like it has gone off the bottom of the screen
game.world.height = 620;
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
var brick; var brick;
bricks = game.add.group(); bricks = game.add.group();
@@ -35,15 +51,22 @@
} }
} }
ball = game.add.sprite(game.world.centerX, 534, 'breakout', 'ball_1.png'); paddle = game.add.sprite(game.world.centerX, 500, 'breakout', 'paddle_big.png');
paddle.anchor.setTo(0.5, 0.5);
paddle.body.collideWorldBounds = true;
paddle.body.bounce.setTo(1, 1);
paddle.body.immovable = true;
ball = game.add.sprite(game.world.centerX, paddle.y - 16, 'breakout', 'ball_1.png');
ball.anchor.setTo(0.5, 0.5);
ball.body.collideWorldBounds = true; ball.body.collideWorldBounds = true;
ball.body.bounce.setTo(1, 1); ball.body.bounce.setTo(1, 1);
ball.animations.add('spin', [ 'ball_1.png', 'ball_2.png', 'ball_3.png', 'ball_4.png', 'ball_5.png' ], 50, true, false); ball.animations.add('spin', [ 'ball_1.png', 'ball_2.png', 'ball_3.png', 'ball_4.png', 'ball_5.png' ], 50, true, false);
paddle = game.add.sprite(game.world.centerX, 550, 'breakout', 'paddle_big.png'); scoreText = game.add.text(32, 550, 'score: 0', { font: "20px Arial", fill: "#ffffff", align: "left" });
paddle.body.collideWorldBounds = true; livesText = game.add.text(680, 550, 'lives: 3', { font: "20px Arial", fill: "#ffffff", align: "left" });
paddle.body.bounce.setTo(1, 1); introText = game.add.text(game.world.centerX, 400, '- click to start -', { font: "40px Arial", fill: "#ffffff", align: "center" });
paddle.body.immovable = true; introText.anchor.setTo(0.5, 0.5);
game.input.onDown.add(releaseBall, this); game.input.onDown.add(releaseBall, this);
@@ -51,36 +74,133 @@
function update () { function update () {
// Fun, but a little sea-sick inducing :) Uncomment if you like!
// s.tilePosition.x += (game.input.speed.x / 2);
paddle.x = game.input.x; paddle.x = game.input.x;
if (paddle.x < 24)
{
paddle.x = 24;
}
else if (paddle.x > game.width - 24)
{
paddle.x = game.width - 24;
}
if (ballOnPaddle) if (ballOnPaddle)
{ {
ball.x = paddle.x + 16; ball.x = paddle.x;
} }
else else
{ {
game.physics.collide(paddle, ball); game.physics.collide(ball, paddle, ballHitPaddle, null, this);
game.physics.collide(ball, bricks, ballHitBrick, null, this); game.physics.collide(ball, bricks, ballHitBrick, null, this);
} }
// Out?
if (ball.y > 600 && ballOnPaddle == false)
{
ballLost();
}
} }
function releaseBall () { function releaseBall () {
ballOnPaddle = false; if (ballOnPaddle)
ball.body.velocity.y = -300; {
ball.body.velocity.x = -75; ballOnPaddle = false;
ball.animations.play('spin'); ball.body.velocity.y = -300;
ball.body.velocity.x = -75;
ball.animations.play('spin');
introText.visible = false;
}
} }
function ballLost () {
lives--;
if (lives == 0)
{
gameOver();
}
else
{
livesText.text = 'lives: ' + lives;
ballOnPaddle = true;
ball.body.velocity.setTo(0, 0);
ball.x = paddle.x + 16;
ball.y = paddle.y - 16;
ball.animations.stop();
}
}
function gameOver () {
ball.body.velocity.setTo(0, 0);
introText.text = "Game Over!";
introText.visible = true;
}
function ballHitBrick (_ball, _brick) { function ballHitBrick (_ball, _brick) {
_brick.kill(); _brick.kill();
score += 10;
scoreText.text = 'score: ' + score;
// Are they any bricks left?
if (bricks.countLiving() == 0)
{
// New level starts
score += 1000;
scoreText.text = 'score: ' + score;
introText = '- Next Level -';
// Let's move the ball back to the paddle
ballOnPaddle = true;
ball.body.velocity.setTo(0, 0);
ball.x = paddle.x + 16;
ball.y = paddle.y - 16;
ball.animations.stop();
// And bring the bricks back from the dead :)
bricks.callAll('revive', this);
}
} }
function render () { function ballHitPaddle (_ball, _paddle) {
var diff = 0;
if (_ball.x < _paddle.x)
{
// Ball is on the left-hand side of the paddle
diff = _paddle.x - _ball.x;
_ball.body.velocity.x = (-10 * diff);
}
else if (_ball.x > _paddle.x)
{
// Ball is on the right-hand side of the paddle
diff = _ball.x -_paddle.x;
_ball.body.velocity.x = (10 * diff);
}
else
{
// Ball is perfectly in the middle
// Add a little random X to stop it bouncing straight up!
_ball.body.velocity.x = 2 + Math.random() * 8;
}
} }
})(); })();
+140
View File
@@ -0,0 +1,140 @@
<?php
$title = "Invaders";
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.image('phaser', 'assets/sprites/phaser-dude.png');
game.load.image('bullet', 'assets/misc/bullet0.png');
game.load.image('alien', 'assets/sprites/space-baddie.png');
game.load.image('ship', 'assets/sprites/shmup-ship.png');
}
var player;
var aliens;
var bullets;
var bulletTime = 0;
var pickle;
function create() {
player = game.add.sprite(400, 500, 'ship');
player.anchor.setTo(0.5, 0.5);
aliens = game.add.group(null, 'aliens');
for (var y = 0; y < 4; y++)
{
for (var x = 0; x < 10; x++)
{
aliens.create(170 + x * 48, 100 + y * 50, 'alien');
}
}
// Shows off a known bug:
// aliens.x = 100;
// aliens.y = 50;
bullets = game.add.group(null, 'bullets');
for (var i = 0; i < 10; i++)
{
var b = bullets.create(0, 0, 'bullet');
b.name = 'bullet' + i;
b.exists = false;
b.visible = false;
b.events.onOutOfBounds.add(resetBullet, this);
}
// Shows off a known bug:
// var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true);
// tween.onComplete.add(descend, this);
}
function overAlien () {
console.log('over pickle');
}
function descend() {
aliens.y += 10;
}
function update() {
player.velocity.x = 0;
player.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
player.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
player.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
{
fireBullet();
}
game.physics.collide(bullets, aliens, collisionHandler, null, this);
}
function fireBullet () {
if (game.time.now > bulletTime)
{
bullet = bullets.getFirstExists(false);
if (bullet)
{
bullet.reset(player.x + 6, player.y - 8);
bullet.velocity.y = -300;
bulletTime = game.time.now + 250;
}
}
}
// Called if the bullet goes out of the screen
function resetBullet (bullet) {
bullet.kill();
}
function collisionHandler (bullet, alien) {
bullet.kill();
alien.kill();
}
function render () {
aliens.forEach(renderBounds, this);
game.debug.renderQuadTree(game.physics.quadTree);
}
function renderBounds(s) {
game.debug.renderSpriteBounds(s, 'rgba(0,0,255,0.4)', true);
}
})();
</script>
<?php
require('../foot.php');
?>
+2 -2
View File
@@ -12,11 +12,11 @@
var s; var s;
function preload() { function preload() {
game.load.image('disk', 'assets/misc/starfield.jpg'); game.load.image('starfield', 'assets/misc/starfield.jpg');
} }
function create() { function create() {
s = game.add.tileSprite(0, 0, 800, 600, 'disk'); s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
} }
function update() { function update() {
+1 -1
View File
@@ -1,7 +1,7 @@
/** /**
* Phaser - http://www.phaser.io * Phaser - http://www.phaser.io
* *
* v1.0.1 - Built at: {buildDate} * v{version} - Built at: {buildDate}
* *
* @author Richard Davey http://www.photonstorm.com @photonstorm * @author Richard Davey http://www.photonstorm.com @photonstorm
* *
+1 -1
View File
@@ -3,7 +3,7 @@
*/ */
var Phaser = Phaser || { var Phaser = Phaser || {
VERSION: '1.0.4', VERSION: '1.0.5',
GAMES: [], GAMES: [],
AUTO: 0, AUTO: 0,
CANVAS: 1, CANVAS: 1,
+26 -52
View File
@@ -9,104 +9,78 @@
* An Animation instance contains a single animation and the controls to play it. * An Animation instance contains a single animation and the controls to play it.
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite. * It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
* *
* @class Animation * @class Phaser.Animation
* @constructor * @constructor
* @param {Phaser.Game} game A reference to the currently running game. * @param {Phaser.Game} game - A reference to the currently running game.
* @param {Phaser.Sprite} parent A reference to the owner of this Animation. * @param {Phaser.Sprite} parent - A reference to the owner of this Animation.
* @param {String} name The unique name for this animation, used in playback commands. * @param {string} name - The unique name for this animation, used in playback commands.
* @param {Phaser.Animation.FrameData} frameData The FrameData object that contains all frames used by this Animation. * @param {Phaser.Animation.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
* @param {Mixed} frames An array of numbers or strings indicating which frames to play in which order. * @param {(Array.<number>|Array.<string>)} frames - An array of numbers or strings indicating which frames to play in which order.
* @param {Number} delay The time between each frame of the animation, given in ms. * @param {number} delay - The time between each frame of the animation, given in ms.
* @param {Boolean} looped Should this animation loop or play through once. * @param {boolean} looped - Should this animation loop or play through once.
*/ */
Phaser.Animation = function (game, parent, name, frameData, frames, delay, looped) { Phaser.Animation = function (game, parent, name, frameData, frames, delay, looped) {
/** /**
* A reference to the currently running Game. * @property {Phaser.Game} game - A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/ */
this.game = game; this.game = game;
/** /**
* A reference to the parent Sprite that owns this Animation. * @property {Phaser.Sprite} _parent - A reference to the parent Sprite that owns this Animation.
* @property _parent
* @private * @private
* @type {Phaser.Sprite}
*/ */
this._parent = parent; this._parent = parent;
/** /**
* The FrameData the Animation uses. * @property {Phaser.FrameData} _frameData - The FrameData the Animation uses.
* @property _frameData
* @private * @private
* @type {Phaser.FrameData}
*/ */
this._frameData = frameData; this._frameData = frameData;
/** /**
* The user defined name given to this Animation. * @property {string} name - The user defined name given to this Animation.
* @property name
* @public
* @type {String}
*/ */
this.name = name; this.name = name;
/** /**
* @property _frames * @property {object} _frames
* @private * @private
* @type {Object}
*/ */
this._frames = frames; this._frames = [];
this._frames = this._frames.concat(frames);
/** /**
* The delay in ms between each frame of the Animation. * @property {number} delay - The delay in ms between each frame of the Animation.
* @property delay
* @public
* @type {Number}
*/ */
this.delay = 1000 / delay; this.delay = 1000 / delay;
/** /**
* The loop state of the Animation. * @property {boolean} looped - The loop state of the Animation.
* @property looped
* @public
* @type {Boolean}
*/ */
this.looped = looped; this.looped = looped;
/** /**
* The finished state of the Animation. Set to true once playback completes, false during playback. * @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
* @property isFinished * @default
* @public
* @type {Boolean}
* default true
*/ */
this.isFinished = false; this.isFinished = false;
/** /**
* The playing state of the Animation. Set to false once playback completes, true during playback. * @property {boolean} isPlaying - The playing state of the Animation. Set to false once playback completes, true during playback.
* @property isPlaying * @default
* @public
* @type {Boolean}
* default false
*/ */
this.isPlaying = false; this.isPlaying = false;
/** /**
* @property _frameIndex * @property {number} _frameIndex
* @private * @private
* @type {Number} * @default
* default 0
*/ */
this._frameIndex = 0; this._frameIndex = 0;
/** /**
* The currently displayed frame of the Animation. * @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation.
* @property currentFrame
* @public
* @type {Phaser.Animation.Frame}
*/ */
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
@@ -129,8 +103,8 @@ Phaser.Animation.prototype = {
if (frameRate !== null) if (frameRate !== null)
{ {
// this.delay = 1000 / frameRate; this.delay = 1000 / frameRate;
this.delay = frameRate; // this.delay = frameRate;
} }
if (loop !== null) if (loop !== null)
+6 -6
View File
@@ -188,14 +188,14 @@ Phaser.Animation.FrameData.prototype = {
* @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created. * @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created.
* @return {Array} An array of all Frame indexes matching the given names or IDs. * @return {Array} An array of all Frame indexes matching the given names or IDs.
*/ */
getFrameIndexes: function (input, useNumericIndex, output) { getFrameIndexes: function (frames, useNumericIndex, output) {
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; } if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
if (typeof output === "undefined") { output = []; } if (typeof output === "undefined") { output = []; }
if (typeof frames === "undefined" || frames.length == 0) if (typeof frames === "undefined" || frames.length == 0)
{ {
// No input array, so we loop through all frames // No frames array, so we loop through all frames
for (var i = 0, len = this._frames.length; i < len; i++) for (var i = 0, len = this._frames.length; i < len; i++)
{ {
output.push(this._frames[i].index); output.push(this._frames[i].index);
@@ -204,16 +204,16 @@ Phaser.Animation.FrameData.prototype = {
else else
{ {
// Input array given, loop through that instead // Input array given, loop through that instead
for (var i = 0, len = input.length; i < len; i++) for (var i = 0, len = frames.length; i < len; i++)
{ {
// Does the input array contain names or indexes? // Does the frames array contain names or indexes?
if (useNumericIndex) if (useNumericIndex)
{ {
output.push(input[i].index); output.push(frames[i].index);
} }
else else
{ {
output.push(this.getFrameByName(input[i]).index); output.push(this.getFrameByName(frames[i]).index);
} }
} }
} }
+2
View File
@@ -139,6 +139,7 @@ Phaser.Animation.Parser = {
); );
PIXI.TextureCache[uuid].realSize = frames[i].spriteSourceSize; PIXI.TextureCache[uuid].realSize = frames[i].spriteSourceSize;
// PIXI.TextureCache[uuid].realSize = frames[i].sourceSize;
PIXI.TextureCache[uuid].trim.x = 0; PIXI.TextureCache[uuid].trim.x = 0;
} }
} }
@@ -208,6 +209,7 @@ Phaser.Animation.Parser = {
); );
PIXI.TextureCache[uuid].realSize = frames[key].spriteSourceSize; PIXI.TextureCache[uuid].realSize = frames[key].spriteSourceSize;
// PIXI.TextureCache[uuid].realSize = frames[key].sourceSize;
PIXI.TextureCache[uuid].trim.x = 0; PIXI.TextureCache[uuid].trim.x = 0;
} }
+118 -23
View File
@@ -1,65 +1,107 @@
/** /**
* Phaser - Camera * @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser.Camera
*/
/**
* *
* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. * A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view.
* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y * The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
* *
* @class Phaser.Camera * @class Camera
* @constructor * @constructor
* @param game {Phaser.Game} game reference to the currently running game. * @param {Phaser.Game} game game reference to the currently running game.
* @param id {number} not being used at the moment, will be when Phaser supports multiple camera * @param {number} id not being used at the moment, will be when Phaser supports multiple camera
* @param x {number} position of the camera on the X axis * @param {number} x position of the camera on the X axis
* @param y {number} position of the camera on the Y axis * @param {number} y position of the camera on the Y axis
* @param width {number} the width of the view rectangle * @param {number} width the width of the view rectangle
* @param height {number} the height of the view rectangle * @param {number} height the height of the view rectangle
*/ */
Phaser.Camera = function (game, id, x, y, width, height) { Phaser.Camera = function (game, id, x, y, width, height) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
this.game = game; this.game = game;
/**
* A reference to the game world
* @property world
* @public
* @type {Phaser.World}
*/
this.world = game.world; this.world = game.world;
this.id = 0; // reserved for future multiple camera set-ups
/**
// The view into the world we wish to render (by default the game dimensions) * reserved for future multiple camera set-ups
// The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render * @property id
// Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?) * @public
* @type {number}
*/
this.id = 0;
/** /**
* Camera view. * Camera view.
* @type {Rectangle} * The view into the world we wish to render (by default the game dimensions)
* The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render
* Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?)
* @property view
* @public
* @type {Phaser.Rectangle}
*/ */
this.view = new Phaser.Rectangle(x, y, width, height); this.view = new Phaser.Rectangle(x, y, width, height);
/** /**
* Used by Sprites to work out Camera culling. * Used by Sprites to work out Camera culling.
* @type {Rectangle} * @property screenView
* @public
* @type {Phaser.Rectangle}
*/ */
this.screenView = new Phaser.Rectangle(x, y, width, height); this.screenView = new Phaser.Rectangle(x, y, width, height);
/** /**
* Sprite moving inside this Rectangle will not cause camera moving. * Sprite moving inside this Rectangle will not cause camera moving.
* @type {Rectangle} * @property deadzone
* @type {Phaser.Rectangle}
*/ */
this.deadzone = null; this.deadzone = null;
/** /**
* Whether this camera is visible or not. (default is true) * Whether this camera is visible or not. (default is true)
* @property visible
* @public
* @default true
* @type {bool} * @type {bool}
*/ */
this.visible = true; this.visible = true;
/** /**
* Whether this camera is flush with the World Bounds or not. * Whether this camera is flush with the World Bounds or not.
* @property atLimit
* @type {bool} * @type {bool}
*/ */
this.atLimit = { x: false, y: false }; this.atLimit = { x: false, y: false };
/** /**
* If the camera is tracking a Sprite, this is a reference to it, otherwise null * If the camera is tracking a Sprite, this is a reference to it, otherwise null
* @type {Sprite} * @property target
* @public
* @type {Phaser.Sprite}
*/ */
this.target = null; this.target = null;
/**
* Edge property
* @property edge
* @private
* @type {number}
*/
this._edge = 0; this._edge = 0;
}; };
@@ -74,8 +116,9 @@ Phaser.Camera.prototype = {
/** /**
* Tells this camera which sprite to follow. * Tells this camera which sprite to follow.
* @param target {Sprite} The object you want the camera to track. Set to null to not follow anything. * @method follow
* @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow(). * @param {Phaser.Sprite} target The object you want the camera to track. Set to null to not follow anything.
* @param {number} [style] Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
*/ */
follow: function (target, style) { follow: function (target, style) {
@@ -112,9 +155,10 @@ Phaser.Camera.prototype = {
}, },
/** /**
* Move the camera focus to this location instantly. * Move the camera focus to a location instantly.
* @param x {number} X position. * @method focusOnXY
* @param y {number} Y position. * @param {number} x X position.
* @param {number} y Y position.
*/ */
focusOnXY: function (x, y) { focusOnXY: function (x, y) {
@@ -125,6 +169,7 @@ Phaser.Camera.prototype = {
/** /**
* Update focusing and scrolling. * Update focusing and scrolling.
* @method update
*/ */
update: function () { update: function () {
@@ -172,6 +217,10 @@ Phaser.Camera.prototype = {
}, },
/**
* Method called to ensure the camera doesn't venture outside of the game world
* @method checkWorldBounds
*/
checkWorldBounds: function () { checkWorldBounds: function () {
this.atLimit.x = false; this.atLimit.x = false;
@@ -206,6 +255,14 @@ Phaser.Camera.prototype = {
}, },
/**
* A helper function to set both the X and Y properties of the camera at once
* without having to use game.camera.x and game.camera.y
*
* @method setPosition
* @param {number} x X position.
* @param {number} y Y position.
*/
setPosition: function (x, y) { setPosition: function (x, y) {
this.view.x = x; this.view.x = x;
@@ -214,6 +271,13 @@ Phaser.Camera.prototype = {
}, },
/**
* Sets the size of the view rectangle given the width and height in parameters
*
* @method setSize
* @param {number} width The desired width.
* @param {number} height The desired height.
*/
setSize: function (width, height) { setSize: function (width, height) {
this.view.width = width; this.view.width = width;
@@ -225,10 +289,17 @@ Phaser.Camera.prototype = {
Object.defineProperty(Phaser.Camera.prototype, "x", { Object.defineProperty(Phaser.Camera.prototype, "x", {
/**
* @method x
* @return {Number} The x position
*/
get: function () { get: function () {
return this.view.x; return this.view.x;
}, },
/**
* @method x
* @return {Number} Sets the camera's x position and clamp it if it's outside the world bounds
*/
set: function (value) { set: function (value) {
this.view.x = value; this.view.x = value;
this.checkWorldBounds(); this.checkWorldBounds();
@@ -238,10 +309,18 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
Object.defineProperty(Phaser.Camera.prototype, "y", { Object.defineProperty(Phaser.Camera.prototype, "y", {
/**
* @method y
* @return {Number} The y position
*/
get: function () { get: function () {
return this.view.y; return this.view.y;
}, },
/**
* @method y
* @return {Number} Sets the camera's y position and clamp it if it's outside the world bounds
*/
set: function (value) { set: function (value) {
this.view.y = value; this.view.y = value;
this.checkWorldBounds(); this.checkWorldBounds();
@@ -251,10 +330,18 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
Object.defineProperty(Phaser.Camera.prototype, "width", { Object.defineProperty(Phaser.Camera.prototype, "width", {
/**
* @method width
* @return {Number} The width of the view rectangle, in pixels
*/
get: function () { get: function () {
return this.view.width; return this.view.width;
}, },
/**
* @method width
* @return {Number} Sets the width of the view rectangle
*/
set: function (value) { set: function (value) {
this.view.width = value; this.view.width = value;
} }
@@ -263,10 +350,18 @@ Object.defineProperty(Phaser.Camera.prototype, "width", {
Object.defineProperty(Phaser.Camera.prototype, "height", { Object.defineProperty(Phaser.Camera.prototype, "height", {
/**
* @method height
* @return {Number} The height of the view rectangle, in pixels
*/
get: function () { get: function () {
return this.view.height; return this.view.height;
}, },
/**
* @method height
* @return {Number} Sets the height of the view rectangle
*/
set: function (value) { set: function (value) {
this.view.height = value; this.view.height = value;
} }
+33 -50
View File
@@ -273,54 +273,6 @@ Phaser.Group.prototype = {
}, },
/**
* Call this function to sort the group according to a particular value and order.
* For example, to sort game objects for Zelda-style overlaps you might call
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
* <code>State.update()</code> override. To sort all existing objects after
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
*
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "z".
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
*/
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.c
sort: function (index, order) {
// if (typeof index === "undefined") { index = 'z'; }
// if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
// var _this = this;
// this._sortIndex = index;
// this._sortOrder = order;
// this.members.sort(function (a, b) {
// return _this.sortHandler(a, b);
// });
},
/**
* Helper function for the sort process.
*
* @param {Basic} Obj1 The first object being sorted.
* @param {Basic} Obj2 The second object being sorted.
*
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
*/
sortHandler: function (obj1, obj2) {
/*
if (!obj1 || !obj2) {
//console.log('null objects in sort', obj1, obj2);
return 0;
}
if (obj1[this._sortIndex] < obj2[this._sortIndex]) {
return this._sortOrder;
} else if (obj1[this._sortIndex] > obj2[this._sortIndex]) {
return -this._sortOrder;
}
return 0;
*/
},
// key is an ARRAY of values. // key is an ARRAY of values.
setProperty: function (child, key, value, operation) { setProperty: function (child, key, value, operation) {
@@ -424,8 +376,31 @@ Phaser.Group.prototype = {
}, },
callAllExists: function (callback, callbackContext, existsValue) {
var args = Array.prototype.splice.call(arguments, 3);
if (this._container.children.length > 0 && this._container.first._iNext)
{
var currentNode = this._container.first._iNext;
do
{
if (currentNode.exists == existsValue && currentNode[callback])
{
currentNode[callback].apply(currentNode, args);
}
currentNode = currentNode._iNext;
}
while (currentNode != this._container.last._iNext)
}
},
/** /**
* Calls a function on all of the active children (children with exists=true). * Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that)
* You must pass the context in which the callback is applied. * You must pass the context in which the callback is applied.
* After the context you can add as many parameters as you like, which will all be passed to the child. * After the context you can add as many parameters as you like, which will all be passed to the child.
*/ */
@@ -439,7 +414,7 @@ Phaser.Group.prototype = {
do do
{ {
if (currentNode.exists && currentNode[callback]) if (currentNode[callback])
{ {
currentNode[callback].apply(currentNode, args); currentNode[callback].apply(currentNode, args);
} }
@@ -832,6 +807,14 @@ Phaser.Group.prototype = {
}; };
Object.defineProperty(Phaser.Group.prototype, "length", {
get: function () {
return this._container.children.length;
}
});
Object.defineProperty(Phaser.Group.prototype, "x", { Object.defineProperty(Phaser.Group.prototype, "x", {
get: function () { get: function () {
+78 -19
View File
@@ -1,49 +1,97 @@
/** /**
* Stage * @author Richard Davey <rich@photonstorm.com>
* * @copyright 2013 Photon Storm Ltd.
* The Stage controls the canvas on which everything is displayed. It handles display within the browser, * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* focus handling, game resizing, scaling and the pause, boot and orientation screens. * @module Phaser.Stage
* */
* @package Phaser.Stage
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
/**
*
* The Stage controls the canvas on which everything is displayed. It handles display within the browser,
* focus handling, game resizing, scaling and the pause, boot and orientation screens.
*
* @class Stage * @class Stage
* @constructor * @constructor
* @param game {Phaser.Game} game reference to the currently running game. * @param {Phaser.Game} game Game reference to the currently running game.
* @param width {number} width of the canvas element * @param {number} width Width of the canvas element
* @param height {number} height of the canvas element * @param {number} height Height of the canvas element
*/ */
Phaser.Stage = function (game, width, height) { Phaser.Stage = function (game, width, height) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
this.game = game; this.game = game;
/** /**
* Background color of the stage (defaults to black). Set via the public backgroundColor property. * Background color of the stage (defaults to black). Set via the public backgroundColor property.
* @property _backgroundColor
* @private
* @type {string} * @type {string}
*/ */
this._backgroundColor = 'rgb(0,0,0)'; this._backgroundColor = 'rgb(0,0,0)';
// Get the offset values (for input and other things) /**
* Get the offset values (for input and other things)
* @property offset
* @public
* @type {Phaser.Point}
*/
this.offset = new Phaser.Point; this.offset = new Phaser.Point;
/**
* reference to the newly created <canvas> element
* @property canvas
* @public
* @type {HTMLCanvasElement}
*/
this.canvas = Phaser.Canvas.create(width, height); this.canvas = Phaser.Canvas.create(width, height);
this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
// The Pixi Stage which is hooked to the renderer /**
* The Pixi Stage which is hooked to the renderer
* @property _stage
* @private
* @type {PIXI.Stage}
*/
this._stage = new PIXI.Stage(0x000000, false); this._stage = new PIXI.Stage(0x000000, false);
this._stage.name = '_stage_root'; this._stage.name = '_stage_root';
/**
* The current scaleMode
* @property scaleMode
* @public
* @type {number}
*/
this.scaleMode = Phaser.StageScaleMode.NO_SCALE; this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
/**
* The scale of the current running game
* @property scale
* @public
* @type {Phaser.StageScaleMode}
*/
this.scale = new Phaser.StageScaleMode(this.game, width, height); this.scale = new Phaser.StageScaleMode(this.game, width, height);
/**
* aspect ratio
* @property aspectRatio
* @public
* @type {number}
*/
this.aspectRatio = width / height; this.aspectRatio = width / height;
}; };
Phaser.Stage.prototype = { Phaser.Stage.prototype = {
/**
* Initialises the stage and adds the event listeners
* @method boot
*/
boot: function () { boot: function () {
Phaser.Canvas.getOffset(this.canvas, this.offset); Phaser.Canvas.getOffset(this.canvas, this.offset);
@@ -68,6 +116,8 @@ Phaser.Stage.prototype = {
/** /**
* This method is called when the document visibility is changed. * This method is called when the document visibility is changed.
* @method visibilityChange
* @param {Event} event Its type will be used to decide whether the game should be paused or not
*/ */
visibilityChange: function (event) { visibilityChange: function (event) {
@@ -93,10 +143,19 @@ Phaser.Stage.prototype = {
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", { Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
/**
* @method backgroundColor
* @return {string} returns the background color of the stage
*/
get: function () { get: function () {
return this._backgroundColor; return this._backgroundColor;
}, },
/**
* @method backgroundColor
* @param {string} the background color you want the stage to have
* @return {string} returns the background color of the stage
*/
set: function (color) { set: function (color) {
this._backgroundColor = color; this._backgroundColor = color;
+76 -25
View File
@@ -1,5 +1,11 @@
/** /**
* World * @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser.World
*/
/**
* *
* "This world is but a canvas to our imagination." - Henry David Thoreau * "This world is but a canvas to our imagination." - Henry David Thoreau
* *
@@ -7,50 +13,62 @@
* by stage limits and can be any size. You look into the world via cameras. All game objects live within * by stage limits and can be any size. You look into the world via cameras. All game objects live within
* the world at world-based coordinates. By default a world is created the same size as your Stage. * the world at world-based coordinates. By default a world is created the same size as your Stage.
* *
* @package Phaser.World
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @class World * @class World
* @constructor * @constructor
* @param game {Phaser.Game} reference to the current game instance. * @param {Phaser.Game} game Reference to the current game instance.
*/ */
Phaser.World = function (game) { Phaser.World = function (game) {
/** /**
* Local reference to Game. * A reference to the currently running Game.
*/ * @property game
* @public
* @type {Phaser.Game}
*/
this.game = game; this.game = game;
/** /**
* Bound of this world that objects can not escape from. * Bound of this world that objects can not escape from.
* @type {Rectangle} * @property bounds
*/ * @public
* @type {Phaser.Rectangle}
*/
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height); this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
/** /**
* Camera instance. * Camera instance.
* @type {Camera} * @property camera
*/ * @public
* @type {Phaser.Camera}
*/
this.camera = null; this.camera = null;
/** /**
* Reset each frame, keeps a count of the total number of objects updated. * Reset each frame, keeps a count of the total number of objects updated.
* @type {Number} * @property currentRenderOrderID
*/ * @public
* @type {Number}
*/
this.currentRenderOrderID = 0; this.currentRenderOrderID = 0;
/** /**
* Object container stores every object created with `create*` methods. * Object container stores every object created with `create*` methods.
* @type {Group} * @property group
*/ * @public
* @type {Phaser.Group}
*/
this.group = null; this.group = null;
}; };
Phaser.World.prototype = { Phaser.World.prototype = {
/**
* Initialises the game world
*
* @method boot
*/
boot: function () { boot: function () {
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height); this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
@@ -62,8 +80,9 @@ Phaser.World.prototype = {
}, },
/** /**
* This is called automatically every frame, and is where main logic happens. * This is called automatically every frame, and is where main logic happens.
*/ * @method update
*/
update: function () { update: function () {
this.camera.update(); this.camera.update();
@@ -96,8 +115,8 @@ Phaser.World.prototype = {
/** /**
* Updates the size of this world. * Updates the size of this world.
* @method setSize * @method setSize
* @param width {number} New width of the world. * @param {number} width New width of the world.
* @param height {number} New height of the world. * @param {number} height New height of the world.
*/ */
setSize: function (width, height) { setSize: function (width, height) {
@@ -134,10 +153,18 @@ Phaser.World.prototype = {
Object.defineProperty(Phaser.World.prototype, "width", { Object.defineProperty(Phaser.World.prototype, "width", {
/**
* @method width
* @return {Number} The current width of the game world
*/
get: function () { get: function () {
return this.bounds.width; return this.bounds.width;
}, },
/**
* @method width
* @return {Number} Sets the width of the game world
*/
set: function (value) { set: function (value) {
this.bounds.width = value; this.bounds.width = value;
} }
@@ -146,10 +173,18 @@ Object.defineProperty(Phaser.World.prototype, "width", {
Object.defineProperty(Phaser.World.prototype, "height", { Object.defineProperty(Phaser.World.prototype, "height", {
/**
* @method height
* @return {Number} The current height of the game world
*/
get: function () { get: function () {
return this.bounds.height; return this.bounds.height;
}, },
/**
* @method height
* @return {Number} Sets the width of the game world
*/
set: function (value) { set: function (value) {
this.bounds.height = value; this.bounds.height = value;
} }
@@ -158,6 +193,10 @@ Object.defineProperty(Phaser.World.prototype, "height", {
Object.defineProperty(Phaser.World.prototype, "centerX", { Object.defineProperty(Phaser.World.prototype, "centerX", {
/**
* @method centerX
* @return {Number} return the X position of the center point of the world
*/
get: function () { get: function () {
return this.bounds.halfWidth; return this.bounds.halfWidth;
} }
@@ -166,6 +205,10 @@ Object.defineProperty(Phaser.World.prototype, "centerX", {
Object.defineProperty(Phaser.World.prototype, "centerY", { Object.defineProperty(Phaser.World.prototype, "centerY", {
/**
* @method centerY
* @return {Number} return the Y position of the center point of the world
*/
get: function () { get: function () {
return this.bounds.halfHeight; return this.bounds.halfHeight;
} }
@@ -174,6 +217,10 @@ Object.defineProperty(Phaser.World.prototype, "centerY", {
Object.defineProperty(Phaser.World.prototype, "randomX", { Object.defineProperty(Phaser.World.prototype, "randomX", {
/**
* @method randomX
* @return {Number} a random integer which is lesser or equal to the current width of the game world
*/
get: function () { get: function () {
return Math.round(Math.random() * this.bounds.width); return Math.round(Math.random() * this.bounds.width);
} }
@@ -182,6 +229,10 @@ Object.defineProperty(Phaser.World.prototype, "randomX", {
Object.defineProperty(Phaser.World.prototype, "randomY", { Object.defineProperty(Phaser.World.prototype, "randomY", {
/**
* @method randomY
* @return {Number} a random integer which is lesser or equal to the current height of the game world
*/
get: function () { get: function () {
return Math.round(Math.random() * this.bounds.height); return Math.round(Math.random() * this.bounds.height);
} }
+20 -13
View File
@@ -1,20 +1,28 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser.Button
*/
/** /**
* Create a new <code>Button</code> object. * Create a new <code>Button</code> object.
* @class Button * @class Button
* @constructor * @constructor
* *
* @param game {Phaser.Game} Current game instance. * @param {Phaser.Game} game Current game instance.
* @param [x] {number} X position of the button. * @param {number} [x] X position of the button.
* @param [y] {number} Y position of the button. * @param {number} [y] Y position of the button.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button. * @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
* @param [callback] {function} The function to call when this button is pressed * @param {function} [callback] The function to call when this button is pressed
* @param [callbackContext] {object} The context in which the callback will be called (usually 'this') * @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
*/ */
Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
x = x || 0; x = x || 0;
y = y || 0; y = y || 0;
key = key || null; key = key || null;
@@ -65,11 +73,10 @@ Phaser.Button.prototype.constructor = Phaser.Button;
* exactly like setting them in the constructor * exactly like setting them in the constructor
* *
* @method setFrames * @method setFrames
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. * @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
*/ */
Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
if (overFrame !== null) if (overFrame !== null)
+2
View File
@@ -9,6 +9,8 @@ Phaser.RenderTexture = function (game, key, width, height) {
this.width = width || 100; this.width = width || 100;
this.height = height || 100; this.height = height || 100;
// I know this has a typo in it, but it's because the PIXI.RenderTexture does and we need to pair-up with it
// once they update pixi to fix the typo, we'll fix it here too :)
this.indetityMatrix = PIXI.mat3.create(); this.indetityMatrix = PIXI.mat3.create();
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
+77 -65
View File
@@ -214,6 +214,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
// If this sprite or the camera have moved then let's update everything // If this sprite or the camera have moved then let's update everything
// Note: The actual position shouldn't be changed if this item is inside a Group?
if (this.position.x != this._cache.x || this.position.y != this._cache.y) if (this.position.x != this._cache.x || this.position.y != this._cache.y)
{ {
this.position.x = this._cache.x; this.position.x = this._cache.x;
@@ -224,76 +225,77 @@ Phaser.Sprite.prototype.preUpdate = function() {
if (this.visible) if (this.visible)
{ {
this.renderOrderID = this.game.world.currentRenderOrderID++; this.renderOrderID = this.game.world.currentRenderOrderID++;
// |a c tx|
// |b d ty|
// |0 0 1|
// Only update the values we need
if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01)
{
this._cache.a00 = this.worldTransform[0]; // scaleX a
this._cache.a01 = this.worldTransform[1]; // skewY c
this._cache.i01 = this.worldTransform[1]; // skewY c
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
this._cache.a01 *= -1;
this._cache.dirty = true;
}
// Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew
if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11)
{
this._cache.a10 = this.worldTransform[3]; // skewX b
this._cache.i10 = this.worldTransform[3]; // skewX b
this._cache.a11 = this.worldTransform[4]; // scaleY d
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
this._cache.a10 *= -1;
this._cache.dirty = true;
}
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
{
this._cache.a02 = this.worldTransform[2]; // translateX tx
this._cache.a12 = this.worldTransform[5]; // translateY ty
this._cache.dirty = true;
}
// Frame updated?
if (this.currentFrame.uuid != this._cache.frameID)
{
this._cache.frameWidth = this.texture.frame.width;
this._cache.frameHeight = this.texture.frame.height;
this._cache.frameID = this.currentFrame.uuid;
this._cache.dirty = true;
}
if (this._cache.dirty)
{
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
this._cache.halfWidth = Math.floor(this._cache.width / 2);
this._cache.halfHeight = Math.floor(this._cache.height / 2);
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
this.updateBounds();
}
} }
else
// |a c tx|
// |b d ty|
// |0 0 1|
// Only update the values we need
if (this.worldTransform[0] != this._cache.a00 || this.worldTransform[1] != this._cache.a01)
{ {
this._cache.a00 = this.worldTransform[0]; // scaleX a
this._cache.a01 = this.worldTransform[1]; // skewY c
this._cache.i01 = this.worldTransform[1]; // skewY c
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
this._cache.a01 *= -1;
this._cache.dirty = true;
}
// Need to test, but probably highly unlikely that a scaleX would happen without effecting the Y skew
if (this.worldTransform[3] != this._cache.a10 || this.worldTransform[4] != this._cache.a11)
{
this._cache.a10 = this.worldTransform[3]; // skewX b
this._cache.i10 = this.worldTransform[3]; // skewX b
this._cache.a11 = this.worldTransform[4]; // scaleY d
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
this._cache.a10 *= -1;
this._cache.dirty = true;
}
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
{
this._cache.a02 = this.worldTransform[2]; // translateX tx
this._cache.a12 = this.worldTransform[5]; // translateY ty
this._cache.dirty = true;
}
// Frame updated?
if (this.currentFrame.uuid != this._cache.frameID)
{
this._cache.frameWidth = this.texture.frame.width;
this._cache.frameHeight = this.texture.frame.height;
this._cache.frameID = this.currentFrame.uuid;
this._cache.dirty = true;
}
if (this._cache.dirty)
{
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
this._cache.halfWidth = Math.floor(this._cache.width / 2);
this._cache.halfHeight = Math.floor(this._cache.height / 2);
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
this.updateBounds();
}
// }
// else
// {
// We still need to work out the bounds in case the camera has moved // We still need to work out the bounds in case the camera has moved
// but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible. // but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible.
// So we'll compare against the cached state + new position. // So we'll compare against the cached state + new position.
if (this._cache.dirty && this.visible == false) // if (this._cache.dirty && this.visible == false)
{ // {
this.bounds.x -= this._cache.boundsX - this._cache.x; // this.bounds.x -= this._cache.boundsX - this._cache.x;
this._cache.boundsX = this._cache.x; // this._cache.boundsX = this._cache.x;
this.bounds.y -= this._cache.boundsY - this._cache.y; // this.bounds.y -= this._cache.boundsY - this._cache.y;
this._cache.boundsY = this._cache.y; // this._cache.boundsY = this._cache.y;
} // }
} // }
// Re-run the camera visibility check // Re-run the camera visibility check
if (this._cache.dirty) if (this._cache.dirty)
@@ -302,7 +304,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
if (this.autoCull == true) if (this.autoCull == true)
{ {
this.visible = this._cache.cameraVisible; // Won't get rendered but will still get its transform updated
this.renderable = this._cache.cameraVisible;
} }
// Update our physics bounds // Update our physics bounds
@@ -313,6 +316,15 @@ Phaser.Sprite.prototype.preUpdate = function() {
} }
Phaser.Sprite.prototype.postUpdate = function() {
if (this.exists)
{
this.body.postUpdate();
}
}
/** /**
* Moves the sprite so its center is located on the given x and y coordinates. * Moves the sprite so its center is located on the given x and y coordinates.
* Doesn't change the origin of the sprite. * Doesn't change the origin of the sprite.
+25 -8
View File
@@ -17,12 +17,15 @@ Phaser.Text = function (game, x, y, text, style) {
this.game = game; this.game = game;
this._text = text;
this._style = style;
PIXI.Text.call(this, text, style); PIXI.Text.call(this, text, style);
this.type = Phaser.TEXT; this.type = Phaser.TEXT;
this.position.x = x; this.position.x = this.x = x;
this.position.y = y; this.position.y = this.y = y;
// Replaces the PIXI.Point with a slightly more flexible one // Replaces the PIXI.Point with a slightly more flexible one
this.anchor = new Phaser.Point(); this.anchor = new Phaser.Point();
@@ -91,26 +94,40 @@ Object.defineProperty(Phaser.Text.prototype, 'angle', {
}); });
Object.defineProperty(Phaser.Text.prototype, 'x', { Object.defineProperty(Phaser.Text.prototype, 'text', {
get: function() { get: function() {
return this.position.x; return this._text;
}, },
set: function(value) { set: function(value) {
this.position.x = value;
// Let's not update unless needed, this way we can safely update the text in a core loop without constant re-draws
if (value !== this._text)
{
this._text = value;
this.dirty = true;
}
} }
}); });
Object.defineProperty(Phaser.Text.prototype, 'y', { Object.defineProperty(Phaser.Text.prototype, 'style', {
get: function() { get: function() {
return this.position.y; return this._style;
}, },
set: function(value) { set: function(value) {
this.position.y = value;
// Let's not update unless needed, this way we can safely update the text in a core loop without constant re-draws
if (value !== this._style)
{
this._style = value;
this.dirty = true;
}
} }
}); });
+20
View File
@@ -323,6 +323,26 @@ Phaser.Math = {
} }
} }
},
/**
* Returns an Array containing the numbers from min to max (inclusive)
*
* @param min The minimum value the array starts with
* @param max The maximum value the array contains
* @return The array of number values
*/
numberArray: function (min, max) {
var result = [];
for (var i = min; i <= max; i++)
{
result.push(i);
}
return result;
}, },
/** /**
+15 -3
View File
@@ -7,6 +7,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this.x = sprite.x; this.x = sprite.x;
this.y = sprite.y; this.y = sprite.y;
this.lastX = sprite.x;
this.lastY = sprite.y;
// un-scaled original size // un-scaled original size
this.sourceWidth = sprite.currentFrame.sourceSizeW; this.sourceWidth = sprite.currentFrame.sourceSizeW;
@@ -62,9 +64,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this.collideWorldBounds = false; this.collideWorldBounds = false;
this.lastX = sprite.x;
this.lastY = sprite.y;
}; };
Phaser.Physics.Arcade.Body.prototype = { Phaser.Physics.Arcade.Body.prototype = {
@@ -102,8 +101,11 @@ Phaser.Physics.Arcade.Body.prototype = {
this.lastY = this.y; this.lastY = this.y;
this.rotation = this.sprite.angle; this.rotation = this.sprite.angle;
// There is a bug here in that the worldTransform values are what should be used, otherwise the quadTree gets the wrong rect given to it
this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x; this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y; this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
// this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
// this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
if (this.moves) if (this.moves)
{ {
@@ -122,6 +124,16 @@ Phaser.Physics.Arcade.Body.prototype = {
this.game.physics.quadTree.insert(this); this.game.physics.quadTree.insert(this);
} }
if (this.deltaX() != 0)
{
this.sprite.x -= this.deltaX();
}
if (this.deltaY() != 0)
{
this.sprite.y -= this.deltaY();
}
// Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update // Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width); this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height); this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
+107 -13
View File
@@ -3,26 +3,70 @@
* *
* @class Sound * @class Sound
* @constructor * @constructor
* @param game {Phaser.Game} reference to the current game instance. * @param {Phaser.Game} game Reference to the current game instance.
* @param key {string} Asset key for the sound. * @param {string} key Asset key for the sound.
* @param volume {number} default value for the volume. * @param {number} volume Default value for the volume.
* @param loop {bool} Whether or not the sound will loop. * @param {bool} loop Whether or not the sound will loop.
*/ */
Phaser.Sound = function (game, key, volume, loop) { Phaser.Sound = function (game, key, volume, loop) {
volume = volume || 1; volume = volume || 1;
if (typeof loop == 'undefined') { loop = false; } if (typeof loop == 'undefined') { loop = false; }
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
this.game = game; this.game = game;
/**
* Name of the sound
* @property name
* @public
* @type {string}
*/
this.name = ''; this.name = '';
/**
* Asset key for the sound.
* @property key
* @public
* @type {string}
*/
this.key = key; this.key = key;
/**
* Whether or not the sound will loop.
* @property loop
* @public
* @type {bool}
*/
this.loop = loop; this.loop = loop;
/**
* The global audio volume. A value between 0 (silence) and 1 (full volume)
* @property _volume
* @private
* @type {number}
*/
this._volume = volume; this._volume = volume;
/**
* The sound markers, empty by default
* @property markers
* @public
* @type {object}
*/
this.markers = {}; this.markers = {};
/** /**
* Reference to AudioContext instance. * Reference to AudioContext instance.
* @property context
* @public
* @type {AudioContext}
*/ */
this.context = null; this.context = null;
@@ -31,9 +75,28 @@ Phaser.Sound = function (game, key, volume, loop) {
*/ */
this._buffer = null; this._buffer = null;
/**
* Boolean indicating whether the game is on "mute"
* @property _muted
* @private
* @type {bool}
*/
this._muted = false; this._muted = false;
/**
* Boolean indicating whether the sound should start automatically
* @property autoplay
* @public
* @type {bool}
*/
this.autoplay = false; this.autoplay = false;
/**
* The total duration of the sound, in milliseconds
* @property autoplay
* @public
* @type {bool}
*/
this.totalDuration = 0; this.totalDuration = 0;
this.startTime = 0; this.startTime = 0;
this.currentTime = 0; this.currentTime = 0;
@@ -188,11 +251,11 @@ Phaser.Sound.prototype = {
/** /**
* Play this sound, or a marked section of it. * Play this sound, or a marked section of it.
* @method play
* @param marker {string} Assets key of the sound you want to play. * @param {string} marker Assets key of the sound you want to play.
* @param position {number} the starting position * @param {number} position The starting position
* @param [volume] {number} volume of the sound you want to play. * @param {number} [volume] Volume of the sound you want to play.
* @param [loop] {bool} loop when it finished playing? (Default to false) * @param {bool} [loop] Loop when it finished playing? (Default to false)
* @return {Sound} The playing sound object. * @return {Sound} The playing sound object.
*/ */
play: function (marker, position, volume, loop, forceRestart) { play: function (marker, position, volume, loop, forceRestart) {
@@ -366,6 +429,14 @@ Phaser.Sound.prototype = {
} }
}, },
/**
* Restart the sound, or a marked section of it.
* @method restart
* @param {string} marker Assets key of the sound you want to play.
* @param {number} position The starting position
* @param {number} [volume] Volume of the sound you want to play.
* @param {bool} [loop] Loop when it finished playing? (Default to false)
*/
restart: function (marker, position, volume, loop) { restart: function (marker, position, volume, loop) {
marker = marker || ''; marker = marker || '';
@@ -377,6 +448,10 @@ Phaser.Sound.prototype = {
}, },
/**
* Pauses the sound
* @method pause
*/
pause: function () { pause: function () {
if (this.isPlaying && this._sound) if (this.isPlaying && this._sound)
@@ -388,7 +463,10 @@ Phaser.Sound.prototype = {
} }
}, },
/**
* Resumes the sound
* @method pause
*/
resume: function () { resume: function () {
if (this.paused && this._sound) if (this.paused && this._sound)
@@ -419,6 +497,7 @@ Phaser.Sound.prototype = {
/** /**
* Stop playing this sound. * Stop playing this sound.
* @method stop
*/ */
stop: function () { stop: function () {
@@ -470,13 +549,20 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
Object.defineProperty(Phaser.Sound.prototype, "mute", { Object.defineProperty(Phaser.Sound.prototype, "mute", {
/**
* Mute sounds. /**
* Mutes sound.
* @method mute
* @return {bool} whether or not the sound is muted
*/ */
get: function () { get: function () {
return this._muted; return this._muted;
}, },
/**
* Mutes sound.
* @method mute
* @return {bool} whether or not the sound is muted
*/
set: function (value) { set: function (value) {
value = value || null; value = value || null;
@@ -518,10 +604,18 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", {
Object.defineProperty(Phaser.Sound.prototype, "volume", { Object.defineProperty(Phaser.Sound.prototype, "volume", {
/**
* @method volume
* @return {number} The current volume. A value between 0 (silence) and 1 (full volume)
*/
get: function () { get: function () {
return this._volume; return this._volume;
}, },
/**
* @method volume
* @return {number} Sets the current volume. A value between 0 (silence) and 1 (full volume)
*/
set: function (value) { set: function (value) {
if (this.usingWebAudio) if (this.usingWebAudio)
+73 -11
View File
@@ -3,20 +3,47 @@
* *
* @class SoundManager * @class SoundManager
* @constructor * @constructor
* @param game {Phaser.Game} reference to the current game instance. * @param {Phaser.Game} game reference to the current game instance.
*/ */
Phaser.SoundManager = function (game) { Phaser.SoundManager = function (game) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
this.game = game; this.game = game;
this.onSoundDecode = new Phaser.Signal; this.onSoundDecode = new Phaser.Signal;
/**
* Boolean indicating whether the game is on "mute"
* @property _muted
* @private
* @type {bool}
*/
this._muted = false; this._muted = false;
this._unlockSource = null; this._unlockSource = null;
/**
* The global audio volume. A value between 0 (silence) and 1 (full volume)
* @property _volume
* @private
* @type {number}
*/
this._volume = 1; this._volume = 1;
this._muted = false;
/**
* An array containing all the sounds
* @property _sounds
* @private
* @type {array}
*/
this._sounds = []; this._sounds = [];
this.context = null; this.context = null;
this.usingWebAudio = true; this.usingWebAudio = true;
this.usingAudioTag = false; this.usingAudioTag = false;
@@ -30,6 +57,10 @@ Phaser.SoundManager = function (game) {
Phaser.SoundManager.prototype = { Phaser.SoundManager.prototype = {
/**
* Initialises the sound manager
* @method boot
*/
boot: function () { boot: function () {
if (this.game.device.iOS && this.game.device.webAudio == false) if (this.game.device.iOS && this.game.device.webAudio == false)
@@ -108,6 +139,10 @@ Phaser.SoundManager.prototype = {
}, },
/**
* Enables the audio, usually after the first touch
* @method unlock
*/
unlock: function () { unlock: function () {
if (this.touchLocked == false) if (this.touchLocked == false)
@@ -138,6 +173,10 @@ Phaser.SoundManager.prototype = {
}, },
/**
* Stops all the sounds in the game
* @method stopAll
*/
stopAll: function () { stopAll: function () {
for (var i = 0; i < this._sounds.length; i++) for (var i = 0; i < this._sounds.length; i++)
@@ -150,6 +189,10 @@ Phaser.SoundManager.prototype = {
}, },
/**
* Pauses all the sounds in the game
* @method pauseAll
*/
pauseAll: function () { pauseAll: function () {
for (var i = 0; i < this._sounds.length; i++) for (var i = 0; i < this._sounds.length; i++)
@@ -162,6 +205,10 @@ Phaser.SoundManager.prototype = {
}, },
/**
* resumes every sound in the game
* @method resumeAll
*/
resumeAll: function () { resumeAll: function () {
for (var i = 0; i < this._sounds.length; i++) for (var i = 0; i < this._sounds.length; i++)
@@ -176,8 +223,9 @@ Phaser.SoundManager.prototype = {
/** /**
* Decode a sound with its assets key. * Decode a sound with its assets key.
* @method decode
* @param key {string} Assets key of the sound to be decoded. * @param key {string} Assets key of the sound to be decoded.
* @param [sound] {Sound} its bufer will be set to decoded data. * @param [sound] {Phaser.Sound} its bufer will be set to decoded data.
*/ */
decode: function (key, sound) { decode: function (key, sound) {
@@ -205,6 +253,10 @@ Phaser.SoundManager.prototype = {
}, },
/**
* updates every sound in the game
* @method update
*/
update: function () { update: function () {
if (this.touchLocked) if (this.touchLocked)
@@ -232,11 +284,10 @@ Phaser.SoundManager.prototype = {
/** /**
* *
* @method add * @method add
* @param key {string} Asset key for the sound. * @param {string} key Asset key for the sound.
* @param volume {number} default value for the volume. * @param {number} volume Default value for the volume.
* @param loop {bool} Whether or not the sound will loop. * @param {bool} loop Whether or not the sound will loop.
*/ */
add: function (key, volume, loop) { add: function (key, volume, loop) {
volume = volume || 1; volume = volume || 1;
@@ -258,6 +309,8 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
/** /**
* A global audio mute toggle. * A global audio mute toggle.
* @method mute
* @return {bool} whether or not the game is on "mute"
*/ */
get: function () { get: function () {
@@ -265,6 +318,11 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
}, },
/**
* Mute sounds.
* @method mute
* @return {bool} whether or not the game is on "mute"
*/
set: function (value) { set: function (value) {
value = value || null; value = value || null;
@@ -316,14 +374,16 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
} }
} }
} }
}, }
enumerable: true,
configurable: true
}); });
Object.defineProperty(Phaser.SoundManager.prototype, "volume", { Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
/**
* @method volume
* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume)
*/
get: function () { get: function () {
if (this.usingWebAudio) if (this.usingWebAudio)
@@ -338,7 +398,9 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", {
}, },
/** /**
* The global audio volume. A value between 0 (silence) and 1 (full volume) * Sets the global volume
* @method volume
* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume)
*/ */
set: function (value) { set: function (value) {
+19 -1
View File
@@ -5,8 +5,22 @@
* @module Phaser.Canvas * @module Phaser.Canvas
*/ */
Phaser.Canvas = { /**
* The Canvas class handles everything related to the <canvas> tag as a DOM Element, like styles, offset, aspect ratio
*
* @class Canvas
* @static
*/
Phaser.Canvas = {
/**
* Creates the <canvas> tag
*
* @method create
* @param {number} width The desired width
* @param {number} height The desired height
* @return {HTMLCanvasElement} the newly created <canvas> tag
*/
create: function (width, height) { create: function (width, height) {
width = width || 256; width = width || 256;
@@ -23,6 +37,10 @@ Phaser.Canvas = {
/** /**
* Get the DOM offset values of any given element * Get the DOM offset values of any given element
* @method getOffset
* @param {HTMLElement} element The targeted element that we want to retrieve the offset
* @param {Phaser.Point} [point] The point we want to take the x/y values of the offset
* @return point {Phaser.Point} A point objet with the offsetX and Y as its properties
*/ */
getOffset: function (element, point) { getOffset: function (element, point) {
+10 -3
View File
@@ -36,6 +36,8 @@ Phaser.Tween = function (object, game) {
this._pausedTime = 0; this._pausedTime = 0;
this.pendingDelete = false;
// Set all starting values present on the target object // Set all starting values present on the target object
for ( var field in object ) { for ( var field in object ) {
this._valuesStart[ field ] = parseFloat(object[field], 10); this._valuesStart[ field ] = parseFloat(object[field], 10);
@@ -190,21 +192,21 @@ Phaser.Tween.prototype = {
}, },
onStart: function ( callback ) { onStartCallback: function ( callback ) {
this._onStartCallback = callback; this._onStartCallback = callback;
return this; return this;
}, },
onUpdate: function ( callback ) { onUpdateCallback: function ( callback ) {
this._onUpdateCallback = callback; this._onUpdateCallback = callback;
return this; return this;
}, },
onComplete: function ( callback ) { onCompleteCallback: function ( callback ) {
this._onCompleteCallback = callback; this._onCompleteCallback = callback;
return this; return this;
@@ -222,6 +224,11 @@ Phaser.Tween.prototype = {
update: function ( time ) { update: function ( time ) {
if (this.pendingDelete)
{
return false;
}
if (this._paused || time < this._startTime) { if (this._paused || time < this._startTime) {
return true; return true;
+13 -4
View File
@@ -13,6 +13,7 @@ Phaser.TweenManager = function (game) {
this.game = game; this.game = game;
this._tweens = []; this._tweens = [];
this._add = [];
this.game.onPause.add(this.pauseAll, this); this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this); this.game.onResume.add(this.resumeAll, this);
@@ -50,7 +51,7 @@ Phaser.TweenManager.prototype = {
*/ */
add: function ( tween ) { add: function ( tween ) {
this._tweens.push( tween ); this._add.push( tween );
}, },
@@ -77,7 +78,7 @@ Phaser.TweenManager.prototype = {
if ( i !== -1 ) { if ( i !== -1 ) {
this._tweens.splice( i, 1 ); this._tweens[i].pendingDelete = true;
} }
@@ -90,9 +91,10 @@ Phaser.TweenManager.prototype = {
*/ */
update: function () { update: function () {
if ( this._tweens.length === 0 ) return false; if ( this._tweens.length === 0 && this._add.length === 0 ) return false;
var i = 0, numTweens = this._tweens.length; var i = 0;
var numTweens = this._tweens.length;
while ( i < numTweens ) { while ( i < numTweens ) {
@@ -110,6 +112,13 @@ Phaser.TweenManager.prototype = {
} }
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
if (this._add.length > 0)
{
this._tweens = this._tweens.concat(this._add);
this._add.length = 0;
}
return true; return true;
}, },
+45 -5
View File
@@ -119,6 +119,14 @@ Phaser.Utils.Debug.prototype = {
this.context.strokeStyle = color; this.context.strokeStyle = color;
this.context.strokeRect(bounds.x, bounds.y, bounds.width, bounds.height); this.context.strokeRect(bounds.x, bounds.y, bounds.width, bounds.height);
this.renderText(quadtree.ID + ' / ' + quadtree.objects.length, bounds.x + 4, bounds.y + 16, 'rgb(0,200,0)', '12px Courier'); this.renderText(quadtree.ID + ' / ' + quadtree.objects.length, bounds.x + 4, bounds.y + 16, 'rgb(0,200,0)', '12px Courier');
this.context.strokeStyle = 'rgb(0,255,0)';
// children
for (var i = 0; i < quadtree.objects.length; i++)
{
this.context.strokeRect(quadtree.objects[i].x, quadtree.objects[i].y, quadtree.objects[i].width, quadtree.objects[i].height);
}
} }
else else
{ {
@@ -374,6 +382,7 @@ Phaser.Utils.Debug.prototype = {
this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1)); this.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
this.line('visible: ' + sprite.visible); this.line('visible: ' + sprite.visible);
this.line('in camera: ' + sprite.inCamera); this.line('in camera: ' + sprite.inCamera);
this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1));
// 0 = scaleX // 0 = scaleX
// 1 = skewY // 1 = skewY
@@ -382,7 +391,6 @@ Phaser.Utils.Debug.prototype = {
// 4 = scaleY // 4 = scaleY
// 5 = translateY // 5 = translateY
// this.line('id: ' + sprite._id); // this.line('id: ' + sprite._id);
// this.line('scale x: ' + sprite.worldTransform[0]); // this.line('scale x: ' + sprite.worldTransform[0]);
// this.line('scale y: ' + sprite.worldTransform[4]); // this.line('scale y: ' + sprite.worldTransform[4]);
@@ -390,6 +398,8 @@ Phaser.Utils.Debug.prototype = {
// this.line('ty: ' + sprite.worldTransform[5]); // this.line('ty: ' + sprite.worldTransform[5]);
// this.line('skew x: ' + sprite.worldTransform[3]); // this.line('skew x: ' + sprite.worldTransform[3]);
// this.line('skew y: ' + sprite.worldTransform[1]); // this.line('skew y: ' + sprite.worldTransform[1]);
// this.line('dx: ' + sprite.body.deltaX());
// this.line('dy: ' + sprite.body.deltaY());
// this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite)); // this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite));
@@ -454,18 +464,48 @@ Phaser.Utils.Debug.prototype = {
}, },
renderSpriteBounds: function (sprite, color) { renderSpriteBody: function (sprite, color) {
if (this.context == null) if (this.context == null)
{ {
return; return;
} }
color = color || 'rgba(0, 255, 0, 0.2)'; color = color || 'rgba(255,0,255, 0.3)';
this.start(0, 0, color);
this.start();
this.context.fillStyle = color; this.context.fillStyle = color;
this.context.fillRect(sprite.worldView.x, sprite.worldView.y, sprite.worldView.width, sprite.worldView.height); // this.context.fillRect(sprite.body.x - sprite.body.deltaX(), sprite.body.y - sprite.body.deltaY(), sprite.body.width, sprite.body.height);
this.context.fillRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height);
this.stop();
},
renderSpriteBounds: function (sprite, color, fill) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255,0,255)';
this.start(0, 0, color);
if (fill)
{
this.context.fillStyle = color;
this.context.fillRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
}
else
{
this.context.strokeStyle = color;
this.context.strokeRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
this.context.stroke();
}
this.stop(); this.stop();
}, },
+34 -4
View File
@@ -1,4 +1,15 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser.Utils
*/
/**
*
* @class Utils
* @static
*/
Phaser.Utils = { Phaser.Utils = {
/** /**
@@ -6,6 +17,11 @@ Phaser.Utils = {
* http://www.webtoolkit.info/ * http://www.webtoolkit.info/
* pad = the string to pad it out with (defaults to a space) * pad = the string to pad it out with (defaults to a space)
* dir = 1 (left), 2 (right), 3 (both) * dir = 1 (left), 2 (right), 3 (both)
* @method pad
* @param {string} str the target string
* @param {number} pad the string to pad it out with (defaults to a space)
* @param {number} len
* @param {number} [dir=3] the direction dir = 1 (left), 2 (right), 3 (both)
**/ **/
pad: function (str, len, pad, dir) { pad: function (str, len, pad, dir) {
@@ -37,7 +53,11 @@ Phaser.Utils = {
}, },
// This is a slightly modified version of jQuery.isPlainObject /**
* This is a slightly modified version of jQuery.isPlainObject
* @method isPlainObject
* @param {object} obj
*/
isPlainObject: function (obj) { isPlainObject: function (obj) {
// Not plain objects: // Not plain objects:
@@ -67,11 +87,20 @@ Phaser.Utils = {
return true; return true;
}, },
// deep, target, objects to copy to the target object // deep, target, objects to copy to the target object
// This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/) // This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/)
// deep (boolean) // deep (boolean)
// target (object to add to) // target (object to add to)
// objects ... (objects to recurse and copy from) // objects ... (objects to recurse and copy from)
/**
* This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/)
* @method extend
* @param {bool} [deep] If true, the merge becomes recursive (aka. deep copy).
* @param {object} target The object to add to
* @param {object} objets Objects to recurse and copy from
*/
extend: function () { extend: function () {
var options, name, src, copy, copyIsArray, clone, var options, name, src, copy, copyIsArray, clone,
@@ -147,17 +176,18 @@ Phaser.Utils = {
// Global functions that PIXI needs // Global functions that PIXI needs
/** /**
* Converts a hex color number to an [R, G, B] array * Converts a hex color number to an [R, G, B] array
* *
* @method HEXtoRGB * @method HEXtoRGB
* @param hex {Number} * @param {Number} hex
* @return {array}
*/ */
function HEXtoRGB(hex) { function HEXtoRGB(hex) {
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
} }
/** /**
* A polyfill for Function.prototype.bind * A polyfill for Function.prototype.bind
* *
* @method bind * @method bind