mirror of
https://github.com/wassname/phaser.git
synced 2026-08-04 13:14:14 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c41b3253c | ||
|
|
a415e779d1 | ||
|
|
9e88da5c66 | ||
|
|
e938e41c73 | ||
|
|
1b5c1f18fe | ||
|
|
26a595cd44 | ||
|
|
3f1cafe21f | ||
|
|
7dd63df087 | ||
|
|
78a062dfb6 | ||
|
|
6e4631a849 | ||
|
|
6fde862f61 | ||
|
|
4f969901da | ||
|
|
c5fc5e3394 | ||
|
|
cf26f68693 | ||
|
|
47834ad478 | ||
|
|
91c07ea37d | ||
|
|
d9a49797c4 | ||
|
|
a102859622 | ||
|
|
a899d24d4c |
Binary file not shown.
@@ -1,11 +1,11 @@
|
||||

|
||||

|
||||
|
||||
Phaser 1.0
|
||||
==========
|
||||
|
||||
Phaser is a fast, free and fun open source game framework for making desktop and mobile browser HTML5 games. It supports 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.3 - Released: September 17th 2013
|
||||
Version: 1.0.5 - Released: September 20th 2013
|
||||
|
||||
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
|
||||
|
||||
@@ -17,10 +17,8 @@ Try out the [Phaser Test Suite](http://gametest.mobi/phaser/)
|
||||
|
||||
"Being negative is not how we make progress" - Larry Page, Google
|
||||
|
||||
Latest Update
|
||||
-------------
|
||||
|
||||
September 13th 2013
|
||||
Welcome to Phaser
|
||||
-----------------
|
||||
|
||||
We're very pleased to have finally shipped the 1.0 release of Phaser. This version represents many months of hard work, feedback and refactoring based on the previous 0.5 through to 0.97 releases. You can see the full gory details in our change log.
|
||||
|
||||
@@ -37,6 +35,36 @@ Phaser is everything we ever wanted from an HTML5 game framework. It will power
|
||||
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)
|
||||
|
||||
* Small fix to Phaser.Canvas to stop it from setting overflow hidden if the parent DOM element doesn't exist.
|
||||
* Added Loader.setPreloadSprite(sprite, direction) - this will automatically apply a crop rect to the Sprite which is updated in line with the load progress.
|
||||
* A lot of changes inside the StateManager. State functions are now passed through link() which automatically creates the key Game properties (load, input, etc)
|
||||
* Fixed a bug in getFrameByName that wouldn't return the first frame in the array.
|
||||
* Updated Phaser.Rectangle.intersects to use x and y instead of left and top so it can be used to check Physics bodies overlapping.
|
||||
* Fixed issue in Cache where the Frame index wasn't being set correctly (thanks Cameron)
|
||||
* Fixed issue in Sprite where boundsY wasn't set (thanks Cameron)
|
||||
* For some reason there were 2 copies of the Canvas class in the build file - fixed, a few KB saved :)
|
||||
|
||||
Version 1.0.3 (September 17th 2013)
|
||||
|
||||
* FrameData.getFrameIndexes and getFrameIndexesByName refactored into a more versatile getFrames function.
|
||||
@@ -164,8 +192,9 @@ The following list is not exhaustive and is subject to change:
|
||||
* Tilemap: more advanced Tiled support and support for DAME tilemaps.
|
||||
* Joypad support.
|
||||
* Gestures input class.
|
||||
* Flash CC html output support.
|
||||
|
||||
Right now our main focus is on documentation.
|
||||
Right now however our main focus is on documentation and examples, we won't be touching any of the above features until the docs are finished.
|
||||
|
||||
Test Suite
|
||||
----------
|
||||
@@ -185,9 +214,9 @@ You can also browse the [Phaser Test Suite](http://gametest.mobi/phaser/) online
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Phaser is in early stages and although we've still got a lot to add to it, we wanted to just get it out there and share it with the world.
|
||||
Phaser is in early stages and although we've still got a lot to add to it, we wanted to get it out there and share it with the world.
|
||||
|
||||
If you find a bug (highly likely!) then please report it on github.
|
||||
If you find a bug (highly likely!) then please report it on github or our forum.
|
||||
|
||||
If you have a feature request, or have written a small game or demo that shows Phaser in use, then please get in touch. We'd love to hear from you.
|
||||
|
||||
@@ -198,7 +227,7 @@ Bugs?
|
||||
|
||||
Please add them to the [Issue Tracker][1] with as much info as possible.
|
||||
|
||||

|
||||

|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
+13
-2
@@ -2,7 +2,13 @@
|
||||
|
||||
<textarea style="width: 800px; height: 800px">
|
||||
<?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');
|
||||
$output = "";
|
||||
|
||||
@@ -15,16 +21,21 @@
|
||||
{
|
||||
$line = str_replace('<script src="', '', $line);
|
||||
$line = str_replace('"></script>', '', $line);
|
||||
$filename = substr($line, strrpos($line, '/') + 1);
|
||||
|
||||
echo $line . "\n";
|
||||
// echo $filename . "\n";
|
||||
|
||||
// Read the file in
|
||||
$source = file_get_contents($line);
|
||||
|
||||
if ($i == 4)
|
||||
if ($filename == 'Intro.js')
|
||||
{
|
||||
// Built at: {buildDate}
|
||||
$source = str_replace('{buildDate}', date('r'), $source);
|
||||
|
||||
// {version}
|
||||
$source = str_replace('{version}', $version, $source);
|
||||
}
|
||||
|
||||
$output .= $source . "\n";
|
||||
|
||||
Vendored
-1
File diff suppressed because one or more lines are too long
+1687
-908
File diff suppressed because it is too large
Load Diff
Vendored
+1
File diff suppressed because one or more lines are too long
@@ -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 |
@@ -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 |
@@ -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');
|
||||
?>
|
||||
@@ -21,13 +21,11 @@
|
||||
//setting the size of the game world larger than the tilemap's size
|
||||
game.world.setSize(2000,2000);
|
||||
|
||||
// game.camera.width=150;
|
||||
// game.camera.height=150;
|
||||
|
||||
game.stage.backgroundColor = '#255d3b';
|
||||
|
||||
// adding the tilemap
|
||||
game.add.tilemap(0, 168, 'snes');
|
||||
game.add.tilemap(0, 150, 'snes');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
?>
|
||||
@@ -55,8 +55,11 @@
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderRectangle(sprite1.body);
|
||||
game.debug.renderRectangle(sprite2.body);
|
||||
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
(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() {
|
||||
|
||||
@@ -21,17 +21,21 @@
|
||||
function create() {
|
||||
|
||||
// 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.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);
|
||||
}
|
||||
|
||||
function clickedIt() {
|
||||
|
||||
boss.scale.x += 0.5;
|
||||
boss.scale.y += 0.5;
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
+134
-14
@@ -7,21 +7,37 @@
|
||||
|
||||
(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() {
|
||||
|
||||
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 paddle;
|
||||
var bricks;
|
||||
|
||||
var ballOnPaddle = true;
|
||||
|
||||
var lives = 3;
|
||||
var score = 0;
|
||||
|
||||
var scoreText;
|
||||
var livesText;
|
||||
var introText;
|
||||
|
||||
var s;
|
||||
|
||||
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;
|
||||
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.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);
|
||||
|
||||
paddle = game.add.sprite(game.world.centerX, 550, 'breakout', 'paddle_big.png');
|
||||
paddle.body.collideWorldBounds = true;
|
||||
paddle.body.bounce.setTo(1, 1);
|
||||
paddle.body.immovable = true;
|
||||
scoreText = game.add.text(32, 550, 'score: 0', { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
livesText = game.add.text(680, 550, 'lives: 3', { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
introText = game.add.text(game.world.centerX, 400, '- click to start -', { font: "40px Arial", fill: "#ffffff", align: "center" });
|
||||
introText.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.input.onDown.add(releaseBall, this);
|
||||
|
||||
@@ -51,36 +74,133 @@
|
||||
|
||||
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;
|
||||
|
||||
if (paddle.x < 24)
|
||||
{
|
||||
paddle.x = 24;
|
||||
}
|
||||
else if (paddle.x > game.width - 24)
|
||||
{
|
||||
paddle.x = game.width - 24;
|
||||
}
|
||||
|
||||
if (ballOnPaddle)
|
||||
{
|
||||
ball.x = paddle.x + 16;
|
||||
ball.x = paddle.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.physics.collide(paddle, ball);
|
||||
game.physics.collide(ball, paddle, ballHitPaddle, null, this);
|
||||
game.physics.collide(ball, bricks, ballHitBrick, null, this);
|
||||
}
|
||||
|
||||
// Out?
|
||||
if (ball.y > 600 && ballOnPaddle == false)
|
||||
{
|
||||
ballLost();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function releaseBall () {
|
||||
|
||||
ballOnPaddle = false;
|
||||
ball.body.velocity.y = -300;
|
||||
ball.body.velocity.x = -75;
|
||||
ball.animations.play('spin');
|
||||
if (ballOnPaddle)
|
||||
{
|
||||
ballOnPaddle = false;
|
||||
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) {
|
||||
|
||||
_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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -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');
|
||||
?>
|
||||
@@ -12,11 +12,11 @@
|
||||
var s;
|
||||
|
||||
function preload() {
|
||||
game.load.image('disk', 'assets/misc/starfield.jpg');
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
}
|
||||
|
||||
function create() {
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'disk');
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Phaser - http://www.phaser.io
|
||||
*
|
||||
* v1.0.1 - Built at: {buildDate}
|
||||
* v{version} - Built at: {buildDate}
|
||||
*
|
||||
* @author Richard Davey http://www.photonstorm.com @photonstorm
|
||||
*
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
var Phaser = Phaser || {
|
||||
|
||||
VERSION: '1.0.3',
|
||||
VERSION: '1.0.5',
|
||||
GAMES: [],
|
||||
AUTO: 0,
|
||||
CANVAS: 1,
|
||||
|
||||
+25
-50
@@ -9,104 +9,78 @@
|
||||
* 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.
|
||||
*
|
||||
* @class Animation
|
||||
* @class Phaser.Animation
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game A reference to the currently running game.
|
||||
* @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 {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 {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 {Phaser.Game} game - A reference to the currently running game.
|
||||
* @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 {Phaser.Animation.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
|
||||
* @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 {boolean} looped - Should this animation loop or play through once.
|
||||
*/
|
||||
Phaser.Animation = function (game, parent, name, frameData, frames, delay, looped) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* A reference to the parent Sprite that owns this Animation.
|
||||
* @property _parent
|
||||
* @property {Phaser.Sprite} _parent - A reference to the parent Sprite that owns this Animation.
|
||||
* @private
|
||||
* @type {Phaser.Sprite}
|
||||
*/
|
||||
this._parent = parent;
|
||||
|
||||
/**
|
||||
* The FrameData the Animation uses.
|
||||
* @property _frameData
|
||||
* @property {Phaser.FrameData} _frameData - The FrameData the Animation uses.
|
||||
* @private
|
||||
* @type {Phaser.FrameData}
|
||||
*/
|
||||
this._frameData = frameData;
|
||||
|
||||
/**
|
||||
* The user defined name given to this Animation.
|
||||
* @property name
|
||||
* @public
|
||||
* @type {String}
|
||||
* @property {string} name - The user defined name given to this Animation.
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property _frames
|
||||
* @property {object} _frames
|
||||
* @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 delay
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} delay - The delay in ms between each frame of the Animation.
|
||||
*/
|
||||
this.delay = 1000 / delay;
|
||||
|
||||
/**
|
||||
* The loop state of the Animation.
|
||||
* @property looped
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* @property {boolean} looped - The loop state of the Animation.
|
||||
*/
|
||||
this.looped = looped;
|
||||
|
||||
/**
|
||||
* The finished state of the Animation. Set to true once playback completes, false during playback.
|
||||
* @property isFinished
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* default true
|
||||
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
|
||||
* @default
|
||||
*/
|
||||
this.isFinished = false;
|
||||
|
||||
/**
|
||||
* The playing state of the Animation. Set to false once playback completes, true during playback.
|
||||
* @property isPlaying
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* default false
|
||||
* @property {boolean} isPlaying - The playing state of the Animation. Set to false once playback completes, true during playback.
|
||||
* @default
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* @property _frameIndex
|
||||
* @property {number} _frameIndex
|
||||
* @private
|
||||
* @type {Number}
|
||||
* default 0
|
||||
* @default
|
||||
*/
|
||||
this._frameIndex = 0;
|
||||
|
||||
/**
|
||||
* The currently displayed frame of the Animation.
|
||||
* @property currentFrame
|
||||
* @public
|
||||
* @type {Phaser.Animation.Frame}
|
||||
* @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation.
|
||||
*/
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
@@ -130,6 +104,7 @@ Phaser.Animation.prototype = {
|
||||
if (frameRate !== null)
|
||||
{
|
||||
this.delay = 1000 / frameRate;
|
||||
// this.delay = frameRate;
|
||||
}
|
||||
|
||||
if (loop !== null)
|
||||
|
||||
@@ -359,7 +359,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
if (this._frameData && this._frameData.getFrameByName(value))
|
||||
if (this._frameData && this._frameData.getFrameByName(value) !== null)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrameByName(value);
|
||||
this._frameIndex = this.currentFrame.index;
|
||||
|
||||
@@ -82,7 +82,7 @@ Phaser.Animation.FrameData.prototype = {
|
||||
*/
|
||||
getFrameByName: function (name) {
|
||||
|
||||
if (this._frameNames[name] && this._frameNames[name] !== '')
|
||||
if (typeof this._frameNames[name] === 'number')
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
@@ -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.
|
||||
* @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 output === "undefined") { output = []; }
|
||||
|
||||
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++)
|
||||
{
|
||||
output.push(this._frames[i].index);
|
||||
@@ -204,16 +204,16 @@ Phaser.Animation.FrameData.prototype = {
|
||||
else
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
output.push(input[i].index);
|
||||
output.push(frames[i].index);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
output.push(this.getFrameByName(frames[i]).index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ Phaser.Animation.Parser = {
|
||||
);
|
||||
|
||||
PIXI.TextureCache[uuid].realSize = frames[i].spriteSourceSize;
|
||||
// PIXI.TextureCache[uuid].realSize = frames[i].sourceSize;
|
||||
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].sourceSize;
|
||||
PIXI.TextureCache[uuid].trim.x = 0;
|
||||
}
|
||||
|
||||
|
||||
+118
-23
@@ -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.
|
||||
* 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
|
||||
* @param game {Phaser.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 x {number} position of the camera on the X axis
|
||||
* @param y {number} position of the camera on the Y axis
|
||||
* @param width {number} the width of the view rectangle
|
||||
* @param height {number} the height of the view rectangle
|
||||
* @param {Phaser.Game} game game reference to the currently running game.
|
||||
* @param {number} id not being used at the moment, will be when Phaser supports multiple camera
|
||||
* @param {number} x position of the camera on the X axis
|
||||
* @param {number} y position of the camera on the Y axis
|
||||
* @param {number} width the width of the view rectangle
|
||||
* @param {number} height the height of the view rectangle
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* A reference to the game world
|
||||
* @property world
|
||||
* @public
|
||||
* @type {Phaser.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)
|
||||
// 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?)
|
||||
|
||||
/**
|
||||
* reserved for future multiple camera set-ups
|
||||
* @property id
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.id = 0;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Sprite moving inside this Rectangle will not cause camera moving.
|
||||
* @type {Rectangle}
|
||||
* @property deadzone
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
this.deadzone = null;
|
||||
|
||||
/**
|
||||
* Whether this camera is visible or not. (default is true)
|
||||
* @property visible
|
||||
* @public
|
||||
* @default true
|
||||
* @type {bool}
|
||||
*/
|
||||
this.visible = true;
|
||||
|
||||
/**
|
||||
* Whether this camera is flush with the World Bounds or not.
|
||||
* @property atLimit
|
||||
* @type {bool}
|
||||
*/
|
||||
this.atLimit = { x: false, y: false };
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Edge property
|
||||
* @property edge
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this._edge = 0;
|
||||
|
||||
};
|
||||
@@ -74,8 +116,9 @@ Phaser.Camera.prototype = {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @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().
|
||||
* @method 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) {
|
||||
|
||||
@@ -112,9 +155,10 @@ Phaser.Camera.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Move the camera focus to this location instantly.
|
||||
* @param x {number} X position.
|
||||
* @param y {number} Y position.
|
||||
* Move the camera focus to a location instantly.
|
||||
* @method focusOnXY
|
||||
* @param {number} x X position.
|
||||
* @param {number} y Y position.
|
||||
*/
|
||||
focusOnXY: function (x, y) {
|
||||
|
||||
@@ -125,6 +169,7 @@ Phaser.Camera.prototype = {
|
||||
|
||||
/**
|
||||
* Update focusing and scrolling.
|
||||
* @method update
|
||||
*/
|
||||
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 () {
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
||||
this.view.width = width;
|
||||
@@ -225,10 +289,17 @@ Phaser.Camera.prototype = {
|
||||
|
||||
Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
|
||||
/**
|
||||
* @method x
|
||||
* @return {Number} The x position
|
||||
*/
|
||||
get: function () {
|
||||
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) {
|
||||
this.view.x = value;
|
||||
this.checkWorldBounds();
|
||||
@@ -238,10 +309,18 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
|
||||
Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
|
||||
/**
|
||||
* @method y
|
||||
* @return {Number} The y position
|
||||
*/
|
||||
get: function () {
|
||||
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) {
|
||||
this.view.y = value;
|
||||
this.checkWorldBounds();
|
||||
@@ -251,10 +330,18 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
|
||||
Object.defineProperty(Phaser.Camera.prototype, "width", {
|
||||
|
||||
/**
|
||||
* @method width
|
||||
* @return {Number} The width of the view rectangle, in pixels
|
||||
*/
|
||||
get: function () {
|
||||
return this.view.width;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method width
|
||||
* @return {Number} Sets the width of the view rectangle
|
||||
*/
|
||||
set: function (value) {
|
||||
this.view.width = value;
|
||||
}
|
||||
@@ -263,10 +350,18 @@ Object.defineProperty(Phaser.Camera.prototype, "width", {
|
||||
|
||||
Object.defineProperty(Phaser.Camera.prototype, "height", {
|
||||
|
||||
/**
|
||||
* @method height
|
||||
* @return {Number} The height of the view rectangle, in pixels
|
||||
*/
|
||||
get: function () {
|
||||
return this.view.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method height
|
||||
* @return {Number} Sets the height of the view rectangle
|
||||
*/
|
||||
set: function (value) {
|
||||
this.view.height = value;
|
||||
}
|
||||
|
||||
+33
-50
@@ -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.
|
||||
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.
|
||||
* 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
|
||||
{
|
||||
if (currentNode.exists && currentNode[callback])
|
||||
if (currentNode[callback])
|
||||
{
|
||||
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", {
|
||||
|
||||
get: function () {
|
||||
|
||||
+78
-19
@@ -1,49 +1,97 @@
|
||||
/**
|
||||
* Stage
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
|
||||
* @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.Stage
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 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
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} game reference to the currently running game.
|
||||
* @param width {number} width of the canvas element
|
||||
* @param height {number} height of the canvas element
|
||||
* @param {Phaser.Game} game Game reference to the currently running game.
|
||||
* @param {number} width Width of the canvas element
|
||||
* @param {number} height Height of the canvas element
|
||||
*/
|
||||
Phaser.Stage = function (game, width, height) {
|
||||
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Background color of the stage (defaults to black). Set via the public backgroundColor property.
|
||||
* @property _backgroundColor
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* reference to the newly created <canvas> element
|
||||
* @property canvas
|
||||
* @public
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
this.canvas = Phaser.Canvas.create(width, height);
|
||||
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.name = '_stage_root';
|
||||
|
||||
|
||||
/**
|
||||
* The current scaleMode
|
||||
* @property scaleMode
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* aspect ratio
|
||||
* @property aspectRatio
|
||||
* @public
|
||||
* @type {number}
|
||||
*/
|
||||
this.aspectRatio = width / height;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Stage.prototype = {
|
||||
|
||||
/**
|
||||
* Initialises the stage and adds the event listeners
|
||||
* @method boot
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
Phaser.Canvas.getOffset(this.canvas, this.offset);
|
||||
@@ -68,6 +116,8 @@ Phaser.Stage.prototype = {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
@@ -93,10 +143,19 @@ Phaser.Stage.prototype = {
|
||||
|
||||
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
|
||||
|
||||
/**
|
||||
* @method backgroundColor
|
||||
* @return {string} returns the background color of the stage
|
||||
*/
|
||||
get: function () {
|
||||
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) {
|
||||
|
||||
this._backgroundColor = color;
|
||||
|
||||
+1
-20
@@ -31,25 +31,6 @@ Phaser.State = function () {
|
||||
|
||||
Phaser.State.prototype = {
|
||||
|
||||
link: function (game) {
|
||||
|
||||
this.game = game;
|
||||
this.add = game.add;
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.input = game.input;
|
||||
this.load = game.load;
|
||||
this.math = game.math;
|
||||
this.sound = game.sound;
|
||||
this.stage = game.stage;
|
||||
this.time = game.time;
|
||||
this.tweens = game.tweens;
|
||||
this.world = game.world;
|
||||
this.particles = game.particles;
|
||||
this.physics = game.physics;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Override this method to add some load operations.
|
||||
* If you need to use the loader, you may need to use them here.
|
||||
@@ -59,7 +40,7 @@ Phaser.State.prototype = {
|
||||
|
||||
/**
|
||||
* This method is called after the game engine successfully switches states.
|
||||
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
|
||||
* Feel free to add any setup code here.(Do not load anything here, override preload() instead)
|
||||
*/
|
||||
create: function () {
|
||||
},
|
||||
|
||||
@@ -145,7 +145,6 @@ Phaser.StateManager.prototype = {
|
||||
{
|
||||
// console.log('Phaser.StateManager.addState: Phaser.State given');
|
||||
newState = state;
|
||||
newState.link(this.game);
|
||||
}
|
||||
else if (typeof state === 'object')
|
||||
{
|
||||
@@ -326,12 +325,35 @@ Phaser.StateManager.prototype = {
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
link: function (key) {
|
||||
|
||||
// console.log('linked');
|
||||
this.states[key].game = this.game;
|
||||
this.states[key].add = this.game.add;
|
||||
this.states[key].camera = this.game.camera;
|
||||
this.states[key].cache = this.game.cache;
|
||||
this.states[key].input = this.game.input;
|
||||
this.states[key].load = this.game.load;
|
||||
this.states[key].math = this.game.math;
|
||||
this.states[key].sound = this.game.sound;
|
||||
this.states[key].stage = this.game.stage;
|
||||
this.states[key].time = this.game.time;
|
||||
this.states[key].tweens = this.game.tweens;
|
||||
this.states[key].world = this.game.world;
|
||||
this.states[key].particles = this.game.particles;
|
||||
this.states[key].physics = this.game.physics;
|
||||
this.states[key].rnd = this.game.rnd;
|
||||
|
||||
},
|
||||
|
||||
setCurrentState: function (key) {
|
||||
|
||||
this.callbackContext = this.states[key];
|
||||
|
||||
this.link(key);
|
||||
|
||||
// Used when the state is set as being the current active state
|
||||
this.onInitCallback = this.states[key]['init'] || this.dummy;
|
||||
|
||||
|
||||
+76
-25
@@ -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
|
||||
*
|
||||
@@ -7,50 +13,62 @@
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
* @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) {
|
||||
|
||||
/**
|
||||
* Local reference to Game.
|
||||
*/
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Bound of this world that objects can not escape from.
|
||||
* @type {Rectangle}
|
||||
*/
|
||||
* Bound of this world that objects can not escape from.
|
||||
* @property bounds
|
||||
* @public
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
|
||||
/**
|
||||
* Camera instance.
|
||||
* @type {Camera}
|
||||
*/
|
||||
* Camera instance.
|
||||
* @property camera
|
||||
* @public
|
||||
* @type {Phaser.Camera}
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* Reset each frame, keeps a count of the total number of objects updated.
|
||||
* @type {Number}
|
||||
*/
|
||||
* Reset each frame, keeps a count of the total number of objects updated.
|
||||
* @property currentRenderOrderID
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
/**
|
||||
* Object container stores every object created with `create*` methods.
|
||||
* @type {Group}
|
||||
*/
|
||||
* Object container stores every object created with `create*` methods.
|
||||
* @property group
|
||||
* @public
|
||||
* @type {Phaser.Group}
|
||||
*/
|
||||
this.group = null;
|
||||
|
||||
};
|
||||
|
||||
Phaser.World.prototype = {
|
||||
|
||||
|
||||
/**
|
||||
* Initialises the game world
|
||||
*
|
||||
* @method boot
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
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 () {
|
||||
|
||||
this.camera.update();
|
||||
@@ -96,8 +115,8 @@ Phaser.World.prototype = {
|
||||
/**
|
||||
* Updates the size of this world.
|
||||
* @method setSize
|
||||
* @param width {number} New width of the world.
|
||||
* @param height {number} New height of the world.
|
||||
* @param {number} width New width of the world.
|
||||
* @param {number} height New height of the world.
|
||||
*/
|
||||
setSize: function (width, height) {
|
||||
|
||||
@@ -134,10 +153,18 @@ Phaser.World.prototype = {
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "width", {
|
||||
|
||||
/**
|
||||
* @method width
|
||||
* @return {Number} The current width of the game world
|
||||
*/
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method width
|
||||
* @return {Number} Sets the width of the game world
|
||||
*/
|
||||
set: function (value) {
|
||||
this.bounds.width = value;
|
||||
}
|
||||
@@ -146,10 +173,18 @@ Object.defineProperty(Phaser.World.prototype, "width", {
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "height", {
|
||||
|
||||
/**
|
||||
* @method height
|
||||
* @return {Number} The current height of the game world
|
||||
*/
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method height
|
||||
* @return {Number} Sets the width of the game world
|
||||
*/
|
||||
set: function (value) {
|
||||
this.bounds.height = value;
|
||||
}
|
||||
@@ -158,6 +193,10 @@ Object.defineProperty(Phaser.World.prototype, "height", {
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "centerX", {
|
||||
|
||||
/**
|
||||
* @method centerX
|
||||
* @return {Number} return the X position of the center point of the world
|
||||
*/
|
||||
get: function () {
|
||||
return this.bounds.halfWidth;
|
||||
}
|
||||
@@ -166,6 +205,10 @@ Object.defineProperty(Phaser.World.prototype, "centerX", {
|
||||
|
||||
Object.defineProperty(Phaser.World.prototype, "centerY", {
|
||||
|
||||
/**
|
||||
* @method centerY
|
||||
* @return {Number} return the Y position of the center point of the world
|
||||
*/
|
||||
get: function () {
|
||||
return this.bounds.halfHeight;
|
||||
}
|
||||
@@ -174,6 +217,10 @@ Object.defineProperty(Phaser.World.prototype, "centerY", {
|
||||
|
||||
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 () {
|
||||
return Math.round(Math.random() * this.bounds.width);
|
||||
}
|
||||
@@ -182,6 +229,10 @@ Object.defineProperty(Phaser.World.prototype, "randomX", {
|
||||
|
||||
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 () {
|
||||
return Math.round(Math.random() * this.bounds.height);
|
||||
}
|
||||
|
||||
+20
-13
@@ -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.
|
||||
* @class Button
|
||||
* @constructor
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param [x] {number} X position of the button.
|
||||
* @param [y] {number} 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 [callback] {function} The function to call when this button is pressed
|
||||
* @param [callbackContext] {object} 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 [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 [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 {Phaser.Game} game Current game instance.
|
||||
* @param {number} [x] X position of the button.
|
||||
* @param {number} [y] Y position of the button.
|
||||
* @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param {function} [callback] The function to call when this button is pressed
|
||||
* @param {object} [callbackContext] The context in which the callback will be called (usually 'this')
|
||||
* @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 {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 {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) {
|
||||
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null;
|
||||
@@ -65,11 +73,10 @@ Phaser.Button.prototype.constructor = Phaser.Button;
|
||||
* exactly like setting them in the constructor
|
||||
*
|
||||
* @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 [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 [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} [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 {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 {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) {
|
||||
|
||||
if (overFrame !== null)
|
||||
|
||||
@@ -9,6 +9,8 @@ Phaser.RenderTexture = function (game, key, width, height) {
|
||||
this.width = width || 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.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
|
||||
|
||||
+77
-65
@@ -214,6 +214,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
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
|
||||
// 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)
|
||||
{
|
||||
this.position.x = this._cache.x;
|
||||
@@ -224,76 +225,77 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
if (this.visible)
|
||||
{
|
||||
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
|
||||
// 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.
|
||||
if (this._cache.dirty && this.visible == false)
|
||||
{
|
||||
this.bounds.x -= this._cache.boundsX - this._cache.x;
|
||||
this._cache.boundsX = this._cache.x;
|
||||
// if (this._cache.dirty && this.visible == false)
|
||||
// {
|
||||
// this.bounds.x -= this._cache.boundsX - this._cache.x;
|
||||
// this._cache.boundsX = this._cache.x;
|
||||
|
||||
this.bounds.y -= this._cache.boundsy - this._cache.y;
|
||||
this._cache.boundsY = this._cache.y;
|
||||
}
|
||||
}
|
||||
// this.bounds.y -= this._cache.boundsY - this._cache.y;
|
||||
// this._cache.boundsY = this._cache.y;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Re-run the camera visibility check
|
||||
if (this._cache.dirty)
|
||||
@@ -302,7 +304,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
|
||||
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
|
||||
@@ -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.
|
||||
* Doesn't change the origin of the sprite.
|
||||
|
||||
+25
-8
@@ -17,12 +17,15 @@ Phaser.Text = function (game, x, y, text, style) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this._text = text;
|
||||
this._style = style;
|
||||
|
||||
PIXI.Text.call(this, text, style);
|
||||
|
||||
this.type = Phaser.TEXT;
|
||||
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
this.position.x = this.x = x;
|
||||
this.position.y = this.y = y;
|
||||
|
||||
// Replaces the PIXI.Point with a slightly more flexible one
|
||||
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() {
|
||||
return this.position.x;
|
||||
return this._text;
|
||||
},
|
||||
|
||||
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() {
|
||||
return this.position.y;
|
||||
return this._style;
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -675,7 +675,7 @@ Phaser.Rectangle.intersects = function (a, b, tolerance) {
|
||||
|
||||
tolerance = tolerance || 0;
|
||||
|
||||
return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
|
||||
return !(a.x > b.right + tolerance || a.right < b.x - tolerance || a.y > b.bottom + tolerance || a.bottom < b.y - tolerance);
|
||||
|
||||
};
|
||||
|
||||
|
||||
+3
-3
@@ -80,7 +80,7 @@ Phaser.Cache.prototype = {
|
||||
*/
|
||||
addRenderTexture: function (key, texture) {
|
||||
|
||||
var frame = new Phaser.Animation.Frame(0, 0, texture.width, texture.height, '', '');
|
||||
var frame = new Phaser.Animation.Frame(0, 0, 0, texture.width, texture.height, '', '');
|
||||
|
||||
this._textures[key] = { texture: texture, frame: frame };
|
||||
|
||||
@@ -177,7 +177,7 @@ Phaser.Cache.prototype = {
|
||||
addDefaultImage: function () {
|
||||
|
||||
this._images['__default'] = { url: null, data: null, spriteSheet: false };
|
||||
this._images['__default'].frame = new Phaser.Animation.Frame(0, 0, 32, 32, '', '');
|
||||
this._images['__default'].frame = new Phaser.Animation.Frame(0, 0, 0, 32, 32, '', '');
|
||||
|
||||
var base = new PIXI.BaseTexture();
|
||||
base.width = 32;
|
||||
@@ -198,7 +198,7 @@ Phaser.Cache.prototype = {
|
||||
addImage: function (key, url, data) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: false };
|
||||
this._images[key].frame = new Phaser.Animation.Frame(0, 0, data.width, data.height, '', '');
|
||||
this._images[key].frame = new Phaser.Animation.Frame(0, 0, 0, data.width, data.height, '', '');
|
||||
|
||||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
||||
|
||||
@@ -57,6 +57,12 @@ Phaser.Loader = function (game) {
|
||||
*/
|
||||
this.progress = 0;
|
||||
|
||||
/**
|
||||
* You can optionally link a sprite to the preloader.
|
||||
* If you do so the Sprite's width or height will be cropped based on the percentage loaded.
|
||||
*/
|
||||
this.preloadSprite = null;
|
||||
|
||||
/**
|
||||
* The crossOrigin value applied to loaded images
|
||||
* @type {string}
|
||||
@@ -90,6 +96,27 @@ Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2;
|
||||
|
||||
Phaser.Loader.prototype = {
|
||||
|
||||
setPreloadSprite: function (sprite, direction) {
|
||||
|
||||
direction = direction || 0;
|
||||
|
||||
this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
|
||||
|
||||
if (direction == 0)
|
||||
{
|
||||
// Horizontal crop
|
||||
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 0, sprite.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vertical crop
|
||||
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 0);
|
||||
}
|
||||
|
||||
sprite.crop = this.preloadSprite.crop;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether asset exists with a specific key.
|
||||
* @param key {string} Key of the asset you want to check.
|
||||
@@ -113,6 +140,7 @@ Phaser.Loader.prototype = {
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
this.preloadSprite = null;
|
||||
this.queueSize = 0;
|
||||
this.isLoading = false;
|
||||
|
||||
@@ -872,6 +900,20 @@ Phaser.Loader.prototype = {
|
||||
this.progress = 100;
|
||||
}
|
||||
|
||||
if (this.preloadSprite !== null)
|
||||
{
|
||||
if (this.preloadSprite.direction == 0)
|
||||
{
|
||||
this.preloadSprite.crop.width = (this.preloadSprite.width / 100) * this.progress;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.preloadSprite.crop.height = (this.preloadSprite.height / 100) * this.progress;
|
||||
}
|
||||
|
||||
this.preloadSprite.sprite.crop = this.preloadSprite.crop;
|
||||
}
|
||||
|
||||
this.onFileComplete.dispatch(this.progress, previousKey, success, this.queueSize - this._keys.length, this.queueSize);
|
||||
|
||||
if (this._keys.length > 0)
|
||||
|
||||
@@ -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;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.x = sprite.x;
|
||||
this.y = sprite.y;
|
||||
this.lastX = sprite.x;
|
||||
this.lastY = sprite.y;
|
||||
|
||||
// un-scaled original size
|
||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||
@@ -62,9 +64,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.collideWorldBounds = false;
|
||||
|
||||
this.lastX = sprite.x;
|
||||
this.lastY = sprite.y;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.Arcade.Body.prototype = {
|
||||
@@ -102,8 +101,11 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.lastY = this.y;
|
||||
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.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)
|
||||
{
|
||||
@@ -122,6 +124,16 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
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
|
||||
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);
|
||||
|
||||
+107
-13
@@ -3,26 +3,70 @@
|
||||
*
|
||||
* @class Sound
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} reference to the current game instance.
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param volume {number} default value for the volume.
|
||||
* @param loop {bool} Whether or not the sound will loop.
|
||||
* @param {Phaser.Game} game Reference to the current game instance.
|
||||
* @param {string} key Asset key for the sound.
|
||||
* @param {number} volume Default value for the volume.
|
||||
* @param {bool} loop Whether or not the sound will loop.
|
||||
*/
|
||||
Phaser.Sound = function (game, key, volume, loop) {
|
||||
|
||||
volume = volume || 1;
|
||||
if (typeof loop == 'undefined') { loop = false; }
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Name of the sound
|
||||
* @property name
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* Asset key for the sound.
|
||||
* @property key
|
||||
* @public
|
||||
* @type {string}
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* Whether or not the sound will loop.
|
||||
* @property loop
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.loop = loop;
|
||||
|
||||
/**
|
||||
* The global audio volume. A value between 0 (silence) and 1 (full volume)
|
||||
* @property _volume
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this._volume = volume;
|
||||
|
||||
/**
|
||||
* The sound markers, empty by default
|
||||
* @property markers
|
||||
* @public
|
||||
* @type {object}
|
||||
*/
|
||||
this.markers = {};
|
||||
|
||||
|
||||
/**
|
||||
* Reference to AudioContext instance.
|
||||
* @property context
|
||||
* @public
|
||||
* @type {AudioContext}
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
@@ -31,9 +75,28 @@ Phaser.Sound = function (game, key, volume, loop) {
|
||||
*/
|
||||
this._buffer = null;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
*/
|
||||
this._muted = false;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the sound should start automatically
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.autoplay = false;
|
||||
|
||||
/**
|
||||
* The total duration of the sound, in milliseconds
|
||||
* @property autoplay
|
||||
* @public
|
||||
* @type {bool}
|
||||
*/
|
||||
this.totalDuration = 0;
|
||||
this.startTime = 0;
|
||||
this.currentTime = 0;
|
||||
@@ -188,11 +251,11 @@ Phaser.Sound.prototype = {
|
||||
|
||||
/**
|
||||
* Play this sound, or a marked section of it.
|
||||
|
||||
* @param marker {string} Assets key of the sound you want to play.
|
||||
* @param position {number} the starting position
|
||||
* @param [volume] {number} volume of the sound you want to play.
|
||||
* @param [loop] {bool} loop when it finished playing? (Default to false)
|
||||
* @method play
|
||||
* @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)
|
||||
* @return {Sound} The playing sound object.
|
||||
*/
|
||||
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) {
|
||||
|
||||
marker = marker || '';
|
||||
@@ -377,6 +448,10 @@ Phaser.Sound.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Pauses the sound
|
||||
* @method pause
|
||||
*/
|
||||
pause: function () {
|
||||
|
||||
if (this.isPlaying && this._sound)
|
||||
@@ -388,7 +463,10 @@ Phaser.Sound.prototype = {
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resumes the sound
|
||||
* @method pause
|
||||
*/
|
||||
resume: function () {
|
||||
|
||||
if (this.paused && this._sound)
|
||||
@@ -419,6 +497,7 @@ Phaser.Sound.prototype = {
|
||||
|
||||
/**
|
||||
* Stop playing this sound.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
@@ -470,13 +549,20 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", {
|
||||
|
||||
Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
/**
|
||||
* Mute sounds.
|
||||
|
||||
/**
|
||||
* Mutes sound.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the sound is muted
|
||||
*/
|
||||
get: function () {
|
||||
return this._muted;
|
||||
},
|
||||
|
||||
/**
|
||||
* Mutes sound.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the sound is muted
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
value = value || null;
|
||||
@@ -518,10 +604,18 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", {
|
||||
|
||||
Object.defineProperty(Phaser.Sound.prototype, "volume", {
|
||||
|
||||
/**
|
||||
* @method volume
|
||||
* @return {number} The current volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
get: function () {
|
||||
return this._volume;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method volume
|
||||
* @return {number} Sets the current volume. A value between 0 (silence) and 1 (full volume)
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
if (this.usingWebAudio)
|
||||
|
||||
+73
-11
@@ -3,20 +3,47 @@
|
||||
*
|
||||
* @class SoundManager
|
||||
* @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) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
this.onSoundDecode = new Phaser.Signal;
|
||||
|
||||
|
||||
/**
|
||||
* Boolean indicating whether the game is on "mute"
|
||||
* @property _muted
|
||||
* @private
|
||||
* @type {bool}
|
||||
*/
|
||||
this._muted = false;
|
||||
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._muted = false;
|
||||
|
||||
/**
|
||||
* An array containing all the sounds
|
||||
* @property _sounds
|
||||
* @private
|
||||
* @type {array}
|
||||
*/
|
||||
this._sounds = [];
|
||||
|
||||
|
||||
this.context = null;
|
||||
this.usingWebAudio = true;
|
||||
this.usingAudioTag = false;
|
||||
@@ -30,6 +57,10 @@ Phaser.SoundManager = function (game) {
|
||||
|
||||
Phaser.SoundManager.prototype = {
|
||||
|
||||
/**
|
||||
* Initialises the sound manager
|
||||
* @method boot
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
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 () {
|
||||
|
||||
if (this.touchLocked == false)
|
||||
@@ -138,6 +173,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops all the sounds in the game
|
||||
* @method stopAll
|
||||
*/
|
||||
stopAll: function () {
|
||||
|
||||
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 () {
|
||||
|
||||
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 () {
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
@@ -176,8 +223,9 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
/**
|
||||
* Decode a sound with its assets key.
|
||||
* @method decode
|
||||
* @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) {
|
||||
|
||||
@@ -205,6 +253,10 @@ Phaser.SoundManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* updates every sound in the game
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.touchLocked)
|
||||
@@ -232,11 +284,10 @@ Phaser.SoundManager.prototype = {
|
||||
/**
|
||||
*
|
||||
* @method add
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param volume {number} default value for the volume.
|
||||
* @param loop {bool} Whether or not the sound will loop.
|
||||
* @param {string} key Asset key for the sound.
|
||||
* @param {number} volume Default value for the volume.
|
||||
* @param {bool} loop Whether or not the sound will loop.
|
||||
*/
|
||||
|
||||
add: function (key, volume, loop) {
|
||||
|
||||
volume = volume || 1;
|
||||
@@ -258,6 +309,8 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
|
||||
/**
|
||||
* A global audio mute toggle.
|
||||
* @method mute
|
||||
* @return {bool} whether or not the game is on "mute"
|
||||
*/
|
||||
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) {
|
||||
|
||||
value = value || null;
|
||||
@@ -316,14 +374,16 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
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 () {
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
+26
-7
@@ -5,8 +5,22 @@
|
||||
* @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) {
|
||||
|
||||
width = width || 256;
|
||||
@@ -23,6 +37,10 @@ Phaser.Canvas = {
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
@@ -103,23 +121,24 @@ Phaser.Canvas = {
|
||||
addToDOM: function (canvas, parent, overflowHidden) {
|
||||
|
||||
parent = parent || '';
|
||||
overflowHidden = overflowHidden || true;
|
||||
|
||||
if (typeof overflowHidden === 'undefined') { overflowHidden = true; }
|
||||
|
||||
if (parent !== '')
|
||||
{
|
||||
if (document.getElementById(parent))
|
||||
{
|
||||
document.getElementById(parent).appendChild(canvas);
|
||||
|
||||
if (overflowHidden)
|
||||
{
|
||||
document.getElementById(parent).style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
document.body.appendChild(canvas);
|
||||
}
|
||||
|
||||
if (overflowHidden)
|
||||
{
|
||||
document.getElementById(parent).style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+10
-3
@@ -36,6 +36,8 @@ Phaser.Tween = function (object, game) {
|
||||
|
||||
this._pausedTime = 0;
|
||||
|
||||
this.pendingDelete = false;
|
||||
|
||||
// Set all starting values present on the target object
|
||||
for ( var field in object ) {
|
||||
this._valuesStart[ field ] = parseFloat(object[field], 10);
|
||||
@@ -190,21 +192,21 @@ Phaser.Tween.prototype = {
|
||||
|
||||
},
|
||||
|
||||
onStart: function ( callback ) {
|
||||
onStartCallback: function ( callback ) {
|
||||
|
||||
this._onStartCallback = callback;
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
onUpdate: function ( callback ) {
|
||||
onUpdateCallback: function ( callback ) {
|
||||
|
||||
this._onUpdateCallback = callback;
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
onComplete: function ( callback ) {
|
||||
onCompleteCallback: function ( callback ) {
|
||||
|
||||
this._onCompleteCallback = callback;
|
||||
return this;
|
||||
@@ -222,6 +224,11 @@ Phaser.Tween.prototype = {
|
||||
|
||||
update: function ( time ) {
|
||||
|
||||
if (this.pendingDelete)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._paused || time < this._startTime) {
|
||||
|
||||
return true;
|
||||
|
||||
@@ -13,6 +13,7 @@ Phaser.TweenManager = function (game) {
|
||||
|
||||
this.game = game;
|
||||
this._tweens = [];
|
||||
this._add = [];
|
||||
|
||||
this.game.onPause.add(this.pauseAll, this);
|
||||
this.game.onResume.add(this.resumeAll, this);
|
||||
@@ -50,7 +51,7 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
add: function ( tween ) {
|
||||
|
||||
this._tweens.push( tween );
|
||||
this._add.push( tween );
|
||||
|
||||
},
|
||||
|
||||
@@ -77,7 +78,7 @@ Phaser.TweenManager.prototype = {
|
||||
|
||||
if ( i !== -1 ) {
|
||||
|
||||
this._tweens.splice( i, 1 );
|
||||
this._tweens[i].pendingDelete = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -90,9 +91,10 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
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 ) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
},
|
||||
|
||||
+45
-5
@@ -119,6 +119,14 @@ Phaser.Utils.Debug.prototype = {
|
||||
this.context.strokeStyle = color;
|
||||
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.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
|
||||
{
|
||||
@@ -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('visible: ' + sprite.visible);
|
||||
this.line('in camera: ' + sprite.inCamera);
|
||||
this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1));
|
||||
|
||||
// 0 = scaleX
|
||||
// 1 = skewY
|
||||
@@ -382,7 +391,6 @@ Phaser.Utils.Debug.prototype = {
|
||||
// 4 = scaleY
|
||||
// 5 = translateY
|
||||
|
||||
|
||||
// this.line('id: ' + sprite._id);
|
||||
// this.line('scale x: ' + sprite.worldTransform[0]);
|
||||
// this.line('scale y: ' + sprite.worldTransform[4]);
|
||||
@@ -390,6 +398,8 @@ Phaser.Utils.Debug.prototype = {
|
||||
// this.line('ty: ' + sprite.worldTransform[5]);
|
||||
// this.line('skew x: ' + sprite.worldTransform[3]);
|
||||
// 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));
|
||||
|
||||
@@ -454,18 +464,48 @@ Phaser.Utils.Debug.prototype = {
|
||||
|
||||
},
|
||||
|
||||
renderSpriteBounds: function (sprite, color) {
|
||||
renderSpriteBody: function (sprite, color) {
|
||||
|
||||
if (this.context == null)
|
||||
{
|
||||
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.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();
|
||||
|
||||
},
|
||||
|
||||
+34
-4
@@ -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 = {
|
||||
|
||||
/**
|
||||
@@ -6,6 +17,11 @@ Phaser.Utils = {
|
||||
* http://www.webtoolkit.info/
|
||||
* pad = the string to pad it out with (defaults to a space)
|
||||
* 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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
// Not plain objects:
|
||||
@@ -67,11 +87,20 @@ Phaser.Utils = {
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
// deep, target, objects to copy to the target object
|
||||
// This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/)
|
||||
// deep (boolean)
|
||||
// target (object to add to)
|
||||
// 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 () {
|
||||
|
||||
var options, name, src, copy, copyIsArray, clone,
|
||||
@@ -147,17 +176,18 @@ Phaser.Utils = {
|
||||
|
||||
// Global functions that PIXI needs
|
||||
|
||||
/**
|
||||
/**
|
||||
* Converts a hex color number to an [R, G, B] array
|
||||
*
|
||||
* @method HEXtoRGB
|
||||
* @param hex {Number}
|
||||
* @param {Number} hex
|
||||
* @return {array}
|
||||
*/
|
||||
function HEXtoRGB(hex) {
|
||||
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* A polyfill for Function.prototype.bind
|
||||
*
|
||||
* @method bind
|
||||
|
||||
Reference in New Issue
Block a user