Lots of fixes and updates to the Button class, InputHandler for snap offsets, Sound looping and Stage scaling.

This commit is contained in:
photonstorm 2013-12-31 17:03:09 +00:00
parent 86f6ddcbc8
commit d1cd1df9a5
13 changed files with 377 additions and 149 deletions

View file

@ -12,7 +12,7 @@ By Richard Davey, [Photon Storm](http://www.photonstorm.com)
View the [Official Website](http://phaser.io)<br />
Follow on [Twitter](https://twitter.com/photonstorm)<br />
Join the [Forum](http://www.html5gamedevs.com/forum/14-phaser/)<br />
Try out 170+ [Phaser Examples](http://gametest.mobi/phaser/examples/)
Try out 200+ [Phaser Examples](http://gametest.mobi/phaser/examples/)
[Subscribe to our new Phaser Newsletter](https://confirmsubscription.com/h/r/369DE48E3E86AF1E). We'll email you when new versions are released as well as send you our regular Phaser game making magazine.
@ -36,6 +36,8 @@ Getting Started Guides
We have a new [Getting Started Guide](http://phaser.io/getting-started-js.php) which covers all you need to begin developing games with Phaser. From setting up a web server to picking an IDE. If you're new to HTML5 game development (or are coming from another language like AS3) then we recommend starting there.
There is a comprehensive [How to Learn Phaser](http://gamedevelopment.tutsplus.com/articles/how-to-learn-the-phaser-html5-game-engine--gamedev-13643) guide on the GameDevTuts+ site which is well worth reading through.
There is also this great [Un-official Getting Started Guide](http://www.antonoffplus.com/coding-an-html5-game-for-30-minutes-or-an-introduction-to-the-phaser-framework) which is well worth running through as well.
@ -50,6 +52,7 @@ Significant API changes:
* TilemapLayers are now created via the Tilemap object itself: map.createLayer(x, y, width, height, tileset, layer, group) and no longer via the GameObjectFactory.
* Tilemap.createFromObjects can now turn a bunch of Tiled objects into Sprites in one single call, and copies across all properties as well.
* Tween.onStartCallback and onCompleteCallback have been removed to avoid confusion. You should use the onStart, onLoop and onComplete events instead.
* Button.forceOut default value has changed from true to false, so Buttons will revert to an Up state (if set) when pressed and released.
New features:
@ -69,6 +72,8 @@ New features:
* Stage.display property added. A direct reference to the root Pixi Stage object (very useful for RenderTexture manipulation)
* Added Ejecta detection to Device (thanks endel)
* Tweens can now work with relative + and - values. You can do: `tween(sprite).to( { x: '+400' })` and it will add 400 to the current sprite.x value, or '-400'.
* Buttons now properly use their upFrame if set.
* InputHandler now has snapOffsetX and snapOffsetY properties so your snap grid doesn't have to be 0,0 aligned (thanks srmeier)
New Examples:
@ -78,7 +83,7 @@ New Examples:
* Physics - Bounce accelerator (use the keyboard) by Patrick OReilly.
* Physics - Bounce knock (use the keyboard) by Patrick OReilly.
* Physics - Snake (use the keyboard to control the snake like creature) by Patrick OReilly and Richard Davey.
* Added touch joystick example showing how to use the clay.io virtual game controller (thanks gabehollombe)
* Input - Touch Joystick example showing how to use the clay.io virtual game controller (thanks gabehollombe)
* Games - Matching Pairs by Patrick OReilly.
* Tweens - Example showing how to use the tween events, onStart, onLoop and onComplete.
* Display - Pixi Render Texture. A Phaser conversion of the Pixi.js Render Texture example.
@ -90,10 +95,10 @@ New Examples:
Updates:
* Updated to latest Pixi.js dev branch build
* When a Sprite is destroyed any active filters are removed as well.
* Updated to latest Pixi.js dev branch build.
* When a Sprite is destroyed any active filters are removed at the same time.
* Updated Pixi.js so that removing filters now works correctly without breaking the display list.
* Phaser.Canvas.create updated to it can be given an ID as the 3rd parameter.
* Phaser.Canvas.create updated so it can be given an ID as the 3rd parameter (can also be set via new Game configuration object).
* Updated display/fullscreen example to reflect new full screen change.
* Loads of updates to the TypeScript definitions files - games fully compile now and lots of missing classes added :)
* Removed 'null parent' check from Group constructor. Will parent to game.world only if parent value is undefined.
@ -113,6 +118,7 @@ Updates:
* RenderTexture.render / renderXY has a new parameter: renderHidden, a boolean which will allow you to render Sprites even if their visible is set to false.
* Added in prototype.constructor definitions to every class (thanks darkoverlordofdata)
* Group.destroy has a new parameter: destroyChildren (boolean) which will optionally call the destroy method of all Group children.
* Button.clearFrames method has been added.
Bug Fixes:
@ -133,6 +139,9 @@ Bug Fixes:
* Patched desyrel.xml so it doesn't contain any zero width/height characters, as they broke Firefox 25.
* Cache.addSound now implements a locked attribute (thanks haden)
* Sound now checks for CocoonJS during playback to avoid readyState clash (thanks haden)
* Buttons now clear previously set frames correctly if you call setFrames.
* Sounds will now loop correctly if they are paused and resumed (thanks haden)
* InputHandler.checkBoundsRect and checkBoundsSprite now take into account if the Sprite is fixedToCamera or not.
You can view the Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
@ -185,7 +194,7 @@ Phaser is 321 KB minified and 72 KB gzipped.
Learn By Example
----------------
Phaser comes with an ever growing suite of Examples. Personally I feel that we learn better by looking at small refined code examples, so we created over 170 of them and create new ones to test every new feature added. Inside the `examples` folder you'll find the current set. If you write a particularly good example then please send it to us.
Phaser comes with an ever growing suite of Examples. Personally I feel that we learn better by looking at small refined code examples, so we created over 200 of them and create new ones to test every new feature added. Inside the `examples` folder you'll find the current set. If you write a particularly good example then please send it to us.
The examples need to be run through a local web server (in order to avoid file access permission errors from your browser). You can use your own web server, or start the included web server using grunt.
@ -193,7 +202,7 @@ Using a locally installed web server browse to the examples folder:
examples/index.html
Alternatively in order to start the included web server, after you've cloned the repo, run `npm install` to install all dependencies, then `grunt connect `to start a local server. After running this command you should be able to access your local webserver at `http://127.0.0.1:8000`. Then browse to the examples folder: `http://127.0.0.1:8000/examples/index.html`
Alternatively in order to start the included web server, after you've cloned the repo, run `npm install` to install all dependencies, then `grunt connect` to start a local server. After running this command you should be able to access your local webserver at `http://127.0.0.1:8000`. Then browse to the examples folder: `http://127.0.0.1:8000/examples/index.html`
There is a new 'Side View' example viewer as well. This loads all the examples into a left-hand frame for faster navigation.
@ -276,16 +285,15 @@ Road Map
The 1.1 release was a massive under-taking, but we're really happy with how Phaser is progressing. It's becoming more solid and versatile with each iteration. Here is what's on our road map for future versions:
Versions 1.2 ("Saldaea")
Version 1.2 ("Saldaea")
* Integration with the p2.js physics system.
* Enhance the State Management, so you can perform non-destructive State swaps and persistence.
* Update to Pixi 1.5 - currently still in dev branch only, but lots of nice internal changes and new features.
* Update to Pixi 1.5 - currently still in dev branch only, but lots of nice internal changes and new features we want to take advantage of.
* Start integration with the p2.js physics system.
Beyond version 1.2
* Enhance the State Management, so you can perform non-destructive State swaps and persistence.
* Dedicated CocoonJS packaging features (screencanvas, etc)
* The ability to pass in a configuration option on Game boot, containing more advanced configuration features.
* A more advanced Particle system, one that can render to a single canvas (rather than spawn hundreds of Sprites), more advanced effects, etc.
* Massively enhance the audio side of Phaser. Although it does what it does well, it could do with taking more advantage of Web Audio - echo effects, positional sound, etc.
* Comprehensive testing across Firefox OS devices, CocoonJS and Ejecta.
@ -306,13 +314,15 @@ Beyond version 1.2
Contributing
------------
If you find a bug (highly likely!) then please report it on github or our forum.
If you find a bug 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.
If you have a feature request, or have written a game or demo that shows Phaser in use, then please get in touch. We'd love to hear from you.
You can do this on the Phaser board that is part of the [HTML5 Game Devs forum](http://www.html5gamedevs.com/forum/14-phaser/) or email: rich@photonstorm.com
Before submitting a pull request, please run your code through [JSHint](http://www.jshint.com/) to check for stylistic or formatting errors. To use JSHint, first install it by running `npm install jshint`, then test your code by running `jshint src`. This isn't a requirement, we are happy to receive pull requests that haven't been JSHinted, so don't let it put you off contributing - but do know that we'll reformat your source before going live with it.
If you issue a Pull Request for Phaser, please only ever do so againt the `dev` branch and *not* against the `master` branch.
Before submitting a pull request please run your code through [JSHint](http://www.jshint.com/) to check for stylistic or formatting errors. To use JSHint, first install it by running `npm install jshint`, then test your code by running `jshint src`. This isn't a requirement, we are happy to receive pull requests that haven't been JSHinted, so don't let it put you off contributing - but do know that we'll reformat your source before going live with it.
Bugs?

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

View file

@ -0,0 +1,46 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.audio('music', 'assets/audio/CatAstroPhi_shmup_normal.wav');
}
var music;
function create() {
music = game.add.audio('music');
// play: function (marker, position, volume, loop, forceRestart) {
music.play('', 0, 1, true);
game.input.onDown.add(toggleAudio, this);
}
function toggleAudio() {
if (music.isPlaying)
{
music.pause();
}
else
{
music.resume();
}
}
function update() {
}
function render() {
game.debug.renderSoundInfo(music, 32, 32);
}

View file

@ -19,16 +19,17 @@
* @constructor
*
* @param {Phaser.Game} game Current game instance.
* @param {number} [x] - X position of the Button.
* @param {number} [y] - Y position of the Button.
* @param {number} [x=0] - X position of the Button.
* @param {number} [y=0] - 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.
* @param {string|number} [upFrame] - This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
*/
Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame) {
x = x || 0;
y = y || 0;
@ -63,7 +64,7 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
* @default
*/
this._onDownFrameName = null;
/**
* @property {string} _onUpFrameName - Internal variable.
* @private
@ -91,7 +92,7 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
* @default
*/
this._onDownFrameID = null;
/**
* @property {number} _onUpFrameID - Internal variable.
* @private
@ -173,13 +174,13 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
this.freezeFrames = false;
/**
* When the Button is clicked you can optionally force the state to "out".
* When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".
* @property {boolean} forceOut
* @default
*/
this.forceOut = true;
this.forceOut = false;
this.setFrames(overFrame, outFrame, downFrame);
this.setFrames(overFrame, outFrame, downFrame, upFrame);
if (callback !== null)
{
@ -201,15 +202,38 @@ Phaser.Button.prototype = Phaser.Utils.extend(true, Phaser.Button.prototype, Pha
Phaser.Button.prototype.constructor = Phaser.Button;
/**
* Used to manually set the frames that will be used for the different states of the button
* exactly like setting them in the constructor.
* Clears all of the frames set on this Button.
*
* @method Phaser.Button.prototype.clearFrames
*/
Phaser.Button.prototype.clearFrames = function () {
this._onOverFrameName = null;
this._onOverFrameID = null;
this._onOutFrameName = null;
this._onOutFrameID = null;
this._onDownFrameName = null;
this._onDownFrameID = null;
this._onUpFrameName = null;
this._onUpFrameID = null;
}
/**
* Used to manually set the frames that will be used for the different states of the Button.
*
* @method Phaser.Button.prototype.setFrames
* @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.
* @param {string|number} [upFrame] - This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
*/
Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame, upFrame) {
this.clearFrames();
if (overFrame !== null)
{
@ -238,7 +262,6 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
if (typeof outFrame === 'string')
{
this._onOutFrameName = outFrame;
this._onUpFrameName = outFrame;
if (this.input.pointerOver() === false)
{
@ -248,7 +271,6 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
else
{
this._onOutFrameID = outFrame;
this._onUpFrameID = outFrame;
if (this.input.pointerOver() === false)
{
@ -279,6 +301,28 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
}
}
if (upFrame !== null)
{
if (typeof upFrame === 'string')
{
this._onUpFrameName = upFrame;
if (this.input.pointerUp())
{
this.frameName = upFrame;
}
}
else
{
this._onUpFrameID = upFrame;
if (this.input.pointerUp())
{
this.frame = upFrame;
}
}
}
};
/**
@ -300,8 +344,8 @@ Phaser.Button.prototype.setSounds = function (overSound, overMarker, downSound,
this.setOverSound(overSound, overMarker);
this.setOutSound(outSound, outMarker);
this.setUpSound(upSound, upMarker);
this.setDownSound(downSound, downMarker);
this.setUpSound(upSound, upMarker);
}
@ -354,31 +398,7 @@ Phaser.Button.prototype.setOutSound = function (sound, marker) {
}
/**
* The Sound to be played when a Pointer clicks on this Button.
*
* @method Phaser.Button.prototype.setUpSound
* @param {Phaser.Sound} sound - The Sound that will be played.
* @param {string} [marker] - A Sound Marker that will be used in the playback.
*/
Phaser.Button.prototype.setUpSound = function (sound, marker) {
this.onUpSound = null;
this.onUpSoundMarker = '';
if (sound instanceof Phaser.Sound)
{
this.onUpSound = sound;
}
if (typeof marker === 'string')
{
this.onUpSoundMarker = marker;
}
}
/**
* The Sound to be played when a Pointer clicks on this Button.
* The Sound to be played when a Pointer presses down on this Button.
*
* @method Phaser.Button.prototype.setDownSound
* @param {Phaser.Sound} sound - The Sound that will be played.
@ -401,25 +421,43 @@ Phaser.Button.prototype.setDownSound = function (sound, marker) {
}
/**
* The Sound to be played when a Pointer has pressed down and is released from this Button.
*
* @method Phaser.Button.prototype.setUpSound
* @param {Phaser.Sound} sound - The Sound that will be played.
* @param {string} [marker] - A Sound Marker that will be used in the playback.
*/
Phaser.Button.prototype.setUpSound = function (sound, marker) {
this.onUpSound = null;
this.onUpSoundMarker = '';
if (sound instanceof Phaser.Sound)
{
this.onUpSound = sound;
}
if (typeof marker === 'string')
{
this.onUpSoundMarker = marker;
}
}
/**
* Internal function that handles input events.
*
* @protected
* @method Phaser.Button.prototype.onInputOverHandler
* @param {Phaser.Button} sprite - The Button that the event occured on.
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
*/
Phaser.Button.prototype.onInputOverHandler = function (pointer) {
Phaser.Button.prototype.onInputOverHandler = function (sprite, pointer) {
if (this.freezeFrames === false)
{
if (this._onOverFrameName != null)
{
this.frameName = this._onOverFrameName;
}
else if (this._onOverFrameID != null)
{
this.frame = this._onOverFrameID;
}
this.setState(1);
}
if (this.onOverSound)
@ -438,20 +476,14 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) {
*
* @protected
* @method Phaser.Button.prototype.onInputOverHandler
* @param {Phaser.Button} sprite - The Button that the event occured on.
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
*/
Phaser.Button.prototype.onInputOutHandler = function (pointer) {
Phaser.Button.prototype.onInputOutHandler = function (sprite, pointer) {
if (this.freezeFrames === false)
{
if (this._onOutFrameName != null)
{
this.frameName = this._onOutFrameName;
}
else if (this._onOutFrameID != null)
{
this.frame = this._onOutFrameID;
}
this.setState(2);
}
if (this.onOutSound)
@ -470,20 +502,14 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) {
*
* @protected
* @method Phaser.Button.prototype.onInputOverHandler
* @param {Phaser.Button} sprite - The Button that the event occured on.
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
*/
Phaser.Button.prototype.onInputDownHandler = function (pointer) {
Phaser.Button.prototype.onInputDownHandler = function (sprite, pointer) {
if (this.freezeFrames === false)
{
if (this._onDownFrameName != null)
{
this.frameName = this._onDownFrameName;
}
else if (this._onDownFrameID != null)
{
this.frame = this._onDownFrameID;
}
this.setState(3);
}
if (this.onDownSound)
@ -502,12 +528,100 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) {
*
* @protected
* @method Phaser.Button.prototype.onInputOverHandler
* @param {Phaser.Button} sprite - The Button that the event occured on.
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
*/
Phaser.Button.prototype.onInputUpHandler = function (pointer) {
Phaser.Button.prototype.onInputUpHandler = function (sprite, pointer, isOver) {
if (this.freezeFrames === false)
if (this.onUpSound)
{
this.onUpSound.play(this.onUpSoundMarker);
}
if (this.onInputUp)
{
this.onInputUp.dispatch(this, pointer, isOver);
}
if (this.freezeFrames)
{
return;
}
if (this.forceOut)
{
// Button should be forced to the Out frame when released.
this.setState(2);
}
else
{
if (this._onUpFrameName || this._onUpFrameID)
{
this.setState(4);
}
else
{
if (isOver)
{
this.setState(1);
}
else
{
this.setState(2);
}
}
}
};
/**
* Internal function that handles Button state changes.
*
* @protected
* @method Phaser.Button.prototype.setState
* @param {number} newState - The new State of the Button.
*/
Phaser.Button.prototype.setState = function (newState) {
if (newState === 1)
{
// Over
if (this._onOverFrameName != null)
{
this.frameName = this._onOverFrameName;
}
else if (this._onOverFrameID != null)
{
this.frame = this._onOverFrameID;
}
}
else if (newState === 2)
{
// Out
if (this._onOutFrameName != null)
{
this.frameName = this._onOutFrameName;
}
else if (this._onOutFrameID != null)
{
this.frame = this._onOutFrameID;
}
}
else if (newState === 3)
{
// Down
if (this._onDownFrameName != null)
{
this.frameName = this._onDownFrameName;
}
else if (this._onDownFrameID != null)
{
this.frame = this._onDownFrameID;
}
}
else if (newState === 4)
{
// Up
if (this._onUpFrameName != null)
{
this.frameName = this._onUpFrameName;
@ -518,26 +632,4 @@ Phaser.Button.prototype.onInputUpHandler = function (pointer) {
}
}
if (this.onUpSound)
{
this.onUpSound.play(this.onUpSoundMarker);
}
if (this.forceOut && this.freezeFrames === false)
{
if (this._onOutFrameName != null)
{
this.frameName = this._onOutFrameName;
}
else if (this._onOutFrameID != null)
{
this.frame = this._onOutFrameID;
}
}
if (this.onInputUp)
{
this.onInputUp.dispatch(this, pointer);
}
};

View file

@ -187,14 +187,15 @@ Phaser.GameObjectFactory.prototype = {
* @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.
* @param {string|number} [upFrame] This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Button} The newly created button object.
*/
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, group) {
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group) {
if (typeof group === 'undefined') { group = this.world; }
return group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
return group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame));
},

View file

@ -94,6 +94,18 @@ Phaser.InputHandler = function (sprite) {
*/
this.snapY = 0;
/**
* @property {number} snapOffsetX - This defines the top-left X coordinate of the snap grid.
* @default
*/
this.snapOffsetX = 0;
/**
* @property {number} snapOffsetY - This defines the top-left Y coordinate of the snap grid..
* @default
*/
this.snapOffsetY = 0;
/**
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
* @default
@ -666,11 +678,14 @@ Phaser.InputHandler.prototype = {
// Only release the InputUp signal if the pointer is still over this sprite
if (this.checkPointerOver(pointer))
{
//console.log('releasedHandler: ' + Date.now());
this.sprite.events.onInputUp.dispatch(this.sprite, pointer);
// Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not
this.sprite.events.onInputUp.dispatch(this.sprite, pointer, true);
}
else
{
// Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not
this.sprite.events.onInputUp.dispatch(this.sprite, pointer, false);
// Pointer outside the sprite? Reset the cursor
if (this.useHandCursor)
{
@ -725,8 +740,8 @@ Phaser.InputHandler.prototype = {
if (this.snapOnDrag)
{
this.sprite.cameraOffset.x = Math.round(this.sprite.x / this.snapX) * this.snapX;
this.sprite.cameraOffset.y = Math.round(this.sprite.y / this.snapY) * this.snapY;
this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
}
}
else
@ -753,8 +768,8 @@ Phaser.InputHandler.prototype = {
if (this.snapOnDrag)
{
this.sprite.x = Math.round(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.round(this.sprite.y / this.snapY) * this.snapY;
this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
}
}
@ -986,13 +1001,13 @@ Phaser.InputHandler.prototype = {
{
if (this.sprite.fixedToCamera)
{
this.sprite.cameraOffset.x = Math.round(this.sprite.cameraOffset.x / this.snapX) * this.snapX;
this.sprite.cameraOffset.y = Math.round(this.sprite.cameraOffset.y / this.snapY) * this.snapY;
this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
}
else
{
this.sprite.x = Math.round(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.round(this.sprite.y / this.snapY) * this.snapY;
this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
}
}
@ -1030,14 +1045,20 @@ Phaser.InputHandler.prototype = {
* @param {number} snapY - The height of the grid cell to snap to.
* @param {boolean} [onDrag=true] - If true the sprite will snap to the grid while being dragged.
* @param {boolean} [onRelease=false] - If true the sprite will snap to the grid when released.
* @param {number} [snapOffsetX=0] - Used to offset the top-left starting point of the snap grid.
* @param {number} [snapOffsetX=0] - Used to offset the top-left starting point of the snap grid.
*/
enableSnap: function (snapX, snapY, onDrag, onRelease) {
enableSnap: function (snapX, snapY, onDrag, onRelease, snappOffsetX, snappOffsetY) {
if (typeof onDrag == 'undefined') { onDrag = true; }
if (typeof onRelease == 'undefined') { onRelease = false; }
if (typeof snapOffsetX == 'undefined') { snapOffsetX = 0; }
if (typeof snapOffsetY == 'undefined') { snapOffsetY = 0; }
this.snapX = snapX;
this.snapY = snapY;
this.snapOffsetX = snapOffsetX;
this.snapOffsetY = snapOffsetY;
this.snapOnDrag = onDrag;
this.snapOnRelease = onRelease;
@ -1060,22 +1081,45 @@ Phaser.InputHandler.prototype = {
*/
checkBoundsRect: function () {
if (this.sprite.x < this.boundsRect.left)
if (this.sprite.fixedToCamera)
{
this.sprite.x = this.boundsRect.x;
}
else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right)
{
this.sprite.x = this.boundsRect.right - this.sprite.width;
}
if (this.sprite.cameraOffset.x < this.boundsRect.left)
{
this.sprite.cameraOffset.x = this.boundsRect.cameraOffset.x;
}
else if ((this.sprite.cameraOffset.x + this.sprite.width) > this.boundsRect.right)
{
this.sprite.cameraOffset.x = this.boundsRect.right - this.sprite.width;
}
if (this.sprite.y < this.boundsRect.top)
{
this.sprite.y = this.boundsRect.top;
if (this.sprite.cameraOffset.y < this.boundsRect.top)
{
this.sprite.cameraOffset.y = this.boundsRect.top;
}
else if ((this.sprite.cameraOffset.y + this.sprite.height) > this.boundsRect.bottom)
{
this.sprite.cameraOffset.y = this.boundsRect.bottom - this.sprite.height;
}
}
else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom)
else
{
this.sprite.y = this.boundsRect.bottom - this.sprite.height;
if (this.sprite.x < this.boundsRect.left)
{
this.sprite.x = this.boundsRect.x;
}
else if ((this.sprite.x + this.sprite.width) > this.boundsRect.right)
{
this.sprite.x = this.boundsRect.right - this.sprite.width;
}
if (this.sprite.y < this.boundsRect.top)
{
this.sprite.y = this.boundsRect.top;
}
else if ((this.sprite.y + this.sprite.height) > this.boundsRect.bottom)
{
this.sprite.y = this.boundsRect.bottom - this.sprite.height;
}
}
},
@ -1086,22 +1130,45 @@ Phaser.InputHandler.prototype = {
*/
checkBoundsSprite: function () {
if (this.sprite.x < this.boundsSprite.x)
if (this.sprite.fixedToCamera && this.boundsSprite.fixedToCamera)
{
this.sprite.x = this.boundsSprite.x;
}
else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
{
this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width;
}
if (this.sprite.cameraOffset.x < this.boundsSprite.camerOffset.x)
{
this.sprite.cameraOffset.x = this.boundsSprite.camerOffset.x;
}
else if ((this.sprite.cameraOffset.x + this.sprite.width) > (this.boundsSprite.camerOffset.x + this.boundsSprite.width))
{
this.sprite.cameraOffset.x = (this.boundsSprite.camerOffset.x + this.boundsSprite.width) - this.sprite.width;
}
if (this.sprite.y < this.boundsSprite.y)
{
this.sprite.y = this.boundsSprite.y;
if (this.sprite.cameraOffset.y < this.boundsSprite.camerOffset.y)
{
this.sprite.cameraOffset.y = this.boundsSprite.camerOffset.y;
}
else if ((this.sprite.cameraOffset.y + this.sprite.height) > (this.boundsSprite.camerOffset.y + this.boundsSprite.height))
{
this.sprite.cameraOffset.y = (this.boundsSprite.camerOffset.y + this.boundsSprite.height) - this.sprite.height;
}
}
else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
else
{
this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height;
if (this.sprite.x < this.boundsSprite.x)
{
this.sprite.x = this.boundsSprite.x;
}
else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
{
this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width;
}
if (this.sprite.y < this.boundsSprite.y)
{
this.sprite.y = this.boundsSprite.y;
}
else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
{
this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height;
}
}
}

View file

@ -346,25 +346,25 @@ Phaser.Sound.prototype = {
{
if (this.loop)
{
//console.log('loop1');
// console.log('loop1');
// won't work with markers, needs to reset the position
this.onLoop.dispatch(this);
if (this.currentMarker === '')
{
//console.log('loop2');
// console.log('loop2');
this.currentTime = 0;
this.startTime = this.game.time.now;
}
else
{
//console.log('loop3');
// console.log('loop3');
this.play(this.currentMarker, 0, this.volume, true, true);
}
}
else
{
//console.log('stopping, no loop for marker');
// console.log('stopping, no loop for marker');
this.stop();
}
}
@ -642,7 +642,20 @@ Phaser.Sound.prototype = {
this._sound = this.context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this.gainNode);
if (this.externalNode)
{
this._sound.connect(this.externalNode.input);
}
else
{
this._sound.connect(this.gainNode);
}
if (this.loop)
{
this._sound.loop = true;
}
if (typeof this._sound.start === 'undefined')
{

View file

@ -260,7 +260,7 @@ Phaser.StageScaleMode.prototype = {
this._width = this.width;
this._height = this.height;
console.log('startFullScreen', this._width, this._height);
// console.log('startFullScreen', this._width, this._height);
if (element['requestFullScreen'])
{
@ -328,7 +328,6 @@ Phaser.StageScaleMode.prototype = {
this.game.stage.scale.setShowAll();
this.game.stage.scale.refresh();
}
}
else
{