* Removed the callbackContext parameter from Group.callAll because it's no longer needed.

* Updated Group.forEach, forEachAlive and forEachDead so you can now pass as many parameters as you want, which will all be given to the callback after the child.
* Updated build script so it can be run from the command-line and includes UMD wrappers (thanks iaincarsberg)
This commit is contained in:
Richard Davey
2013-10-01 02:19:08 +01:00
parent 8668b82ef6
commit 480d90b009
6 changed files with 375 additions and 56 deletions
+3 -1
View File
@@ -67,7 +67,9 @@ Version 1.0.7 (in progress in the dev branch)
* Loaded.setPreloadSprite now rounds the width/height values and starts from 1. This fixes canvas draw errors in IE9/10 and Firefox.
* Fixed issue causing Keyboard.justPressed to always fire (thanks stemkoski)
* Added Keyboard.addKey() which creates a new Phaser.Key object that can be polled for updates, pressed states, etc. See the 2 new examples showing use.
* Removed the callbackContext parameter from Group.callAll because it's no longer needed.
* Updated Group.forEach, forEachAlive and forEachDead so you can now pass as many parameters as you want, which will all be given to the callback after the child.
* Updated build script so it can be run from the command-line and includes UMD wrappers (thanks iaincarsberg)
+38 -13
View File
@@ -1,15 +1,14 @@
<a href="http://yui.2clics.net/">Minify it</a><br />
<textarea style="width: 800px; height: 800px">
<?php
date_default_timezone_set('Europe/London');
// Get the version number
// VERSION: '1.0.5',
$vf = file_get_contents('../src/Phaser.js');
$vf = file_get_contents(dirname(__FILE__) . '/../src/Phaser.js');
$version = substr($vf, strpos($vf, 'VERSION: ') + 10, 5);
$buildLog = "Building version $version \n\n";
$header = "";
echo "Building version $version \n\n";
$js = file('../examples/js.php');
$js = file(dirname(__FILE__) . '/../examples/js.php');
$output = "";
for ($i = 0; $i < count($js); $i++)
@@ -20,10 +19,10 @@
if (strpos($line, '<script') !== false)
{
$line = str_replace('<script src="', '', $line);
$line = str_replace('"></script>', '', $line);
$line = dirname(__FILE__) . DIRECTORY_SEPARATOR . str_replace('"></script>', '', $line);
$filename = substr($line, strrpos($line, '/') + 1);
echo $line . "\n";
$buildLog .= $line . "\n";
// echo $filename . "\n";
// Read the file in
@@ -36,15 +35,41 @@
// {version}
$source = str_replace('{version}', $version, $source);
}
$output .= $source . "\n";
// Set the header
$header = $source;
} else {
$output .= $source . "\n";
}
}
}
//echo $output;
// Create a UMD wrapper, to allow Phaser to be exposed to AMD, Node and Browsers
$template = <<<EOT
%s(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Phaser = factory();
}
}(this, function (b) {
%s
return Phaser;
}));
EOT;
file_put_contents('phaser.js', $output);
file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phaser.js', sprintf($template, $header, $output));
if(php_sapi_name() == 'cli' || empty($_SERVER['REMOTE_ADDR'])) {
echo "\ndone\n\n";
return;
}
?>
<a href="http://yui.2clics.net/">Minify it</a><br />
<textarea style="width: 800px; height: 800px">
<?php echo $buildLog; ?>
</textarea>
+256 -32
View File
@@ -1,7 +1,7 @@
/**
* Phaser - http://www.phaser.io
*
* v1.0.7 - Built at: Mon, 30 Sep 2013 21:50:07 +0000
* v1.0.7 - Built at: Tue, 01 Oct 2013 02:14:43 +0100
*
* @author Richard Davey http://www.photonstorm.com @photonstorm
*
@@ -19,7 +19,15 @@
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Phaser = factory();
}
}(this, function (b) {
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
@@ -9435,12 +9443,11 @@ Phaser.Group.prototype = {
/**
* 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.
* After the function you can add as many parameters as you like, which will all be passed to the child.
*/
callAll: function (callback, callbackContext) {
callAll: function (callback) {
var args = Array.prototype.splice.call(arguments, 2);
var args = Array.prototype.splice.call(arguments, 1);
if (this._container.children.length > 0 && this._container.first._iNext)
{
@@ -9461,9 +9468,16 @@ Phaser.Group.prototype = {
},
// After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
forEach: function (callback, callbackContext, checkExists) {
if (typeof checkExists == 'undefined') { checkExists = false; }
if (typeof checkExists === 'undefined')
{
checkExists = false;
}
var args = Array.prototype.splice.call(arguments, 3);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
@@ -9473,7 +9487,8 @@ Phaser.Group.prototype = {
{
if (checkExists == false || (checkExists && currentNode.exists))
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;
@@ -9486,6 +9501,9 @@ Phaser.Group.prototype = {
forEachAlive: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
var currentNode = this._container.first._iNext;
@@ -9494,7 +9512,8 @@ Phaser.Group.prototype = {
{
if (currentNode.alive)
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;
@@ -9507,6 +9526,9 @@ Phaser.Group.prototype = {
forEachDead: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
var currentNode = this._container.first._iNext;
@@ -9515,7 +9537,8 @@ Phaser.Group.prototype = {
{
if (currentNode.alive == false)
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;
@@ -10997,6 +11020,7 @@ Phaser.Input.prototype = {
if (this.pointer10) { this.pointer10.update(); }
this._pollCounter = 0;
},
/**
@@ -11336,11 +11360,161 @@ Object.defineProperty(Phaser.Input.prototype, "worldY", {
});
Phaser.Key = function (game, keycode) {
this.game = game;
/**
*
* @property isDown
* @type Boolean
**/
this.isDown = false;
/**
*
* @property isUp
* @type Boolean
**/
this.isUp = false;
/**
*
* @property altKey
* @type Boolean
**/
this.altKey = false;
/**
*
* @property ctrlKey
* @type Boolean
**/
this.ctrlKey = false;
/**
*
* @property shiftKey
* @type Boolean
**/
this.shiftKey = false;
/**
*
* @property timeDown
* @type Number
**/
this.timeDown = 0;
/**
*
* @property duration
* @type Number
**/
this.duration = 0;
/**
*
* @property timeUp
* @type Number
**/
this.timeUp = 0;
/**
*
* @property repeats
* @type Number
**/
this.repeats = 0;
this.keyCode = keycode;
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
};
Phaser.Key.prototype = {
/**
*
* @method update
* @param {KeyboardEvent} event.
* @return {}
*/
processKeyDown: function (event) {
this.altKey = event.altKey;
this.ctrlKey = event.ctrlKey;
this.shiftKey = event.shiftKey;
if (this.isDown)
{
// Key was already held down, this must be a repeat rate based event
this.duration = event.timeStamp - this.timeDown;
this.repeats++;
}
else
{
this.isDown = true;
this.isUp = false;
this.timeDown = event.timeStamp;
this.duration = 0;
this.repeats = 0;
this.onDown.dispatch(this);
}
},
processKeyUp: function (event) {
this.isDown = false;
this.isUp = true;
this.timeUp = event.timeStamp;
this.onUp.dispatch(this);
},
/**
* @param {Number} [duration]
* @return {bool}
*/
justPressed: function (duration) {
if (typeof duration === "undefined") { duration = 250; }
return (this.isDown && this.duration < duration);
},
/**
* @param {Number} [duration]
* @return {bool}
*/
justReleased: function (duration) {
if (typeof duration === "undefined") { duration = 250; }
return (this.isDown == false && (this.game.time.now - this.timeUp < duration));
}
};
Phaser.Keyboard = function (game) {
this.game = game;
this._keys = {};
this._hotkeys = {};
this._capture = {};
this.callbackContext = this;
this.onDownCallback = null;
this.onUpCallback = null;
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
};
@@ -11357,16 +11531,41 @@ Phaser.Keyboard.prototype = {
_onKeyDown: null,
_onKeyUp: null,
addCallbacks: function (context, onDown, onUp) {
this.callbackContext = context;
this.onDownCallback = onDown;
if (typeof onUp !== 'undefined')
{
this.onUpCallback = onUp;
}
},
addKey: function (keycode) {
this._hotkeys[keycode] = new Phaser.Key(this.game, keycode);
return this._hotkeys[keycode];
},
removeKey: function (keycode) {
delete (this._hotkeys[keycode]);
},
start: function () {
var _this = this;
this._onKeyDown = function (event) {
return _this.onKeyDown(event);
return _this.processKeyDown(event);
};
this._onKeyUp = function (event) {
return _this.onKeyUp(event);
return _this.processKeyUp(event);
};
document.body.addEventListener('keydown', this._onKeyDown, false);
@@ -11418,10 +11617,11 @@ Phaser.Keyboard.prototype = {
},
/**
* @param {KeyboardEvent} event
*/
onKeyDown: function (event) {
processKeyDown: function (event) {
if (this.game.input.disabled || this.disabled)
{
@@ -11433,18 +11633,40 @@ Phaser.Keyboard.prototype = {
event.preventDefault();
}
if (!this._keys[event.keyCode])
if (this.onDownCallback)
{
this._keys[event.keyCode] = {
isDown: true,
timeDown: this.game.time.now,
timeUp: 0
};
this.onDownCallback.call(this.callbackContext, event);
}
if (this._keys[event.keyCode] && this._keys[event.keyCode].isDown)
{
// Key already down and still down, so update
this._keys[event.keyCode].duration = this.game.time.now - this._keys[event.keyCode].timeDown;
}
else
{
this._keys[event.keyCode].isDown = true;
this._keys[event.keyCode].timeDown = this.game.time.now;
if (!this._keys[event.keyCode])
{
// Not used this key before, so register it
this._keys[event.keyCode] = {
isDown: true,
timeDown: this.game.time.now,
timeUp: 0,
duration: 0
};
}
else
{
// Key used before but freshly down
this._keys[event.keyCode].isDown = true;
this._keys[event.keyCode].timeDown = this.game.time.now;
this._keys[event.keyCode].duration = 0;
}
}
if (this._hotkeys[event.keyCode])
{
this._hotkeys[event.keyCode].processKeyDown(event);
}
},
@@ -11452,7 +11674,7 @@ Phaser.Keyboard.prototype = {
/**
* @param {KeyboardEvent} event
*/
onKeyUp: function (event) {
processKeyUp: function (event) {
if (this.game.input.disabled || this.disabled)
{
@@ -11464,20 +11686,19 @@ Phaser.Keyboard.prototype = {
event.preventDefault();
}
if (!this._keys[event.keyCode])
if (this.onUpCallback)
{
this._keys[event.keyCode] = {
isDown: false,
timeDown: 0,
timeUp: this.game.time.now
};
this.onUpCallback.call(this.callbackContext, event);
}
else
if (this._hotkeys[event.keyCode])
{
this._keys[event.keyCode].isDown = false;
this._keys[event.keyCode].timeUp = this.game.time.now;
this._hotkeys[event.keyCode].processKeyUp(event);
}
this._keys[event.keyCode].isDown = false;
this._keys[event.keyCode].timeUp = this.game.time.now;
},
reset: function () {
@@ -11498,7 +11719,7 @@ Phaser.Keyboard.prototype = {
if (typeof duration === "undefined") { duration = 250; }
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration))
if (this._keys[keycode] && this._keys[keycode].isDown && this._keys[keycode].duration < duration)
{
return true;
}
@@ -29658,3 +29879,6 @@ PIXI.WebGLBatch.prototype.update = function()
}
}
return Phaser;
}));
@@ -0,0 +1,53 @@
<?php
$title = "Group move towards object";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('ball', 'assets/sprites/shinyball.png');
}
var balls;
function create() {
balls = game.add.group();
for (var i = 0; i < 50; i++)
{
balls.create(game.world.randomX, game.world.randomY, 'ball');
}
}
function update() {
if (game.input.mousePointer.isDown)
{
// First is the callback
// Second is the context in which the callback runs, in this case game.physics
// Third is the parameter the callback expects - it is always sent the Group child as the first parameter
balls.forEach(game.physics.moveTowardsMouse, game.physics, false, 200);
}
else
{
balls.setAll('body.velocity.x', 0);
balls.setAll('body.velocity.y', 0);
}
}
})();
</script>
<?php
require('../foot.php');
?>
+2 -2
View File
@@ -1,8 +1,8 @@
{
"name": "Phaser",
"version": "1.0.0",
"version": "1.0.7",
"description": "html5 game framework",
"main": "index.js",
"main": "build/phaser.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
+23 -8
View File
@@ -401,12 +401,11 @@ Phaser.Group.prototype = {
/**
* 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.
* After the function you can add as many parameters as you like, which will all be passed to the child.
*/
callAll: function (callback, callbackContext) {
callAll: function (callback) {
var args = Array.prototype.splice.call(arguments, 2);
var args = Array.prototype.splice.call(arguments, 1);
if (this._container.children.length > 0 && this._container.first._iNext)
{
@@ -427,9 +426,16 @@ Phaser.Group.prototype = {
},
// After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
forEach: function (callback, callbackContext, checkExists) {
if (typeof checkExists == 'undefined') { checkExists = false; }
if (typeof checkExists === 'undefined')
{
checkExists = false;
}
var args = Array.prototype.splice.call(arguments, 3);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
@@ -439,7 +445,8 @@ Phaser.Group.prototype = {
{
if (checkExists == false || (checkExists && currentNode.exists))
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;
@@ -452,6 +459,9 @@ Phaser.Group.prototype = {
forEachAlive: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
var currentNode = this._container.first._iNext;
@@ -460,7 +470,8 @@ Phaser.Group.prototype = {
{
if (currentNode.alive)
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;
@@ -473,6 +484,9 @@ Phaser.Group.prototype = {
forEachDead: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
args.unshift(null);
if (this._container.children.length > 0 && this._container.first._iNext)
{
var currentNode = this._container.first._iNext;
@@ -481,7 +495,8 @@ Phaser.Group.prototype = {
{
if (currentNode.alive == false)
{
callback.call(callbackContext, currentNode);
args[0] = currentNode;
callback.apply(callbackContext, args);
}
currentNode = currentNode._iNext;