mirror of
https://github.com/photonstorm/phaser
synced 2024-12-02 17:41:06 +00:00
Merge branch 'dev' of https://github.com/photonstorm/phaser into dev
This commit is contained in:
commit
d53cf52d50
56 changed files with 11230 additions and 1634 deletions
11
Gruntfile.js
11
Gruntfile.js
|
@ -62,6 +62,7 @@ module.exports = function (grunt) {
|
|||
'p2': { 'description': 'P2 Physics', 'optional': true, 'stub': false },
|
||||
'tilemaps': { 'description': 'Tilemap Support', 'optional': true, 'stub': false },
|
||||
'particles': { 'description': 'Arcade Physics Particle System', 'optional': true, 'stub': true },
|
||||
'creature': { 'description': 'Creature Animation Tool Support', 'optional': true, 'stub': false },
|
||||
'outro': { 'description': 'Phaser UMD closure', 'optional': true, 'stub': false }
|
||||
|
||||
};
|
||||
|
@ -207,7 +208,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('build', 'Compile all Phaser versions just to the dist folder', function() {
|
||||
|
||||
grunt.option('exclude', 'ninja');
|
||||
grunt.option('exclude', 'ninja,creature');
|
||||
grunt.option('filename', 'phaser');
|
||||
grunt.option('sourcemap', true);
|
||||
grunt.option('copy', false);
|
||||
|
@ -218,7 +219,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('full', 'Phaser complete', function() {
|
||||
|
||||
grunt.option('exclude', 'ninja');
|
||||
grunt.option('exclude', 'ninja,creature');
|
||||
grunt.option('filename', 'phaser');
|
||||
grunt.option('sourcemap', true);
|
||||
grunt.option('copy', true);
|
||||
|
@ -229,7 +230,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('arcadephysics', 'Phaser with Arcade Physics, Tilemaps and Particles', function() {
|
||||
|
||||
grunt.option('exclude', 'ninja,p2');
|
||||
grunt.option('exclude', 'ninja,p2,creature');
|
||||
grunt.option('filename', 'phaser-arcade-physics');
|
||||
grunt.option('sourcemap', true);
|
||||
grunt.option('copy', false);
|
||||
|
@ -241,7 +242,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('nophysics', 'Phaser without physics, tilemaps or particles', function() {
|
||||
|
||||
grunt.option('exclude', 'arcade,ninja,p2,tilemaps,particles');
|
||||
grunt.option('exclude', 'arcade,ninja,p2,tilemaps,particles,creature');
|
||||
grunt.option('filename', 'phaser-no-physics');
|
||||
grunt.option('sourcemap', true);
|
||||
grunt.option('copy', false);
|
||||
|
@ -253,7 +254,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('minimum', 'Phaser without any optional modules except Pixi', function() {
|
||||
|
||||
grunt.option('exclude', 'gamepad,keyboard,bitmapdata,graphics,rendertexture,text,bitmaptext,retrofont,net,tweens,sound,debug,arcade,ninja,p2,tilemaps,particles');
|
||||
grunt.option('exclude', 'gamepad,keyboard,bitmapdata,graphics,rendertexture,text,bitmaptext,retrofont,net,tweens,sound,debug,arcade,ninja,p2,tilemaps,particles,creature');
|
||||
grunt.option('filename', 'phaser-minimum');
|
||||
grunt.option('sourcemap', true);
|
||||
grunt.option('copy', false);
|
||||
|
|
69
README.md
69
README.md
|
@ -35,7 +35,7 @@ Thousands of developers worldwide use it. From indies and multi-national digital
|
|||
![div](http://www.phaser.io/images/github/div.png)
|
||||
|
||||
<a name="whats-new"></a>
|
||||
## What's new in Phaser 2.3.0
|
||||
## What's new in Phaser 2.4.0
|
||||
|
||||
<div align="center"><img src="http://phaser.io/images/github/news.jpg"></div>
|
||||
|
||||
|
@ -242,22 +242,79 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
|
|||
<a name="change-log"></a>
|
||||
## Change Log
|
||||
|
||||
Version 2.3.1 - "Katar" - in dev
|
||||
Version 2.4 - "Katar" - in dev
|
||||
|
||||
### API Changes
|
||||
|
||||
* RenderTexture.render now takes a Matrix as its second parameter, not a Point object. This brings it in line with Pixi and allows you to perform much more complex transformations on the object being rendered. If you need to replicate the old behavior please use RenderTexture.renderXY(sprite, point.x, point.y) instead.
|
||||
* PIXI.DisplayObject.updateTransform has a new optional parameter `parent`. If the DisplayObject doesn't have a parent (i.e. it isn't on the display list yet) then in the past `updateTransform` would fail. This meant you couldn't do things like scale or rotate a Sprite and then draw it to a RenderTexture or BitmapData, as calls to updateTransform would be ignored. The new checks now look to see if the `parent` parameter is set. If so this takes priority over the actual parent and is used to modify the transform (note that it **doesn't** reparent the DisplayObject, it merely uses it for the transform.) If there is no parent (explicitly or via the parameter) then it falls back to use Phaser.World as the parent. If it can't reach that then no transform takes place.
|
||||
* If Phaser.Sound.noAudio has been set then Phaser.Loader will not load any audio files. No errors are thrown, but all calls to Loader.audio and Loader.audiosprite are silently ignored. `noAudio` can be set either via the `PhaserGlobal` global var or is set if the device your game is running on has no audio playback support.
|
||||
* Files can now be added to the Loader with an absolute URL even if you have a Loader.baseURL set. In previous versions the baseURL would still be prepended to the file URL, but the Loader now checks if the a file URL begins with `http` or `//` and skips prepending the baseURL to it.
|
||||
* Phaser.StateManager would incorrectly call `loadUpdate` and `loadRender` while the game was paused or if the State didn't have an `update` or `render` method defined, even after the loader was completed. Although this is a bug fix it's still an API change should you have been using the `loadUpdate/Render` calls in the old way. Also the StateManager no longer calls `preRender` unless the State `create` method has *finished*. If the State doesn't have a `create` method then `preRender` runs immediately.
|
||||
* Frame.uuid has been removed (was flagged as deprecated for several releases). This has a two-fold effect: First it means that the property no longer exists and secondly it means that the AnimationParser (the class responsible for loading sprite sheets and texture atlases) no longer has to call either RandomDataGenerator.uuid OR populates the PIXI.TextureCache. The first saves some CPU time and the second saves memory by not creating references to textures it doesn't ever use. The PIXI.TextureCache is now ignored by Phaser other than for the `__missing` and `__default` textures.
|
||||
* Phaser.AnimationParser methods `JSONData`, `JSONDataHash` and `XMLData` have all had their `cacheKey` parameter removed as it's no longer used.
|
||||
|
||||
### New Features
|
||||
|
||||
* All calls to Loader methods that add files to the queue, such as `Loader.image` or `Loader.atlas`, now have the URL as an optional parameter. If not set Loader will assume the URL to be based on the key given. For example the following: `game.load.image("boom", "boom.png")` can now be expressed as just `game.load.image("boom")`, or `game.load.atlas("player", "player.png", "player.json")` can now be shortened to `game.load.atlas("player")`. Please see the freshly updated jsdocs for full details.
|
||||
* Loader.atlas and `Cache.addTextureAtlas` will now automatically determine the format of the JSON data (array or hash) when added to the Cache. You no longer need to specify it explicitly if JSON, only if XML.
|
||||
* Added support for the [Creature Automated Animation Tool](http://www.kestrelmoon.com/creature/). You can now create a Phaser.Creature object which uses json data and a texture atlas for the animations. Creature is a powerful animation tool, similar to Spriter or Spine. It is currently limited to WebGL games only, but the new libs should prove a solid starting point for anyone wanting to incorporate Creature animations into their games.
|
||||
* Tilemap.getTileWorldXY has a new optional parameter: `nonNull` which if set makes it behave in the same way as `getTile` does (thanks @GGAlanSmithee #1722)
|
||||
* Group.hash is an array (previously available as `Group._hash`, but protected) into which you can add any of its children via `Group.addToHash` and `Group.removeFromHash`. Only children of the Group can be added to and removed from the hash. The hash is used automatically by Arcade Physics in order to perform non z-index based destructive sorting. However if you don't use Arcade Physics, or it isn't a physics enabled Group, then you can use the hash to perform your own sorting and filtering of Group children without touching their z-index (and therefore display draw order).
|
||||
* Group.physicsSortDirection is a new property allowing you to set a custom sort direction for Arcade Physics Sprites within the Group hash. Previously Arcade Physics used one single sort direction (defined on `Phaser.Physics.Arcade.sortDirection`) but this change allows you to specifically control how each and every Group is sorted, so you can now combine tall and wide Groups with narrow and thin in a single system.
|
||||
* Cache.getPixiTexture will return a PIXI.Texture from the cache based on the given key. A PIXI Texture is created automatically for all images loaded and added to the cache.
|
||||
* Cache.getPixiBaseTexture will return a PIXI.BaseTexture from the cache based on the given key. A PIXI BaseTexture is created automatically for all images loaded and added to the cache.
|
||||
* Phaser.Matrix.clone allows you to clone the Matrix to a new object, or copy its values into the given Matrix.
|
||||
* Phaser.Matrix.copyFrom and copyTo allow you to copy Matrix values from and to other Matrix objects.
|
||||
* Phaser.Matrix.setTo allows you to set all properties of a Matrix in a single call.
|
||||
* The Phaser.Matrix constructor now allows you to optionally set all Matrix properties on instantiation.
|
||||
|
||||
### Updates
|
||||
|
||||
* TypeScript definitions fixes and updates (thanks @clark-stevenson @isuda)
|
||||
* TypeScript definitions fixes and updates (thanks @clark-stevenson @isuda @ggarek)
|
||||
* JSDoc typo fixes (thanks @robertpenner)
|
||||
* Added missing `resumed` method to Phaser.State class template.
|
||||
* Color.webToColor and Color.updateColor now updates the `out.color` and `out.color32` properties (thanks @cuixiping #1728)
|
||||
* Tilemap.createFromObjects has been updated for Tiled 0.11 and can now look-up object layers based on id, uid or name. It will also now copy over Sprite scaling properties if set (thanks @mandarinx #1738)
|
||||
* Graphics.drawPolygon can now accept a Phaser.Polygon or PIXI.Polygon object, as well as a points array (#1712)
|
||||
* Phaser.Physics hooks added in for MatterJS support (coming soon)
|
||||
* Body.destroy now automatically calls `Group.removeFromHash`.
|
||||
* Physics.Arcade.sort has a new property 'sortDirection'. If not specified it will use World.sortDirection. If the Group given as the first parameter has its `physicsSortDirection` property set that will override any other setting.
|
||||
* Physics.Arcade.sort now calls one of four functions: sortLeftRight, sortRightLeft, sortTopBottom and sortBottomTop. Each of which takes 2 Sprites as arguments.
|
||||
* Physics.Arcade.sort now doesn't bail out if the Group contains a mixture of physics and non-physics enabled objects, as the Group hash is now only ever populated with physics enabled objects. Also the sort comparison functions no longer return -1 if the bodies are invalid, but zero instead (#1721)
|
||||
* Phaser.Group would automatically add a child into the _hash array as soon as the child was created (or moved into the Group). This no longer happens. Instead the child is only added to `Group.hash` if it is enabled for Arcade Physics. However `Group.addToHash` and the hash array have been exposed as public in case you were taking advantage of the _hash even though it was a previously marked as private.
|
||||
* Cache.getTexture has now been removed (it was deprecated several versions ago). Use Cache.getRenderTexture instead.
|
||||
* Removed duplicate methods from PIXI.Text such as wordWrap and updateText as Phaser overrides them, so it was wasting bytes.
|
||||
* Phaser.StateManager no longer calls `preRender` unless the State `create` method has finished. If the State doesn't have a `create` method then `preRender` runs immediately.
|
||||
* Phaser.StateManager.created is a new read-only boolean that tells you if the State has finished running its `create` method. If it doesn't have one it's always true.
|
||||
* RenderTexture.render and `renderXY` would ignore the Sprites rotation or scale. The full Sprite transform is now used correctly when the Sprite is drawn to the texture. If you wish to replicate the old behavior please use `RenderTexture.renderRawXY` instead.
|
||||
* Pixi.Sprite.renderCanvas and renderWebGL now has a new optional matrix parameter. You can use this to render the Sprite with an alternative transform matrix without actually adjusting the Sprite matrix at all.
|
||||
* RenderTexture.matrix has been removed as it's no longer used.
|
||||
* SoundManager.pauseAll, resumeAll and stopAll now checks if the SoundManager.noAudio is set and ignores the calls.
|
||||
* SoundManager.usingWebAudio is set to `false` by default (used to be `true`) and is only explicitly set if Web Audio is available and hasn't been disabled in the PhaserGlobal object.
|
||||
* SoundManager.touchLocked is now set to `false` should the device be using legacy Audio, avoiding the unlock call running without need.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* The LoadTexture component has had a redundant `dirty` call removed from it.
|
||||
* The LoadTexture component has had a redundant `dirty` call removed from it that was causing textures to be re-uploaded to the GPU even though they may already have been on it.
|
||||
* TileSprites were missing a `physicsType` property, causing them to not collide with anything (thanks @numbofathma #1702)
|
||||
* Sprite was missing the Health and InCamera components.
|
||||
* A Tween could be incorrectly set to never end if it was given a duration of zero (thanks @hardalias #1710)
|
||||
* Added guards around `context.getImageData` calls in BitmapData, Text and Canvas Tinting classes to avoid crashing restricted browsers like Epic Browser. Please understand that several Phaser features won't work correctly with this browser (thanks @Erik3000 #1714)
|
||||
* P2 Body.destroy now checks for the existence of a `sprite` property on the body before nulling it (thanks @englercj #1736)
|
||||
* The version of p2.js being used in 2.3.0 wasn't correctly declaring itself as a global for browserify / requireJS. This update resolves that (thanks @dgoemans #1723)
|
||||
* AnimationManager.frameName setter wasn't checking if `_frameData` existed before accessing it (thanks @nesukun #1727)
|
||||
* P2.getConstraints would return an array of null objects. It now returns the raw p2 constraint objects (thanks @valueerrorx #1726)
|
||||
* TilemapLayer docs incorrectly reported it as extending Phaser.Image, but it doesn't share the same components so has been updated.
|
||||
* TilemapLayer was missing the Input component (thanks @uhe1231 #1700)
|
||||
* PIXI.Graphics in Canvas mode wouldn't respect the objects visible or alpha zero properties, rendering it regardless (thanks @TimvdEijnden #1720)
|
||||
* Enabling Arcade Physics would add the deltaCap property onto Phaser.Time, even though the property doesn't exist any more, changing the class shape in the process.
|
||||
* Phaser.StateManager would incorrectly call `loadUpdate` while the game was paused or if the State didn't have an `update` method defined even after the loader was completed.
|
||||
* Phaser.StateManager would incorrectly call `loadRender` while the game was paused or if the State didn't have an `render` method defined even after the loader was completed.
|
||||
* Added the missing `preRender` function to the Phaser.State class template.
|
||||
* Fixed bug in Pixi where RenderTexture.render would ignore the given matrix.
|
||||
* Fixed a bug in Pixi where drawing a Sprite to a RenderTexture would reset the Sprites transform to an identity Matrix.
|
||||
* The SoundManager didn't accurately detect devices or browser environments with no sound card present and would try to carry on using a null Web Audio context (thanks @englercj #1746)
|
||||
|
||||
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
|
||||
|
||||
|
@ -292,6 +349,8 @@ The Phaser logo and characters are © 2015 Photon Storm Limited.
|
|||
|
||||
All rights reserved.
|
||||
|
||||
"The art challenges the technology, and the technology inspires the art." - John Lasseter
|
||||
|
||||
[![Analytics](https://ga-beacon.appspot.com/UA-44006568-2/phaser/index)](https://github.com/igrigorik/ga-beacon)
|
||||
|
||||
[get-js]: https://github.com/photonstorm/phaser/releases/download/v2.3.0/phaser.js
|
||||
|
@ -310,7 +369,7 @@ All rights reserved.
|
|||
[forum]: http://www.html5gamedevs.com/forum/14-phaser/
|
||||
|
||||
[game1]: https://www.prodigygame.com/Fun-Math-Games/
|
||||
[game2]: http://www.bbc.co.uk/cbbc/games/deadly-defenders
|
||||
[game2]: http://www.bbc.co.uk/cbbc/games/deadly-defenders-game
|
||||
[game3]: http://www.defiantfew.com/
|
||||
[game4]: http://www.pawpatrol.com/fun.php
|
||||
[game5]: http://www.fyretale.com/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "phaser",
|
||||
"version": "2.3.0",
|
||||
"version": "2.4.0",
|
||||
"homepage": "http://phaser.io",
|
||||
"authors": [
|
||||
"photonstorm <rich@photonstorm.com>"
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
'arcade' => true,
|
||||
'p2' => true,
|
||||
'ninja' => false,
|
||||
'box2d' => false
|
||||
'box2d' => false,
|
||||
'creature' => false,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -29,6 +30,11 @@
|
|||
echo " <script src=\"$path/src/physics/p2/p2.js\"></script>";
|
||||
}
|
||||
|
||||
if ($modules['creature'])
|
||||
{
|
||||
echo " <script src=\"$path/src/animation/creature/gl-matrix.js\"></script>";
|
||||
}
|
||||
|
||||
if ($modules['box2d'] && isset($box2dpath))
|
||||
{
|
||||
echo " <script src=\"$box2dpath/box2d-html5.js\"></script>";
|
||||
|
@ -45,6 +51,7 @@
|
|||
<script src="$path/src/pixi/text/BitmapText.js"></script>
|
||||
<script src="$path/src/pixi/display/Stage.js"></script>
|
||||
|
||||
<script src="$path/src/pixi/utils/EventTarget.js"></script>
|
||||
<script src="$path/src/pixi/utils/Utils.js"></script>
|
||||
<script src="$path/src/pixi/utils/Polyk.js"></script>
|
||||
|
||||
|
@ -80,6 +87,7 @@
|
|||
<script src="$path/src/pixi/textures/BaseTexture.js"></script>
|
||||
<script src="$path/src/pixi/textures/Texture.js"></script>
|
||||
<script src="$path/src/pixi/textures/RenderTexture.js"></script>
|
||||
<script src="$path/src/pixi/textures/VideoTexture.js"></script>
|
||||
|
||||
<script src="$path/src/pixi/filters/AbstractFilter.js"></script>
|
||||
|
||||
|
@ -288,6 +296,17 @@ EOL;
|
|||
|
||||
EOL;
|
||||
|
||||
if ($modules['creature'])
|
||||
{
|
||||
echo <<<EOL
|
||||
<script src="$path/src/animation/creature/CreatureMeshBone.js"></script>
|
||||
<script src="$path/src/animation/creature/CreaturePixiJSRenderer.js"></script>
|
||||
<script src="$path/src/gameobjects/Creature.js"></script>
|
||||
|
||||
|
||||
EOL;
|
||||
}
|
||||
|
||||
if ($modules['sound'])
|
||||
{
|
||||
echo <<<EOL
|
||||
|
|
|
@ -28,8 +28,8 @@ PIXI.AlphaMaskFilter = function(texture)
|
|||
|
||||
if (texture.baseTexture.hasLoaded)
|
||||
{
|
||||
this.uniforms.mask.value.x = texture.width;
|
||||
this.uniforms.mask.value.y = texture.height;
|
||||
this.uniforms.mapDimensions.value.x = texture.width;
|
||||
this.uniforms.mapDimensions.value.y = texture.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "phaser",
|
||||
"version": "2.3.1",
|
||||
"version": "2.4.0",
|
||||
"release": "Katar",
|
||||
"description": "A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.",
|
||||
"author": "Richard Davey <rdavey@gmail.com> (http://www.photonstorm.com)",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
var Phaser = Phaser || {
|
||||
|
||||
VERSION: '2.3.1-dev',
|
||||
VERSION: '2.4.0-dev',
|
||||
GAMES: [],
|
||||
|
||||
AUTO: 0,
|
||||
|
@ -51,6 +51,7 @@ var Phaser = Phaser || {
|
|||
MATRIX: 24,
|
||||
POINT: 25,
|
||||
ROUNDEDRECTANGLE: 26,
|
||||
CREATURE: 27,
|
||||
|
||||
/**
|
||||
* Various blend modes supported by pixi. IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes.
|
||||
|
|
|
@ -429,22 +429,19 @@ Phaser.Animation.prototype = {
|
|||
return false;
|
||||
}
|
||||
|
||||
var idx = this.currentFrame.index;
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
if (this.currentFrame)
|
||||
if (this.currentFrame && idx !== this.currentFrame.index)
|
||||
{
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
|
||||
if (this._parent.__tilePattern)
|
||||
{
|
||||
this._parent.__tilePattern = false;
|
||||
this._parent.tilingTexture = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.onUpdate && signalUpdate)
|
||||
{
|
||||
this.onUpdate.dispatch(this, this.currentFrame);
|
||||
|
||||
// False if the animation was destroyed from within a callback
|
||||
return !!this._frameData;
|
||||
}
|
||||
|
|
|
@ -205,14 +205,9 @@ Phaser.AnimationManager.prototype = {
|
|||
this.currentAnim = this._anims[name];
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
|
||||
// this.sprite.setFrame(this.currentFrame);
|
||||
|
||||
// CHECK WE STILL NEED THIS - PRETTY SURE IT DOESN'T ACTUALLY DO ANYTHING!
|
||||
if (this.sprite.__tilePattern)
|
||||
if (this.sprite.tilingTexture)
|
||||
{
|
||||
// this.__tilePattern = false;
|
||||
this.sprite.__tilePattern = false;
|
||||
this.tilingTexture = false;
|
||||
this.sprite.refreshTexture = true;
|
||||
}
|
||||
|
||||
return this._anims[name];
|
||||
|
@ -409,14 +404,9 @@ Phaser.AnimationManager.prototype = {
|
|||
*/
|
||||
refreshFrame: function () {
|
||||
|
||||
// TODO
|
||||
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
|
||||
if (this.sprite.__tilePattern)
|
||||
{
|
||||
this.__tilePattern = false;
|
||||
this.tilingTexture = false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -539,12 +529,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
|
|||
if (this.currentFrame)
|
||||
{
|
||||
this.sprite.setFrame(this.currentFrame);
|
||||
|
||||
if (this.sprite.__tilePattern)
|
||||
{
|
||||
this.__tilePattern = false;
|
||||
this.tilingTexture = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -569,7 +553,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
|
|||
|
||||
set: function (value) {
|
||||
|
||||
if (typeof value === 'string' && this._frameData.getFrameByName(value) !== null)
|
||||
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrameByName(value);
|
||||
|
||||
|
@ -578,12 +562,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
|
|||
this._frameIndex = this.currentFrame.index;
|
||||
|
||||
this.sprite.setFrame(this.currentFrame);
|
||||
|
||||
if (this.sprite.__tilePattern)
|
||||
{
|
||||
this.__tilePattern = false;
|
||||
this.tilingTexture = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -71,17 +71,7 @@ Phaser.AnimationParser = {
|
|||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
// uuid needed?
|
||||
data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, '', uuid));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[key], {
|
||||
x: x,
|
||||
y: y,
|
||||
width: frameWidth,
|
||||
height: frameHeight
|
||||
});
|
||||
data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, ''));
|
||||
|
||||
x += frameWidth + spacing;
|
||||
|
||||
|
@ -102,10 +92,9 @@ Phaser.AnimationParser = {
|
|||
* @method Phaser.AnimationParser.JSONData
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in Array format.
|
||||
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONData: function (game, json, cacheKey) {
|
||||
JSONData: function (game, json) {
|
||||
|
||||
// Malformed?
|
||||
if (!json['frames'])
|
||||
|
@ -124,25 +113,15 @@ Phaser.AnimationParser = {
|
|||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[i].frame.x,
|
||||
frames[i].frame.y,
|
||||
frames[i].frame.w,
|
||||
frames[i].frame.h,
|
||||
frames[i].filename,
|
||||
uuid
|
||||
frames[i].filename
|
||||
));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
|
||||
x: frames[i].frame.x,
|
||||
y: frames[i].frame.y,
|
||||
width: frames[i].frame.w,
|
||||
height: frames[i].frame.h
|
||||
});
|
||||
|
||||
if (frames[i].trimmed)
|
||||
{
|
||||
newFrame.setTrim(
|
||||
|
@ -167,10 +146,9 @@ Phaser.AnimationParser = {
|
|||
* @method Phaser.AnimationParser.JSONDataHash
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
|
||||
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONDataHash: function (game, json, cacheKey) {
|
||||
JSONDataHash: function (game, json) {
|
||||
|
||||
// Malformed?
|
||||
if (!json['frames'])
|
||||
|
@ -190,25 +168,15 @@ Phaser.AnimationParser = {
|
|||
|
||||
for (var key in frames)
|
||||
{
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[key].frame.x,
|
||||
frames[key].frame.y,
|
||||
frames[key].frame.w,
|
||||
frames[key].frame.h,
|
||||
key,
|
||||
uuid
|
||||
key
|
||||
));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
|
||||
x: frames[key].frame.x,
|
||||
y: frames[key].frame.y,
|
||||
width: frames[key].frame.w,
|
||||
height: frames[key].frame.h
|
||||
});
|
||||
|
||||
if (frames[key].trimmed)
|
||||
{
|
||||
newFrame.setTrim(
|
||||
|
@ -235,10 +203,9 @@ Phaser.AnimationParser = {
|
|||
* @method Phaser.AnimationParser.XMLData
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} xml - The XML data from the Texture Atlas. Must be in Starling XML format.
|
||||
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
XMLData: function (game, xml, cacheKey) {
|
||||
XMLData: function (game, xml) {
|
||||
|
||||
// Malformed?
|
||||
if (!xml.getElementsByTagName('TextureAtlas'))
|
||||
|
@ -252,7 +219,6 @@ Phaser.AnimationParser = {
|
|||
var frames = xml.getElementsByTagName('SubTexture');
|
||||
var newFrame;
|
||||
|
||||
var uuid;
|
||||
var name;
|
||||
var frame;
|
||||
var x;
|
||||
|
@ -266,8 +232,6 @@ Phaser.AnimationParser = {
|
|||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
uuid = game.rnd.uuid();
|
||||
|
||||
frame = frames[i].attributes;
|
||||
|
||||
name = frame.name.value;
|
||||
|
@ -287,15 +251,9 @@ Phaser.AnimationParser = {
|
|||
frameHeight = parseInt(frame.frameHeight.value, 10);
|
||||
}
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid));
|
||||
newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
});
|
||||
// Trimmed?
|
||||
// Trimmed?
|
||||
if (frameX !== null || frameY !== null)
|
||||
{
|
||||
newFrame.setTrim(true, width, height, frameX, frameY, frameWidth, frameHeight);
|
||||
|
|
|
@ -15,9 +15,8 @@
|
|||
* @param {number} width - Width of the frame within the texture image.
|
||||
* @param {number} height - Height of the frame within the texture image.
|
||||
* @param {string} name - The name of the frame. In Texture Atlas data this is usually set to the filename.
|
||||
* @param {string} uuid - Internal UUID key.
|
||||
*/
|
||||
Phaser.Frame = function (index, x, y, width, height, name, uuid) {
|
||||
Phaser.Frame = function (index, x, y, width, height, name) {
|
||||
|
||||
/**
|
||||
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
|
||||
|
@ -49,11 +48,6 @@ Phaser.Frame = function (index, x, y, width, height, name, uuid) {
|
|||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {string} uuid - DEPRECATED: A link to the PIXI.TextureCache entry.
|
||||
*/
|
||||
this.uuid = uuid;
|
||||
|
||||
/**
|
||||
* @property {number} centerX - Center X position within the image to cut from.
|
||||
*/
|
||||
|
@ -88,12 +82,12 @@ Phaser.Frame = function (index, x, y, width, height, name, uuid) {
|
|||
this.trimmed = false;
|
||||
|
||||
/**
|
||||
* @property {number} sourceSizeW - Width of the original sprite.
|
||||
* @property {number} sourceSizeW - Width of the original sprite before it was trimmed.
|
||||
*/
|
||||
this.sourceSizeW = width;
|
||||
|
||||
/**
|
||||
* @property {number} sourceSizeH - Height of the original sprite.
|
||||
* @property {number} sourceSizeH - Height of the original sprite before it was trimmed.
|
||||
*/
|
||||
this.sourceSizeH = height;
|
||||
|
||||
|
@ -174,7 +168,7 @@ Phaser.Frame.prototype = {
|
|||
*/
|
||||
clone: function () {
|
||||
|
||||
var output = new Phaser.Frame(this.index, this.x, this.y, this.width, this.height, this.name, this.uuid);
|
||||
var output = new Phaser.Frame(this.index, this.x, this.y, this.width, this.height, this.name);
|
||||
|
||||
for (var prop in this)
|
||||
{
|
||||
|
|
2727
src/animation/creature/CreatureMeshBone.js
Normal file
2727
src/animation/creature/CreatureMeshBone.js
Normal file
File diff suppressed because it is too large
Load diff
226
src/animation/creature/CreaturePixiJSRenderer.js
Normal file
226
src/animation/creature/CreaturePixiJSRenderer.js
Normal file
|
@ -0,0 +1,226 @@
|
|||
/******************************************************************************
|
||||
* Creature Runtimes License
|
||||
*
|
||||
* Copyright (c) 2015, Kestrel Moon Studios
|
||||
* All rights reserved.
|
||||
*
|
||||
* Preamble: This Agreement governs the relationship between Licensee and Kestrel Moon Studios(Hereinafter: Licensor).
|
||||
* This Agreement sets the terms, rights, restrictions and obligations on using [Creature Runtimes] (hereinafter: The Software) created and owned by Licensor,
|
||||
* as detailed herein:
|
||||
* License Grant: Licensor hereby grants Licensee a Sublicensable, Non-assignable & non-transferable, Commercial, Royalty free,
|
||||
* Including the rights to create but not distribute derivative works, Non-exclusive license, all with accordance with the terms set forth and
|
||||
* other legal restrictions set forth in 3rd party software used while running Software.
|
||||
* Limited: Licensee may use Software for the purpose of:
|
||||
* Running Software on Licensee’s Website[s] and Server[s];
|
||||
* Allowing 3rd Parties to run Software on Licensee’s Website[s] and Server[s];
|
||||
* Publishing Software’s output to Licensee and 3rd Parties;
|
||||
* Distribute verbatim copies of Software’s output (including compiled binaries);
|
||||
* Modify Software to suit Licensee’s needs and specifications.
|
||||
* Binary Restricted: Licensee may sublicense Software as a part of a larger work containing more than Software,
|
||||
* distributed solely in Object or Binary form under a personal, non-sublicensable, limited license. Such redistribution shall be limited to unlimited codebases.
|
||||
* Non Assignable & Non-Transferable: Licensee may not assign or transfer his rights and duties under this license.
|
||||
* Commercial, Royalty Free: Licensee may use Software for any purpose, including paid-services, without any royalties
|
||||
* Including the Right to Create Derivative Works: Licensee may create derivative works based on Software,
|
||||
* including amending Software’s source code, modifying it, integrating it into a larger work or removing portions of Software,
|
||||
* as long as no distribution of the derivative works is made
|
||||
*
|
||||
* THE RUNTIMES IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE RUNTIMES OR THE USE OR OTHER DEALINGS IN THE
|
||||
* RUNTIMES.
|
||||
*****************************************************************************/
|
||||
|
||||
function CreatureRenderer(manager_in, texture_in)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.call( this );
|
||||
|
||||
this.creature_manager = manager_in;
|
||||
this.texture = texture_in;
|
||||
this.dirty = true;
|
||||
this.blendMode = PIXI.blendModes.NORMAL;
|
||||
|
||||
var target_creature = this.creature_manager.target_creature;
|
||||
|
||||
this.verticies = new PIXI.Float32Array(target_creature.total_num_pts * 2);
|
||||
this.uvs = new PIXI.Float32Array(target_creature.total_num_pts * 2);
|
||||
|
||||
this.indices = new PIXI.Uint16Array(target_creature.global_indices.length);
|
||||
for(var i = 0; i < this.indices.length; i++)
|
||||
{
|
||||
this.indices[i] = target_creature.global_indices[i];
|
||||
}
|
||||
|
||||
this.colors = new PIXI.Float32Array([1,1,1,1]);
|
||||
|
||||
this.UpdateRenderData(target_creature.global_pts, target_creature.global_uvs);
|
||||
};
|
||||
|
||||
// constructor
|
||||
CreatureRenderer.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||
CreatureRenderer.prototype.constructor = CreatureRenderer;
|
||||
|
||||
CreatureRenderer.prototype._renderWebGL = function(renderSession)
|
||||
{
|
||||
// if the sprite is not visible or the alpha is 0 then no need to render this element
|
||||
if(!this.visible || this.alpha <= 0)return;
|
||||
// render triangles..
|
||||
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
// init! init!
|
||||
if(!this._vertexBuffer)this._initWebGL(renderSession);
|
||||
|
||||
renderSession.shaderManager.setShader(renderSession.shaderManager.stripShader);
|
||||
|
||||
this._renderCreature(renderSession);
|
||||
|
||||
///renderSession.shaderManager.activateDefaultShader();
|
||||
|
||||
renderSession.spriteBatch.start();
|
||||
|
||||
//TODO check culling
|
||||
};
|
||||
|
||||
CreatureRenderer.prototype._initWebGL = function(renderSession)
|
||||
{
|
||||
// build the strip!
|
||||
var gl = renderSession.gl;
|
||||
|
||||
this._vertexBuffer = gl.createBuffer();
|
||||
this._indexBuffer = gl.createBuffer();
|
||||
this._uvBuffer = gl.createBuffer();
|
||||
this._colorBuffer = gl.createBuffer();
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.verticies, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.DYNAMIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._colorBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.colors, gl.STATIC_DRAW);
|
||||
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
};
|
||||
|
||||
CreatureRenderer.prototype._renderCreature = function(renderSession)
|
||||
{
|
||||
var gl = renderSession.gl;
|
||||
var projection = renderSession.projection,
|
||||
offset = renderSession.offset,
|
||||
shader = renderSession.shaderManager.stripShader;
|
||||
|
||||
|
||||
// gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mat4Real);
|
||||
|
||||
renderSession.blendModeManager.setBlendMode(this.blendMode);
|
||||
|
||||
|
||||
// set uniforms
|
||||
gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true));
|
||||
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
|
||||
gl.uniform2f(shader.offsetVector, -offset.x, -offset.y);
|
||||
gl.uniform1f(shader.alpha, this.worldAlpha);
|
||||
|
||||
if(!this.dirty)
|
||||
{
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// check if a texture is dirty..
|
||||
if(this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind the current texture
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]);
|
||||
}
|
||||
|
||||
// dont need to upload!
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
this.dirty = false;
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.verticies, gl.DYNAMIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
// update the uvs
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, this.uvs, gl.DYNAMIC_DRAW);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// check if a texture is dirty..
|
||||
if(this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.bindTexture(gl.TEXTURE_2D, this.texture.baseTexture._glTextures[gl.id]);
|
||||
}
|
||||
|
||||
// dont need to upload!
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||
|
||||
}
|
||||
|
||||
gl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
};
|
||||
|
||||
CreatureRenderer.prototype.UpdateData = function()
|
||||
{
|
||||
var target_creature = this.creature_manager.target_creature;
|
||||
|
||||
var read_pts = target_creature.render_pts;
|
||||
//var read_pts = target_creature.global_pts;
|
||||
var read_uvs = target_creature.global_uvs;
|
||||
|
||||
this.UpdateRenderData(read_pts, read_uvs);
|
||||
this.dirty = true;
|
||||
};
|
||||
|
||||
CreatureRenderer.prototype.UpdateRenderData = function(inputVerts, inputUVs)
|
||||
{
|
||||
var target_creature = this.creature_manager.target_creature;
|
||||
|
||||
var pt_index = 0;
|
||||
var uv_index = 0;
|
||||
|
||||
var write_pt_index = 0;
|
||||
|
||||
for(var i = 0; i < target_creature.total_num_pts; i++)
|
||||
{
|
||||
this.verticies[write_pt_index] = inputVerts[pt_index];
|
||||
this.verticies[write_pt_index + 1] = -inputVerts[pt_index + 1];
|
||||
|
||||
this.uvs[uv_index] = inputUVs[uv_index];
|
||||
this.uvs[uv_index + 1] = 1.0 - inputUVs[uv_index + 1];
|
||||
|
||||
pt_index += 3;
|
||||
uv_index += 2;
|
||||
|
||||
write_pt_index += 2;
|
||||
}
|
||||
};
|
4292
src/animation/creature/gl-matrix.js
Normal file
4292
src/animation/creature/gl-matrix.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -156,6 +156,24 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
|
|||
*/
|
||||
this.physicsBodyType = physicsBodyType;
|
||||
|
||||
/**
|
||||
* If this Group contains Arcade Physics Sprites you can set a custom sort direction via this property.
|
||||
*
|
||||
* It should be set to one of the Phaser.Physics.Arcade sort direction constants:
|
||||
*
|
||||
* Phaser.Physics.Arcade.SORT_NONE
|
||||
* Phaser.Physics.Arcade.LEFT_RIGHT
|
||||
* Phaser.Physics.Arcade.RIGHT_LEFT
|
||||
* Phaser.Physics.Arcade.TOP_BOTTOM
|
||||
* Phaser.Physics.Arcade.BOTTOM_TOP
|
||||
*
|
||||
* If set to `null` the Group will use whatever Phaser.Physics.Arcade.sortDirection is set to. This is the default behavior.
|
||||
*
|
||||
* @property {integer} physicsSortDirection
|
||||
* @default
|
||||
*/
|
||||
this.physicsSortDirection = null;
|
||||
|
||||
/**
|
||||
* This signal is dispatched when the group is destroyed.
|
||||
* @property {Phaser.Signal} onDestroy
|
||||
|
@ -186,11 +204,17 @@ Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBody
|
|||
this.cameraOffset = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* An internal array used by physics for fast non z-index destructive sorting.
|
||||
* @property {array} _hash
|
||||
* @private
|
||||
* The hash array is an array belonging to this Group into which you can add any of its children via Group.addToHash and Group.removeFromHash.
|
||||
*
|
||||
* Only children of this Group can be added to and removed from the hash.
|
||||
*
|
||||
* This hash is used automatically by Phaser Arcade Physics in order to perform non z-index based destructive sorting.
|
||||
* However if you don't use Arcade Physics, or this isn't a physics enabled Group, then you can use the hash to perform your own
|
||||
* sorting and filtering of Group children without touching their z-index (and therefore display draw order)
|
||||
*
|
||||
* @property {array} hash
|
||||
*/
|
||||
this._hash = [];
|
||||
this.hash = [];
|
||||
|
||||
/**
|
||||
* The property on which children are sorted.
|
||||
|
@ -257,17 +281,15 @@ Phaser.Group.prototype.add = function (child, silent) {
|
|||
|
||||
if (child.parent !== this)
|
||||
{
|
||||
this.addChild(child);
|
||||
|
||||
child.z = this.children.length;
|
||||
|
||||
if (this.enableBody)
|
||||
{
|
||||
this.game.physics.enable(child, this.physicsBodyType);
|
||||
}
|
||||
|
||||
this.addChild(child);
|
||||
|
||||
this._hash.push(child);
|
||||
|
||||
child.z = this.children.length;
|
||||
|
||||
if (!silent && child.events)
|
||||
{
|
||||
child.events.onAddedToGroup$dispatch(child, this);
|
||||
|
@ -283,6 +305,56 @@ Phaser.Group.prototype.add = function (child, silent) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a child of this Group into the hash array.
|
||||
* This call will return false if the child is not a child of this Group, or is already in the hash.
|
||||
*
|
||||
* @method Phaser.Group#addToHash
|
||||
* @param {DisplayObject} child - The display object to add to this Groups hash. Must be a member of this Group already and not present in the hash.
|
||||
* @return {boolean} True if the child was successfully added to the hash, otherwise false.
|
||||
*/
|
||||
Phaser.Group.prototype.addToHash = function (child) {
|
||||
|
||||
if (child.parent === this)
|
||||
{
|
||||
var index = this.hash.indexOf(child);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
this.hash.push(child);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a child of this Group from the hash array.
|
||||
* This call will return false if the child is not in the hash.
|
||||
*
|
||||
* @method Phaser.Group#removeFromHash
|
||||
* @param {DisplayObject} child - The display object to remove from this Groups hash. Must be a member of this Group and in the hash.
|
||||
* @return {boolean} True if the child was successfully removed from the hash, otherwise false.
|
||||
*/
|
||||
Phaser.Group.prototype.removeFromHash = function (child) {
|
||||
|
||||
if (child)
|
||||
{
|
||||
var index = this.hash.indexOf(child);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this.hash.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds an array of existing display objects to this group.
|
||||
*
|
||||
|
@ -326,17 +398,15 @@ Phaser.Group.prototype.addAt = function (child, index, silent) {
|
|||
|
||||
if (child.parent !== this)
|
||||
{
|
||||
this.addChildAt(child, index);
|
||||
|
||||
this.updateZ();
|
||||
|
||||
if (this.enableBody)
|
||||
{
|
||||
this.game.physics.enable(child, this.physicsBodyType);
|
||||
}
|
||||
|
||||
this.addChildAt(child, index);
|
||||
|
||||
this._hash.push(child);
|
||||
|
||||
this.updateZ();
|
||||
|
||||
if (!silent && child.events)
|
||||
{
|
||||
child.events.onAddedToGroup$dispatch(child, this);
|
||||
|
@ -391,21 +461,19 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
|
|||
|
||||
var child = new this.classType(this.game, x, y, key, frame);
|
||||
|
||||
if (this.enableBody)
|
||||
{
|
||||
this.game.physics.enable(child, this.physicsBodyType, this.enableBodyDebug);
|
||||
}
|
||||
|
||||
child.exists = exists;
|
||||
child.visible = exists;
|
||||
child.alive = exists;
|
||||
|
||||
this.addChild(child);
|
||||
|
||||
this._hash.push(child);
|
||||
|
||||
child.z = this.children.length;
|
||||
|
||||
if (this.enableBody)
|
||||
{
|
||||
this.game.physics.enable(child, this.physicsBodyType, this.enableBodyDebug);
|
||||
}
|
||||
|
||||
if (child.events)
|
||||
{
|
||||
child.events.onAddedToGroup$dispatch(child, this);
|
||||
|
@ -1830,12 +1898,7 @@ Phaser.Group.prototype.remove = function (child, destroy, silent) {
|
|||
|
||||
var removed = this.removeChild(child);
|
||||
|
||||
var index = this._hash.indexOf(removed);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this._hash.splice(index, 1);
|
||||
}
|
||||
this.removeFromHash(child);
|
||||
|
||||
this.updateZ();
|
||||
|
||||
|
@ -1879,12 +1942,7 @@ Phaser.Group.prototype.removeAll = function (destroy, silent) {
|
|||
|
||||
var removed = this.removeChild(this.children[0]);
|
||||
|
||||
var index = this._hash.indexOf(removed);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this._hash.splice(index, 1);
|
||||
}
|
||||
this.removeFromHash(removed);
|
||||
|
||||
if (destroy && removed)
|
||||
{
|
||||
|
@ -1893,7 +1951,7 @@ Phaser.Group.prototype.removeAll = function (destroy, silent) {
|
|||
}
|
||||
while (this.children.length > 0);
|
||||
|
||||
this._hash = [];
|
||||
this.hash = [];
|
||||
|
||||
this.cursor = null;
|
||||
|
||||
|
@ -1935,12 +1993,7 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex, destroy,
|
|||
|
||||
var removed = this.removeChild(this.children[i]);
|
||||
|
||||
var index = this._hash.indexOf(removed);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this._hash.splice(index, 1);
|
||||
}
|
||||
this.removeFromHash(removed);
|
||||
|
||||
if (destroy && removed)
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* A Signal is an event dispatch mechansim than supports broadcasting to multiple listeners.
|
||||
* A Signal is an event dispatch mechansim that supports broadcasting to multiple listeners.
|
||||
*
|
||||
* Event listeners are uniquely identified by the listener/callback function and the context.
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ Phaser.Signal.prototype = {
|
|||
_shouldPropagate: true,
|
||||
|
||||
/**
|
||||
* Is the Signal active? Only active signal will broadcast dispatched events.
|
||||
* Is the Signal active? Only active signals will broadcast dispatched events.
|
||||
*
|
||||
* Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use {@link #halt}.
|
||||
*
|
||||
|
@ -302,7 +302,7 @@ Phaser.Signal.prototype = {
|
|||
/**
|
||||
* Stop propagation of the event, blocking the dispatch to next listener on the queue.
|
||||
*
|
||||
* This should be called only during event dispatch as calling it before/after dispatch won't affect other broadcast.
|
||||
* This should be called only during event dispatch as calling it before/after dispatch won't affect another broadcast.
|
||||
* See {@link #active} to enable/disable the signal entirely.
|
||||
*
|
||||
* @method Phaser.Signal#halt
|
||||
|
|
|
@ -163,6 +163,14 @@ Phaser.State.prototype = {
|
|||
update: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* The preRender method is called after all Game Objects have been updated, but before any rendering takes place.
|
||||
*
|
||||
* @method Phaser.State#preRender
|
||||
*/
|
||||
preRender: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Nearly all display objects in Phaser render automatically, you don't need to tell them to render.
|
||||
* However the render method is called AFTER the game renderer and plugins have rendered, so you're able to do any
|
||||
|
|
|
@ -614,9 +614,12 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
update: function () {
|
||||
|
||||
if (this._created && this.onUpdateCallback)
|
||||
if (this._created)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext, this.game);
|
||||
if (this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -634,9 +637,12 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
pauseUpdate: function () {
|
||||
|
||||
if (this._created && this.onPauseUpdateCallback)
|
||||
if (this._created)
|
||||
{
|
||||
this.onPauseUpdateCallback.call(this.callbackContext, this.game);
|
||||
if (this.onPauseUpdateCallback)
|
||||
{
|
||||
this.onPauseUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -655,7 +661,7 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
preRender: function (elapsedTime) {
|
||||
|
||||
if (this.onPreRenderCallback)
|
||||
if (this._created && this.onPreRenderCallback)
|
||||
{
|
||||
this.onPreRenderCallback.call(this.callbackContext, this.game, elapsedTime);
|
||||
}
|
||||
|
@ -681,18 +687,21 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
render: function () {
|
||||
|
||||
if (this._created && this.onRenderCallback)
|
||||
if (this._created)
|
||||
{
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
if (this.onRenderCallback)
|
||||
{
|
||||
this.game.context.save();
|
||||
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
this.game.context.restore();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
this.game.context.save();
|
||||
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
this.game.context.restore();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -739,3 +748,18 @@ Phaser.StateManager.prototype = {
|
|||
};
|
||||
|
||||
Phaser.StateManager.prototype.constructor = Phaser.StateManager;
|
||||
|
||||
/**
|
||||
* @name Phaser.StateManager#created
|
||||
* @property {boolean} created - True if the current state has had its `create` method run (if it has one, if not this is true by default).
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.StateManager.prototype, "created", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._created;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -829,7 +829,7 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
/**
|
||||
* Scans the BitmapData, pixel by pixel, until it encounters a pixel that isn't transparent (i.e. has an alpha value > 0).
|
||||
* It then stops scanning and returns an object containing the colour of the pixel in r, g and b properties and the location in the x and y properties.
|
||||
* It then stops scanning and returns an object containing the color of the pixel in r, g and b properties and the location in the x and y properties.
|
||||
*
|
||||
* The direction parameter controls from which direction it should start the scan:
|
||||
*
|
||||
|
@ -840,7 +840,7 @@ Phaser.BitmapData.prototype = {
|
|||
*
|
||||
* @method Phaser.BitmapData#getFirstPixel
|
||||
* @param {number} [direction=0] - The direction in which to scan for the first pixel. 0 = top to bottom, 1 = bottom to top, 2 = left to right and 3 = right to left.
|
||||
* @return {object} Returns an object containing the colour of the pixel in the `r`, `g` and `b` properties and the location in the `x` and `y` properties.
|
||||
* @return {object} Returns an object containing the color of the pixel in the `r`, `g` and `b` properties and the location in the `x` and `y` properties.
|
||||
*/
|
||||
getFirstPixel: function (direction) {
|
||||
|
||||
|
@ -912,7 +912,7 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
/**
|
||||
* Scans the BitmapData and calculates the bounds. This is a rectangle that defines the extent of all non-transparent pixels.
|
||||
* The rectangle returned will extend from the top-left of the image to the bottom-right, exluding transparent pixels.
|
||||
* The rectangle returned will extend from the top-left of the image to the bottom-right, excluding transparent pixels.
|
||||
*
|
||||
* @method Phaser.BitmapData#getBounds
|
||||
* @param {Phaser.Rectangle} [rect] - If provided this Rectangle object will be populated with the bounds, otherwise a new object will be created.
|
||||
|
@ -989,7 +989,7 @@ Phaser.BitmapData.prototype = {
|
|||
* @param {number} [scaleX=1] - The horizontal scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on.
|
||||
* @param {number} [scaleY=1] - The vertical scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on.
|
||||
* @param {number} [alpha=1] - The alpha that will be set on the context before drawing. A value between 0 (fully transparent) and 1, opaque.
|
||||
* @param {number} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all.
|
||||
* @param {string} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
|
||||
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
|
@ -1169,7 +1169,7 @@ Phaser.BitmapData.prototype = {
|
|||
* @param {number} x - The destination x coordinate to copy the image to.
|
||||
* @param {number} y - The destination y coordinate to copy the image to.
|
||||
* @param {number} [alpha=1] - The alpha that will be set on the context before drawing. A value between 0 (fully transparent) and 1, opaque.
|
||||
* @param {number} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all.
|
||||
* @param {string} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
|
||||
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
|
@ -1190,7 +1190,7 @@ Phaser.BitmapData.prototype = {
|
|||
* @param {number} [y=0] - The y coordinate to translate to before drawing. If not specified it will default to `source.y`.
|
||||
* @param {number} [width] - The new width of the Sprite being copied. If not specified it will default to `source.width`.
|
||||
* @param {number} [height] - The new height of the Sprite being copied. If not specified it will default to `source.height`.
|
||||
* @param {number} [blendMode=null] - The composite blend mode that will be used when drawing the Sprite. The default is no blend mode at all.
|
||||
* @param {string} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
|
||||
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
|
@ -1210,7 +1210,7 @@ Phaser.BitmapData.prototype = {
|
|||
*
|
||||
* @method Phaser.BitmapData#drawGroup
|
||||
* @param {Phaser.Group} group - The Group to draw onto this BitmapData.
|
||||
* @param {number} [blendMode=null] - The composite blend mode that will be used when drawing the Group children. The default is no blend mode at all.
|
||||
* @param {string} [blendMode=null] - The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
|
||||
* @param {boolean} [roundPx=false] - Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
|
|
|
@ -259,7 +259,7 @@ Phaser.Button.prototype.setStateFrame = function (state, frame, switchImmediatel
|
|||
{
|
||||
var frameKey = '_on' + state + 'Frame';
|
||||
|
||||
if (frame != null) // not null or undefined
|
||||
if (frame !== null) // not null or undefined
|
||||
{
|
||||
this[frameKey] = frame;
|
||||
|
||||
|
|
109
src/gameobjects/Creature.js
Normal file
109
src/gameobjects/Creature.js
Normal file
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @author Kestrel Moon Studios <creature@kestrelmoon.com>
|
||||
* @copyright 2015 Photon Storm Ltd and Kestrel Moon Studios
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creature is a custom Game Object used in conjunction with the Creature Runtime libraries by Kestrel Moon Studios.
|
||||
*
|
||||
* It allows you to display animated Game Objects that were created with the [Creature Automated Animation Tool](http://www.kestrelmoon.com/creature/).
|
||||
*
|
||||
* Note 1: You can only use Phaser.Creature objects in WebGL enabled games. They do not work in Canvas mode games.
|
||||
*
|
||||
* Note 2: You must use a build of Phaser that includes the Creature runtimes, or have them loaded before your Phaser game boots.
|
||||
* See the Phaser custom build process for more details. By default the Creature runtimes are NOT included in any pre-configured version of Phaser.
|
||||
* So you'll need to do `grunt custom` to specify a build that includes them.
|
||||
*
|
||||
* @class Phaser.Creature
|
||||
* @extends PIXI.DisplayObjectContainer
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Angle
|
||||
* @extends Phaser.Component.AutoCull
|
||||
* @extends Phaser.Component.BringToTop
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.LifeSpan
|
||||
* @extends Phaser.Component.Reset
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {CreatureManager} manager - A reference to the CreatureManager instance.
|
||||
* @param {number} x - The x coordinate of the Game Object. The coordinate is relative to any parent container this Game Object may be in.
|
||||
* @param {number} y - The y coordinate of the Game Object. The coordinate is relative to any parent container this Game Object may be in.
|
||||
* @param {string|PIXI.Texture} key - The texture used by the Creature Object during rendering. It can be a string which is a reference to the Cache entry, or an instance of a PIXI.Texture.
|
||||
*/
|
||||
Phaser.Creature = function (game, manager, x, y, key) {
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null;
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.CREATURE;
|
||||
|
||||
/**
|
||||
* @property {number} timeDelta - How quickly the animation time/playback advances
|
||||
*/
|
||||
this.timeDelta = 0.05;
|
||||
|
||||
/**
|
||||
* @property {CreatureManager} _manager - The CreatureManager
|
||||
* @private
|
||||
*/
|
||||
this._manager = manager;
|
||||
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
var texture = game.cache.getPixiTexture(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
var texture = key;
|
||||
}
|
||||
|
||||
CreatureRenderer.call(this, manager, texture);
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, x, y);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Creature.prototype = Object.create(CreatureRenderer.prototype);
|
||||
Phaser.Creature.prototype.constructor = Phaser.Creature;
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.Creature.prototype, [
|
||||
'Angle',
|
||||
'AutoCull',
|
||||
'BringToTop',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'LifeSpan',
|
||||
'Reset'
|
||||
]);
|
||||
|
||||
Phaser.Creature.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
||||
Phaser.Creature.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method Phaser.Creature#preUpdate
|
||||
* @memberof Phaser.Creature
|
||||
*/
|
||||
Phaser.Creature.prototype.preUpdate = function() {
|
||||
|
||||
if (!this.preUpdateInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._manager.Update(this.timeDelta);
|
||||
|
||||
this.UpdateData();
|
||||
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
|
@ -41,9 +41,10 @@ Phaser.RenderTexture = function (game, width, height, key, scaleMode, resolution
|
|||
this.type = Phaser.RENDERTEXTURE;
|
||||
|
||||
/**
|
||||
* @property {PIXI.Matrix} matrix - The matrix that is applied when display objects are rendered to this RenderTexture.
|
||||
* @property {PIXI.Matrix} _tempMatrix - The matrix that is applied when display objects are rendered to this RenderTexture.
|
||||
* @private
|
||||
*/
|
||||
this.matrix = new PIXI.Matrix();
|
||||
this._tempMatrix = new PIXI.Matrix();
|
||||
|
||||
PIXI.RenderTexture.call(this, width, height, this.game.renderer, scaleMode, resolution);
|
||||
|
||||
|
@ -55,50 +56,98 @@ Phaser.RenderTexture.prototype = Object.create(PIXI.RenderTexture.prototype);
|
|||
Phaser.RenderTexture.prototype.constructor = Phaser.RenderTexture;
|
||||
|
||||
/**
|
||||
* This function will draw the display object to the texture.
|
||||
* This function will draw the display object to the RenderTexture at the given coordinates.
|
||||
*
|
||||
* When the display object is drawn it takes into account scale and rotation.
|
||||
*
|
||||
* If you don't want those then use RenderTexture.renderRawXY instead.
|
||||
*
|
||||
* @method Phaser.RenderTexture.prototype.renderXY
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject The display object to render to this texture.
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject - The display object to render to this texture.
|
||||
* @param {number} x - The x position to render the object at.
|
||||
* @param {number} y - The y position to render the object at.
|
||||
* @param {boolean} clear - If true the texture will be cleared before the display object is drawn.
|
||||
* @param {boolean} [clear=false] - If true the texture will be cleared before the display object is drawn.
|
||||
*/
|
||||
Phaser.RenderTexture.prototype.renderXY = function (displayObject, x, y, clear) {
|
||||
|
||||
this.matrix.tx = x;
|
||||
this.matrix.ty = y;
|
||||
displayObject.updateTransform();
|
||||
|
||||
this._tempMatrix.copyFrom(displayObject.worldTransform);
|
||||
this._tempMatrix.tx = x;
|
||||
this._tempMatrix.ty = y;
|
||||
|
||||
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
||||
{
|
||||
this.renderWebGL(displayObject, this.matrix, clear);
|
||||
this.renderWebGL(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderCanvas(displayObject, this.matrix, clear);
|
||||
this.renderCanvas(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will draw the display object to the texture.
|
||||
* This function will draw the display object to the RenderTexture at the given coordinates.
|
||||
*
|
||||
* @method Phaser.RenderTexture.prototype.render
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject The display object to render to this texture.
|
||||
* @param {Phaser.Point} position - A Point object containing the position to render the display object at.
|
||||
* @param {boolean} clear - If true the texture will be cleared before the display object is drawn.
|
||||
* When the display object is drawn it doesn't take into account scale, rotation or translation.
|
||||
*
|
||||
* If you need those then use RenderTexture.renderXY instead.
|
||||
*
|
||||
* @method Phaser.RenderTexture.prototype.renderRawXY
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject - The display object to render to this texture.
|
||||
* @param {number} x - The x position to render the object at.
|
||||
* @param {number} y - The y position to render the object at.
|
||||
* @param {boolean} [clear=false] - If true the texture will be cleared before the display object is drawn.
|
||||
*/
|
||||
Phaser.RenderTexture.prototype.render = function (displayObject, position, clear) {
|
||||
Phaser.RenderTexture.prototype.renderRawXY = function (displayObject, x, y, clear) {
|
||||
|
||||
this.matrix.tx = position.x;
|
||||
this.matrix.ty = position.y;
|
||||
this._tempMatrix.identity().translate(x, y);
|
||||
|
||||
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
||||
{
|
||||
this.renderWebGL(displayObject, this.matrix, clear);
|
||||
this.renderWebGL(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderCanvas(displayObject, this.matrix, clear);
|
||||
this.renderCanvas(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will draw the display object to the RenderTexture.
|
||||
*
|
||||
* In versions of Phaser prior to 2.4.0 the second parameter was a Phaser.Point object.
|
||||
* This is now a Matrix allowing you much more control over how the Display Object is rendered.
|
||||
* If you need to replicate the earlier behavior please use Phaser.RenderTexture.renderXY instead.
|
||||
*
|
||||
* If you wish for the displayObject to be rendered taking its current scale, rotation and translation into account then either
|
||||
* pass `null`, leave it undefined or pass `displayObject.worldTransform` as the matrix value.
|
||||
*
|
||||
* @method Phaser.RenderTexture.prototype.render
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject - The display object to render to this texture.
|
||||
* @param {Phaser.Matrix} [matrix] - Optional matrix to apply to the display object before rendering. If null or undefined it will use the worldTransform matrix of the given display object.
|
||||
* @param {boolean} [clear=false] - If true the texture will be cleared before the display object is drawn.
|
||||
*/
|
||||
Phaser.RenderTexture.prototype.render = function (displayObject, matrix, clear) {
|
||||
|
||||
if (typeof matrix === 'undefined' || matrix === null)
|
||||
{
|
||||
this._tempMatrix.copyFrom(displayObject.worldTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._tempMatrix.copyFrom(matrix);
|
||||
}
|
||||
|
||||
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
||||
{
|
||||
this.renderWebGL(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.renderCanvas(displayObject, this._tempMatrix, clear);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ Phaser.Component.LoadTexture.prototype = {
|
|||
* Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.
|
||||
*
|
||||
* @method
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
|
||||
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
|
||||
* @param {string|number} [frame] - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
||||
* @param {boolean} [stopAnimation=true] - If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.
|
||||
*/
|
||||
|
@ -89,11 +89,6 @@ Phaser.Component.LoadTexture.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
// if (!isRenderTexture)
|
||||
// {
|
||||
// this.texture.baseTexture.dirty();
|
||||
// }
|
||||
|
||||
if (setFrame)
|
||||
{
|
||||
this._frame = Phaser.Rectangle.clone(this.texture.frame);
|
||||
|
@ -164,6 +159,11 @@ Phaser.Component.LoadTexture.prototype = {
|
|||
|
||||
this.texture._updateUvs();
|
||||
|
||||
if (this.tilingTexture)
|
||||
{
|
||||
this.refreshTexture = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,60 +1,72 @@
|
|||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2015 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Matrix class is now an object, which makes it a lot faster,
|
||||
* here is a representation of it :
|
||||
* | a | b | tx|
|
||||
* | c | d | ty|
|
||||
* | 0 | 0 | 1 |
|
||||
*
|
||||
* @class Matrix
|
||||
* @constructor
|
||||
*/
|
||||
Phaser.Matrix = function()
|
||||
{
|
||||
/**
|
||||
* @property a
|
||||
* @type Number
|
||||
* @default 1
|
||||
*/
|
||||
this.a = 1;
|
||||
* The Matrix is a 3x3 matrix mostly used for display transforms within the renderer.
|
||||
*
|
||||
* It is represented like so:
|
||||
*
|
||||
* | a | b | tx |
|
||||
* | c | d | ty |
|
||||
* | 0 | 0 | 1 |
|
||||
*
|
||||
* @class Phaser.Matrix
|
||||
* @constructor
|
||||
* @param {number} [a=1]
|
||||
* @param {number} [b=0]
|
||||
* @param {number} [c=0]
|
||||
* @param {number} [d=1]
|
||||
* @param {number} [tx=0]
|
||||
* @param {number} [ty=0]
|
||||
*/
|
||||
Phaser.Matrix = function (a, b, c, d, tx, ty) {
|
||||
|
||||
a = a || 1;
|
||||
b = b || 0;
|
||||
c = c || 0;
|
||||
d = d || 1;
|
||||
tx = tx || 0;
|
||||
ty = ty || 0;
|
||||
|
||||
/**
|
||||
* @property b
|
||||
* @type Number
|
||||
* @default 0
|
||||
*/
|
||||
this.b = 0;
|
||||
* @property {number} a
|
||||
* @default 1
|
||||
*/
|
||||
this.a = a;
|
||||
|
||||
/**
|
||||
* @property c
|
||||
* @type Number
|
||||
* @default 0
|
||||
*/
|
||||
this.c = 0;
|
||||
* @property {number} b
|
||||
* @default 0
|
||||
*/
|
||||
this.b = b;
|
||||
|
||||
/**
|
||||
* @property d
|
||||
* @type Number
|
||||
* @default 1
|
||||
*/
|
||||
this.d = 1;
|
||||
* @property {number} c
|
||||
* @default 0
|
||||
*/
|
||||
this.c = c;
|
||||
|
||||
/**
|
||||
* @property tx
|
||||
* @type Number
|
||||
* @default 0
|
||||
*/
|
||||
this.tx = 0;
|
||||
* @property {number} d
|
||||
* @default 1
|
||||
*/
|
||||
this.d = d;
|
||||
|
||||
/**
|
||||
* @property ty
|
||||
* @type Number
|
||||
* @default 0
|
||||
*/
|
||||
this.ty = 0;
|
||||
* @property {number} tx
|
||||
* @default 0
|
||||
*/
|
||||
this.tx = tx;
|
||||
|
||||
/**
|
||||
* @property {number} ty
|
||||
* @default 0
|
||||
*/
|
||||
this.ty = ty;
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
|
@ -64,221 +76,309 @@ Phaser.Matrix = function()
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
|
||||
*
|
||||
* a = array[0]
|
||||
* b = array[1]
|
||||
* c = array[3]
|
||||
* d = array[4]
|
||||
* tx = array[2]
|
||||
* ty = array[5]
|
||||
*
|
||||
* @method fromArray
|
||||
* @param array {Array} The array that the matrix will be populated from.
|
||||
*/
|
||||
Phaser.Matrix.prototype.fromArray = function(array)
|
||||
{
|
||||
this.a = array[0];
|
||||
this.b = array[1];
|
||||
this.c = array[3];
|
||||
this.d = array[4];
|
||||
this.tx = array[2];
|
||||
this.ty = array[5];
|
||||
};
|
||||
Phaser.Matrix.prototype = {
|
||||
|
||||
/**
|
||||
* Creates an array from the current Matrix object.
|
||||
*
|
||||
* @method toArray
|
||||
* @param transpose {Boolean} Whether we need to transpose the matrix or not
|
||||
* @return {Array} the newly created array which contains the matrix
|
||||
*/
|
||||
Phaser.Matrix.prototype.toArray = function(transpose)
|
||||
{
|
||||
if (!this.array)
|
||||
{
|
||||
this.array = new PIXI.Float32Array(9);
|
||||
/**
|
||||
* Sets the values of this Matrix to the values in the given array.
|
||||
*
|
||||
* The Array elements should be set as follows:
|
||||
*
|
||||
* a = array[0]
|
||||
* b = array[1]
|
||||
* c = array[3]
|
||||
* d = array[4]
|
||||
* tx = array[2]
|
||||
* ty = array[5]
|
||||
*
|
||||
* @method Phaser.Matrix#fromArray
|
||||
* @param {Array} array - The array to copy from.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
fromArray: function (array) {
|
||||
|
||||
return this.setTo(array[0], array[1], array[3], array[4], array[2], array[5]);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the values of this Matrix to the given values.
|
||||
*
|
||||
* @method Phaser.Matrix#setTo
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @param {number} c
|
||||
* @param {number} d
|
||||
* @param {number} tx
|
||||
* @param {number} ty
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
setTo: function (a, b, c, d, tx, ty) {
|
||||
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.d = d;
|
||||
this.tx = tx;
|
||||
this.ty = ty;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Matrix object based on the values of this Matrix.
|
||||
* If you provide the output parameter the values of this Matrix will be copied over to it.
|
||||
* If the output parameter is blank a new Matrix object will be created.
|
||||
*
|
||||
* @method Phaser.Matrix#clone
|
||||
* @param {Phaser.Matrix} [output] - If provided the values of this Matrix will be copied to it, otherwise a new Matrix object is created.
|
||||
* @return {Phaser.Matrix} A clone of this Matrix.
|
||||
*/
|
||||
clone: function (output) {
|
||||
|
||||
if (typeof output === "undefined" || output === null)
|
||||
{
|
||||
output = new Phaser.Matrix(this.a, this.b, this.c, this.d, this.tx, this.ty);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.a = this.a;
|
||||
output.b = this.b;
|
||||
output.c = this.c;
|
||||
output.d = this.d;
|
||||
output.tx = this.tx;
|
||||
output.ty = this.ty;
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies the properties from this Matrix to the given Matrix.
|
||||
*
|
||||
* @method Phaser.Matrix#copyTo
|
||||
* @param {Phaser.Matrix} matrix - The Matrix to copy from.
|
||||
* @return {Phaser.Matrix} The destination Matrix object.
|
||||
*/
|
||||
copyTo: function (matrix) {
|
||||
|
||||
matrix.copyFrom(this);
|
||||
|
||||
return matrix;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies the properties from the given Matrix into this Matrix.
|
||||
*
|
||||
* @method Phaser.Matrix#copyFrom
|
||||
* @param {Phaser.Matrix} matrix - The Matrix to copy from.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
copyFrom: function (matrix) {
|
||||
|
||||
this.a = matrix.a;
|
||||
this.b = matrix.b;
|
||||
this.c = matrix.c;
|
||||
this.d = matrix.d;
|
||||
this.tx = matrix.tx;
|
||||
this.ty = matrix.ty;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a Float32 Array with values populated from this Matrix object.
|
||||
*
|
||||
* @method Phaser.Matrix#toArray
|
||||
* @param {boolean} [transpose=false] - Whether the values in the array are transposed or not.
|
||||
* @param {PIXI.Float32Array} [array] - If provided the values will be set into this array, otherwise a new Float32Array is created.
|
||||
* @return {PIXI.Float32Array} The newly created array which contains the matrix.
|
||||
*/
|
||||
toArray: function (transpose, array) {
|
||||
|
||||
if (typeof array === 'undefined') { array = new PIXI.Float32Array(9); }
|
||||
|
||||
if (transpose)
|
||||
{
|
||||
array[0] = this.a;
|
||||
array[1] = this.b;
|
||||
array[2] = 0;
|
||||
array[3] = this.c;
|
||||
array[4] = this.d;
|
||||
array[5] = 0;
|
||||
array[6] = this.tx;
|
||||
array[7] = this.ty;
|
||||
array[8] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
array[0] = this.a;
|
||||
array[1] = this.c;
|
||||
array[2] = this.tx;
|
||||
array[3] = this.b;
|
||||
array[4] = this.d;
|
||||
array[5] = this.ty;
|
||||
array[6] = 0;
|
||||
array[7] = 0;
|
||||
array[8] = 1;
|
||||
}
|
||||
|
||||
return array;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a new position with the current transformation applied.
|
||||
*
|
||||
* Can be used to go from a childs coordinate space to the world coordinate space (e.g. rendering)
|
||||
*
|
||||
* @method Phaser.Matrix#apply
|
||||
* @param {Phaser.Point} pos - The origin Point.
|
||||
* @param {Phaser.Point} [newPos] - The point that the new position is assigned to. This can be same as input point.
|
||||
* @return {Phaser.Point} The new point, transformed through this matrix.
|
||||
*/
|
||||
apply: function (pos, newPos) {
|
||||
|
||||
if (typeof newPos === 'undefined') { newPos = new Phaser.Point(); }
|
||||
|
||||
newPos.x = this.a * pos.x + this.c * pos.y + this.tx;
|
||||
newPos.y = this.b * pos.x + this.d * pos.y + this.ty;
|
||||
|
||||
return newPos;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a new position with the inverse of the current transformation applied.
|
||||
*
|
||||
* Can be used to go from the world coordinate space to a childs coordinate space. (e.g. input)
|
||||
*
|
||||
* @method Phaser.Matrix#applyInverse
|
||||
* @param {Phaser.Point} pos - The origin Point.
|
||||
* @param {Phaser.Point} [newPos] - The point that the new position is assigned to. This can be same as input point.
|
||||
* @return {Phaser.Point} The new point, inverse transformed through this matrix.
|
||||
*/
|
||||
applyInverse: function (pos, newPos) {
|
||||
|
||||
if (typeof newPos === 'undefined') { newPos = new Phaser.Point(); }
|
||||
|
||||
var id = 1 / (this.a * this.d + this.c * -this.b);
|
||||
var x = pos.x;
|
||||
var y = pos.y;
|
||||
|
||||
newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
|
||||
newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
|
||||
|
||||
return newPos;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates the matrix on the x and y.
|
||||
* This is the same as Matrix.tx += x.
|
||||
*
|
||||
* @method Phaser.Matrix#translate
|
||||
* @param {number} x - The x value to translate on.
|
||||
* @param {number} y - The y value to translate on.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
translate: function (x, y) {
|
||||
|
||||
this.tx += x;
|
||||
this.ty += y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Applies a scale transformation to this matrix.
|
||||
*
|
||||
* @method Phaser.Matrix#scale
|
||||
* @param {number} x - The amount to scale horizontally.
|
||||
* @param {number} y - The amount to scale vertically.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
scale: function (x, y) {
|
||||
|
||||
this.a *= x;
|
||||
this.d *= y;
|
||||
this.c *= x;
|
||||
this.b *= y;
|
||||
this.tx *= x;
|
||||
this.ty *= y;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Applies a rotation transformation to this matrix.
|
||||
*
|
||||
* @method Phaser.Matrix#rotate
|
||||
* @param {number} angle - The angle to rotate by, given in radians.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
rotate: function (angle) {
|
||||
|
||||
var cos = Math.cos(angle);
|
||||
var sin = Math.sin(angle);
|
||||
|
||||
var a1 = this.a;
|
||||
var c1 = this.c;
|
||||
var tx1 = this.tx;
|
||||
|
||||
this.a = a1 * cos-this.b * sin;
|
||||
this.b = a1 * sin+this.b * cos;
|
||||
this.c = c1 * cos-this.d * sin;
|
||||
this.d = c1 * sin+this.d * cos;
|
||||
this.tx = tx1 * cos - this.ty * sin;
|
||||
this.ty = tx1 * sin + this.ty * cos;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Appends the given Matrix to this Matrix.
|
||||
*
|
||||
* @method Phaser.Matrix#append
|
||||
* @param {Phaser.Matrix} matrix - The matrix to append to this one.
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
append: function (matrix) {
|
||||
|
||||
var a1 = this.a;
|
||||
var b1 = this.b;
|
||||
var c1 = this.c;
|
||||
var d1 = this.d;
|
||||
|
||||
this.a = matrix.a * a1 + matrix.b * c1;
|
||||
this.b = matrix.a * b1 + matrix.b * d1;
|
||||
this.c = matrix.c * a1 + matrix.d * c1;
|
||||
this.d = matrix.c * b1 + matrix.d * d1;
|
||||
|
||||
this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
|
||||
this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets this Matrix to an identity (default) matrix.
|
||||
*
|
||||
* @method identity
|
||||
* @return {Phaser.Matrix} This Matrix object.
|
||||
*/
|
||||
identity: function () {
|
||||
|
||||
return this.setTo(1, 0, 0, 1, 0, 0);
|
||||
}
|
||||
|
||||
var array = this.array;
|
||||
|
||||
if (transpose)
|
||||
{
|
||||
array[0] = this.a;
|
||||
array[1] = this.b;
|
||||
array[2] = 0;
|
||||
array[3] = this.c;
|
||||
array[4] = this.d;
|
||||
array[5] = 0;
|
||||
array[6] = this.tx;
|
||||
array[7] = this.ty;
|
||||
array[8] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
array[0] = this.a;
|
||||
array[1] = this.c;
|
||||
array[2] = this.tx;
|
||||
array[3] = this.b;
|
||||
array[4] = this.d;
|
||||
array[5] = this.ty;
|
||||
array[6] = 0;
|
||||
array[7] = 0;
|
||||
array[8] = 1;
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a new position with the current transformation applied.
|
||||
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
|
||||
*
|
||||
* @method apply
|
||||
* @param pos {Point} The origin
|
||||
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
|
||||
* @return {Point} The new point, transformed through this matrix
|
||||
*/
|
||||
Phaser.Matrix.prototype.apply = function(pos, newPos)
|
||||
{
|
||||
newPos = newPos || new Phaser.Point();
|
||||
|
||||
var x = pos.x;
|
||||
var y = pos.y;
|
||||
|
||||
newPos.x = this.a * x + this.c * y + this.tx;
|
||||
newPos.y = this.b * x + this.d * y + this.ty;
|
||||
|
||||
return newPos;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a new position with the inverse of the current transformation applied.
|
||||
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
|
||||
*
|
||||
* @method applyInverse
|
||||
* @param pos {Point} The origin
|
||||
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
|
||||
* @return {Point} The new point, inverse-transformed through this matrix
|
||||
*/
|
||||
Phaser.Matrix.prototype.applyInverse = function(pos, newPos)
|
||||
{
|
||||
newPos = newPos || new Phaser.Point();
|
||||
|
||||
var id = 1 / (this.a * this.d + this.c * -this.b);
|
||||
var x = pos.x;
|
||||
var y = pos.y;
|
||||
|
||||
newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
|
||||
newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
|
||||
|
||||
return newPos;
|
||||
};
|
||||
|
||||
/**
|
||||
* Translates the matrix on the x and y.
|
||||
*
|
||||
* @method translate
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||
**/
|
||||
Phaser.Matrix.prototype.translate = function(x, y)
|
||||
{
|
||||
this.tx += x;
|
||||
this.ty += y;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies a scale transformation to the matrix.
|
||||
*
|
||||
* @method scale
|
||||
* @param {Number} x The amount to scale horizontally
|
||||
* @param {Number} y The amount to scale vertically
|
||||
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||
**/
|
||||
Phaser.Matrix.prototype.scale = function(x, y)
|
||||
{
|
||||
this.a *= x;
|
||||
this.d *= y;
|
||||
this.c *= x;
|
||||
this.b *= y;
|
||||
this.tx *= x;
|
||||
this.ty *= y;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Applies a rotation transformation to the matrix.
|
||||
* @method rotate
|
||||
* @param {Number} angle The angle in radians.
|
||||
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||
**/
|
||||
Phaser.Matrix.prototype.rotate = function(angle)
|
||||
{
|
||||
var cos = Math.cos( angle );
|
||||
var sin = Math.sin( angle );
|
||||
|
||||
var a1 = this.a;
|
||||
var c1 = this.c;
|
||||
var tx1 = this.tx;
|
||||
|
||||
this.a = a1 * cos-this.b * sin;
|
||||
this.b = a1 * sin+this.b * cos;
|
||||
this.c = c1 * cos-this.d * sin;
|
||||
this.d = c1 * sin+this.d * cos;
|
||||
this.tx = tx1 * cos - this.ty * sin;
|
||||
this.ty = tx1 * sin + this.ty * cos;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Appends the given Matrix to this Matrix.
|
||||
*
|
||||
* @method append
|
||||
* @param {Matrix} matrix
|
||||
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||
*/
|
||||
Phaser.Matrix.prototype.append = function(matrix)
|
||||
{
|
||||
var a1 = this.a;
|
||||
var b1 = this.b;
|
||||
var c1 = this.c;
|
||||
var d1 = this.d;
|
||||
|
||||
this.a = matrix.a * a1 + matrix.b * c1;
|
||||
this.b = matrix.a * b1 + matrix.b * d1;
|
||||
this.c = matrix.c * a1 + matrix.d * c1;
|
||||
this.d = matrix.c * b1 + matrix.d * d1;
|
||||
|
||||
this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
|
||||
this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets this Matix to an identity (default) matrix.
|
||||
*
|
||||
* @method identity
|
||||
* @return {Matrix} This matrix. Good for chaining method calls.
|
||||
*/
|
||||
Phaser.Matrix.prototype.identity = function()
|
||||
{
|
||||
this.a = 1;
|
||||
this.b = 0;
|
||||
this.c = 0;
|
||||
this.d = 1;
|
||||
this.tx = 0;
|
||||
this.ty = 0;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Phaser.identityMatrix = new Phaser.Matrix();
|
||||
|
|
|
@ -488,7 +488,7 @@ Phaser.Input.prototype = {
|
|||
|
||||
if (this.pointers.length >= Phaser.Input.MAX_POINTERS)
|
||||
{
|
||||
console.warn("Phaser.Input.addPointer: only " + Phaser.Input.MAX_POINTERS + " pointer allowed");
|
||||
console.warn("Phaser.Input.addPointer: Maximum limit of " + Phaser.Input.MAX_POINTERS + " pointers reached.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -344,18 +344,22 @@ Phaser.Cache.prototype = {
|
|||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
||||
|
||||
if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
|
||||
{
|
||||
this._images[key].frameData = Phaser.AnimationParser.JSONData(this.game, atlasData, key);
|
||||
}
|
||||
else if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
|
||||
{
|
||||
this._images[key].frameData = Phaser.AnimationParser.JSONDataHash(this.game, atlasData, key);
|
||||
}
|
||||
else if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||
if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||
{
|
||||
this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let's just work it out from the frames array
|
||||
if (Array.isArray(atlasData.frames))
|
||||
{
|
||||
this._images[key].frameData = Phaser.AnimationParser.JSONData(this.game, atlasData, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._images[key].frameData = Phaser.AnimationParser.JSONDataHash(this.game, atlasData, key);
|
||||
}
|
||||
}
|
||||
|
||||
this._resolveURL(url, this._images[key]);
|
||||
|
||||
|
@ -1108,24 +1112,43 @@ Phaser.Cache.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* DEPRECATED: Please use Cache.getRenderTexture instead. This method will be removed in Phaser 2.2.0.
|
||||
* Gets a PIXI.Texture by key from the Cache.
|
||||
*
|
||||
* Get a RenderTexture by key.
|
||||
*
|
||||
* @method Phaser.Cache#getTexture
|
||||
* @deprecated Please use Cache.getRenderTexture instead. This method will be removed in Phaser 2.2.0.
|
||||
* @param {string} key - Asset key of the RenderTexture to retrieve from the Cache.
|
||||
* @return {Phaser.RenderTexture} The RenderTexture object.
|
||||
* @method Phaser.Cache#getPixiTexture
|
||||
* @param {string} key - Asset key of the Texture to retrieve from the Cache.
|
||||
* @return {PIXI.Texture} The Texture object.
|
||||
*/
|
||||
getTexture: function (key) {
|
||||
getPixiTexture: function (key) {
|
||||
|
||||
if (this._textures[key])
|
||||
if (PIXI.TextureCache[key])
|
||||
{
|
||||
return this._textures[key];
|
||||
return PIXI.TextureCache[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"');
|
||||
console.warn('Phaser.Cache.getPixiTexture: Invalid key: "' + key + '"');
|
||||
return null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a PIXI.BaseTexture by key from the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#getPixiBaseTexture
|
||||
* @param {string} key - Asset key of the BaseTexture to retrieve from the Cache.
|
||||
* @return {PIXI.BaseTexture} The BaseTexture object.
|
||||
*/
|
||||
getPixiBaseTexture: function (key) {
|
||||
|
||||
if (PIXI.BaseTextureCache[key])
|
||||
{
|
||||
return PIXI.BaseTextureCache[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getPixiBaseTexture: Invalid key: "' + key + '"');
|
||||
return null;
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -459,11 +459,34 @@ Phaser.Loader.prototype = {
|
|||
* @protected
|
||||
* @param {string} type - The type of resource to add to the list (image, audio, xml, etc).
|
||||
* @param {string} key - The unique Cache ID key of this resource.
|
||||
* @param {string} url - The URL the asset will be loaded from.
|
||||
* @param {string} [url] - The URL the asset will be loaded from.
|
||||
* @param {object} [properties=(none)] - Any additional properties needed to load the file. These are added directly to the added file object and overwrite any defaults.
|
||||
* @param {boolean} [overwrite=false] - If true then this will overwrite a file asset of the same type/key. Otherwise it will will only add a new asset. If overwrite is true, and the asset is already being loaded (or has been loaded), then it is appended instead.
|
||||
* @param {string} [extension] - If no URL is given the Loader will sometimes auto-generate the URL based on the key, using this as the extension.
|
||||
* @return {Phaser.Loader} This instance of the Phaser Loader.
|
||||
*/
|
||||
addToFileList: function (type, key, url, properties, overwrite) {
|
||||
addToFileList: function (type, key, url, properties, overwrite, extension) {
|
||||
|
||||
if (typeof overwrite === 'undefined') { overwrite = false; }
|
||||
|
||||
if (typeof key === 'undefined' || key === '')
|
||||
{
|
||||
console.warn("Phaser.Loader: Invalid or no key given of type " + type);
|
||||
return this;
|
||||
}
|
||||
|
||||
if (typeof url === 'undefined' || url === null)
|
||||
{
|
||||
if (extension)
|
||||
{
|
||||
url = key + extension;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn("Phaser.Loader: No URL given for file type: " + type + " key: " + key);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
var file = {
|
||||
type: type,
|
||||
|
@ -506,6 +529,8 @@ Phaser.Loader.prototype = {
|
|||
this._totalFileCount++;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -596,111 +621,165 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add an 'image' to the Loader.
|
||||
* Adds an Image to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the image via `Cache.getImage(key)`
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.png". It will always add `.png` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* @method Phaser.Loader#image
|
||||
* @param {string} key - Unique asset key of this image file.
|
||||
* @param {string} url - URL of image file.
|
||||
* @param {string} [url] - URL of an image file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {boolean} [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
image: function (key, url, overwrite) {
|
||||
|
||||
if (typeof overwrite === 'undefined') { overwrite = false; }
|
||||
|
||||
this.addToFileList('image', key, url, undefined, overwrite);
|
||||
|
||||
return this;
|
||||
return this.addToFileList('image', key, url, undefined, overwrite, '.png');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a 'text' file to the Loader.
|
||||
* Adds a Text file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getText(key)`
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.txt". It will always add `.txt` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* @method Phaser.Loader#text
|
||||
* @param {string} key - Unique asset key of the text file.
|
||||
* @param {string} url - URL of the text file.
|
||||
* @param {string} [url] - URL of the text file. If undefined or `null` the url will be set to `<key>.txt`, i.e. if `key` was "bomb" then the URL will be "bomb.txt".
|
||||
* @param {boolean} [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
text: function (key, url, overwrite) {
|
||||
|
||||
if (typeof overwrite === 'undefined') { overwrite = false; }
|
||||
|
||||
this.addToFileList('text', key, url, undefined, overwrite);
|
||||
|
||||
return this;
|
||||
return this.addToFileList('text', key, url, undefined, overwrite, '.txt');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a 'json' file to the Loader.
|
||||
* Adds a JSON file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getJSON(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.json". It will always add `.json` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* @method Phaser.Loader#json
|
||||
* @param {string} key - Unique asset key of the json file.
|
||||
* @param {string} url - URL of the json file.
|
||||
* @param {string} [url] - URL of the JSON file. If undefined or `null` the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.json".
|
||||
* @param {boolean} [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
json: function (key, url, overwrite) {
|
||||
|
||||
if (typeof overwrite === 'undefined') { overwrite = false; }
|
||||
|
||||
this.addToFileList('json', key, url, undefined, overwrite);
|
||||
|
||||
return this;
|
||||
return this.addToFileList('json', key, url, undefined, overwrite, '.json');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add an XML ('xml') file to the Loader.
|
||||
* Adds an XML file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getXML(key)`.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.xml". It will always add `.xml` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* @method Phaser.Loader#xml
|
||||
* @param {string} key - Unique asset key of the xml file.
|
||||
* @param {string} url - URL of the xml file.
|
||||
* @param {string} [url] - URL of the XML file. If undefined or `null` the url will be set to `<key>.xml`, i.e. if `key` was "bomb" then the URL will be "bomb.xml".
|
||||
* @param {boolean} [overwrite=false] - If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
xml: function (key, url, overwrite) {
|
||||
|
||||
if (typeof overwrite === 'undefined') { overwrite = false; }
|
||||
|
||||
this.addToFileList('xml', key, url, undefined, overwrite);
|
||||
|
||||
return this;
|
||||
return this.addToFileList('xml', key, url, undefined, overwrite, '.xml');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a JavaScript ('script') file to the Loader.
|
||||
* Adds a JavaScript file to the current load queue.
|
||||
*
|
||||
* The loaded JavaScript is automatically turned into a script tag and executed, so be careful what you load!
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.js". It will always add `.js` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* Upon successful load the JavaScript is automatically turned into a script tag and executed, so be careful what you load!
|
||||
*
|
||||
* A callback, which will be invoked as the script tag has been created, can also be specified.
|
||||
* The callback must return relevant `data`.
|
||||
*
|
||||
* @method Phaser.Loader#script
|
||||
* @param {string} key - Unique asset key of the script file.
|
||||
* @param {string} url - URL of the JavaScript file.
|
||||
* @param {string} [url] - URL of the JavaScript file. If undefined or `null` the url will be set to `<key>.js`, i.e. if `key` was "bomb" then the URL will be "bomb.js".
|
||||
* @param {function} [callback=(none)] - Optional callback that will be called after the script tag has loaded, so you can perform additional processing.
|
||||
* @param {object} [callbackContext=(loader)] - The context under which the callback will be applied. If not specified it will use the callback itself as the context.
|
||||
* @param {object} [callbackContext=(loader)] - The context under which the callback will be applied. If not specified it will use the Phaser Loader as the context.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
script: function (key, url, callback, callbackContext) {
|
||||
|
||||
if (typeof callback === 'undefined') { callback = false; }
|
||||
|
||||
// Why is the default callback context the ..callback?
|
||||
if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; }
|
||||
if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = this; }
|
||||
|
||||
this.addToFileList('script', key, url, { syncPoint: true, callback: callback, callbackContext: callbackContext });
|
||||
|
||||
return this;
|
||||
return this.addToFileList('script', key, url, { syncPoint: true, callback: callback, callbackContext: callbackContext }, false, '.js');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a 'binary' file to the Loader.
|
||||
* Adds a binary file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getBinary(key)`.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.bin". It will always add `.bin` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load.
|
||||
* When the callback is called it will be passed 2 parameters: the key of the file and the file data.
|
||||
|
@ -709,7 +788,7 @@ Phaser.Loader.prototype = {
|
|||
*
|
||||
* @method Phaser.Loader#binary
|
||||
* @param {string} key - Unique asset key of the binary file.
|
||||
* @param {string} url - URL of the binary file.
|
||||
* @param {string} [url] - URL of the binary file. If undefined or `null` the url will be set to `<key>.bin`, i.e. if `key` was "bomb" then the URL will be "bomb.bin".
|
||||
* @param {function} [callback=(none)] - Optional callback that will be passed the file after loading, so you can perform additional processing on it.
|
||||
* @param {object} [callbackContext] - The context under which the callback will be applied. If not specified it will use the callback itself as the context.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
|
@ -721,20 +800,37 @@ Phaser.Loader.prototype = {
|
|||
// Why is the default callback context the ..callback?
|
||||
if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; }
|
||||
|
||||
this.addToFileList('binary', key, url, { callback: callback, callbackContext: callbackContext });
|
||||
|
||||
return this;
|
||||
return this.addToFileList('binary', key, url, { callback: callback, callbackContext: callbackContext }, false, '.bin');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new sprite sheet ('spritesheet') to the loader.
|
||||
* Adds a Sprite Sheet to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* To clarify the terminology that Phaser uses: A Sprite Sheet is an image containing frames, usually of an animation, that are all equal
|
||||
* dimensions and often in sequence. For example if the frame size is 32x32 then every frame in the sprite sheet will be that size.
|
||||
* Sometimes (outside of Phaser) the term "sprite sheet" is used to refer to a texture atlas.
|
||||
* A Texture Atlas works by packing together images as best it can, using whatever frame sizes it likes, often with cropping and trimming
|
||||
* the frames in the process. Software such as Texture Packer, Flash CC or Shoebox all generate texture atlases, not sprite sheets.
|
||||
* If you've got an atlas then use `Loader.atlas` instead.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the image to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getImage(key)`. Sprite sheets, being image based, live in the same Cache as all other Images.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "bomb"
|
||||
* and no URL is given then the Loader will set the URL to be "bomb.png". It will always add `.png` as the extension.
|
||||
* If you do not desire this action then provide a URL.
|
||||
*
|
||||
* @method Phaser.Loader#spritesheet
|
||||
* @param {string} key - Unique asset key of the sheet file.
|
||||
* @param {string} url - URL of the sheet file.
|
||||
* @param {number} frameWidth - Width of each single frame.
|
||||
* @param {number} frameHeight - Height of each single frame.
|
||||
* @param {string} url - URL of the sprite sheet file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {number} frameWidth - Width in pixels of a single frame in the sprite sheet.
|
||||
* @param {number} frameHeight - Height in pixels of a single frame in the sprite sheet.
|
||||
* @param {number} [frameMax=-1] - How many frames in this sprite sheet. If not specified it will divide the whole image into frames.
|
||||
* @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
|
||||
* @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
|
||||
|
@ -746,14 +842,20 @@ Phaser.Loader.prototype = {
|
|||
if (typeof margin === 'undefined') { margin = 0; }
|
||||
if (typeof spacing === 'undefined') { spacing = 0; }
|
||||
|
||||
this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, margin: margin, spacing: spacing });
|
||||
|
||||
return this;
|
||||
return this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, margin: margin, spacing: spacing }, false, '.png');
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new 'audio' file to the loader.
|
||||
* Adds an audio file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getSound(key)`.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* @method Phaser.Loader#audio
|
||||
* @param {string} key - Unique asset key of the audio file.
|
||||
|
@ -767,6 +869,11 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
audio: function (key, urls, autoDecode) {
|
||||
|
||||
if (this.game.sound.noAudio)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
if (typeof autoDecode === 'undefined') { autoDecode = true; }
|
||||
|
||||
if (typeof urls === 'string')
|
||||
|
@ -774,18 +881,25 @@ Phaser.Loader.prototype = {
|
|||
urls = [urls];
|
||||
}
|
||||
|
||||
this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
|
||||
|
||||
return this;
|
||||
return this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new audiosprite file to the loader.
|
||||
* Adds an audio sprite file to the current load queue.
|
||||
*
|
||||
* The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Audio Sprites are a combination of audio files and a JSON configuration.
|
||||
*
|
||||
* The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite
|
||||
*
|
||||
* Retrieve the file via `Cache.getSoundData(key)`.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* @method Phaser.Loader#audiosprite
|
||||
* @param {string} key - Unique asset key of the audio file.
|
||||
* @param {Array|string} urls - An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL.
|
||||
|
@ -797,6 +911,11 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
audiosprite: function(key, urls, jsonURL, jsonData, autoDecode) {
|
||||
|
||||
if (this.game.sound.noAudio)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
if (typeof jsonURL === 'undefined') { jsonURL = null; }
|
||||
if (typeof jsonData === 'undefined') { jsonData = null; }
|
||||
if (typeof autoDecode === 'undefined') { autoDecode = true; }
|
||||
|
@ -826,12 +945,31 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new 'tilemap' loading request. If data is supplied the object is loaded immediately.
|
||||
* Adds a Tile Map data file to the current load queue.
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to a json file.
|
||||
* Or you can pass in a JSON object or String via the `data` parameter.
|
||||
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If a URL is provided the file is **not** loaded immediately after calling this method, but is added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getTilemapData(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified and no data is given then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "level1" and no URL or data is given then the Loader will set the URL to be "level1.json".
|
||||
* If you set the format to be Tilemap.CSV it will set the URL to be "level1.csv" instead.
|
||||
*
|
||||
* If you do not desire this action then provide a URL or data object.
|
||||
*
|
||||
* @method Phaser.Loader#tilemap
|
||||
* @param {string} key - Unique asset key of the tilemap data.
|
||||
* @param {string} [url] - The url of the map data file (csv/json)
|
||||
* @param {object} [data] - An optional JSON data object. If given then the url is ignored and this JSON object is used for map data instead.
|
||||
* @param {string} [url] - URL of the tile map file. If undefined or `null` and no data is given the url will be set to `<key>.json`, i.e. if `key` was "level1" then the URL will be "level1.json".
|
||||
* @param {object|string} [data] - An optional JSON data object. If given then the url is ignored and this JSON object is used for map data instead.
|
||||
* @param {number} [format=Phaser.Tilemap.CSV] - The format of the map data. Either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
|
@ -843,9 +981,14 @@ Phaser.Loader.prototype = {
|
|||
|
||||
if (!url && !data)
|
||||
{
|
||||
console.warn('Phaser.Loader.tilemap - Both url and data are null. One must be set.');
|
||||
|
||||
return this;
|
||||
if (format === Phaser.Tilemap.CSV)
|
||||
{
|
||||
url = key + '.csv';
|
||||
}
|
||||
else
|
||||
{
|
||||
url = key + '.json';
|
||||
}
|
||||
}
|
||||
|
||||
// A map data object has been given
|
||||
|
@ -857,7 +1000,7 @@ Phaser.Loader.prototype = {
|
|||
case Phaser.Tilemap.CSV:
|
||||
break;
|
||||
|
||||
// An xml string or object has been given
|
||||
// A json string or object has been given
|
||||
case Phaser.Tilemap.TILED_JSON:
|
||||
|
||||
if (typeof data === 'string')
|
||||
|
@ -879,14 +1022,33 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new 'physics' data object loading request. If data is supplied the object is loaded immediately.
|
||||
* Adds a physics data file to the current load queue.
|
||||
*
|
||||
* The data must be in Lime + Corona JSON format. Physics Editor by code'n'web exports in this format natively.
|
||||
* The data must be in `Lime + Corona` JSON format. [Physics Editor](https://www.codeandweb.com) by code'n'web exports in this format natively.
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to a json file.
|
||||
* Or you can pass in a JSON object or String via the `data` parameter.
|
||||
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If a URL is provided the file is **not** loaded immediately after calling this method, but is added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getJSON(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed.
|
||||
*
|
||||
* The URL can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the URL isn't specified and no data is given then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "bomb" and no URL or data is given then the Loader will set the URL to be "bomb.json".
|
||||
* It will always use `.json` as the extension.
|
||||
*
|
||||
* If you do not desire this action then provide a URL or data object.
|
||||
*
|
||||
* @method Phaser.Loader#physics
|
||||
* @param {string} key - Unique asset key of the physics json data.
|
||||
* @param {string} [url] - The url of the map data file (csv/json)
|
||||
* @param {object} [data] - An optional JSON data object. If given then the url is ignored and this JSON object is used for physics data instead.
|
||||
* @param {string} [url] - URL of the physics data file. If undefined or `null` and no data is given the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.json".
|
||||
* @param {object|string} [data] - An optional JSON data object. If given then the url is ignored and this JSON object is used for physics data instead.
|
||||
* @param {string} [format=Phaser.Physics.LIME_CORONA_JSON] - The format of the physics data.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
|
@ -898,9 +1060,7 @@ Phaser.Loader.prototype = {
|
|||
|
||||
if (!url && !data)
|
||||
{
|
||||
console.warn('Phaser.Loader.physics - Both url and data are null. One must be set.');
|
||||
|
||||
return this;
|
||||
url = key + '.json';
|
||||
}
|
||||
|
||||
// A map data object has been given
|
||||
|
@ -923,12 +1083,38 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new bitmap font ('bitmapfont') loading request.
|
||||
* Adds Bitmap Font files to the current load queue.
|
||||
*
|
||||
* To create the Bitmap Font files you can use:
|
||||
*
|
||||
* BMFont (Windows, free): http://www.angelcode.com/products/bmfont/
|
||||
* Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner
|
||||
* Littera (Web-based, free): http://kvazars.com/littera/
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to an xml file.
|
||||
* Or you can pass in an XML object or String via the `xmlData` parameter.
|
||||
* If you pass a String the data is automatically run through `Loader.parseXML` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getBitmapFont(key)`. XML files are automatically parsed upon load.
|
||||
* If you need to control when the XML is parsed then use `Loader.text` instead and parse the XML file as needed.
|
||||
*
|
||||
* The URLs can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the textureURL isn't specified then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "megaFont" and textureURL is null then the Loader will set the URL to be "megaFont.png".
|
||||
* The same is true for the xmlURL. If xmlURL isn't specified and no xmlData has been provided then the Loader will
|
||||
* set the xmlURL to be the key. For example if the key is "megaFont" the xmlURL will be set to "megaFont.xml".
|
||||
*
|
||||
* If you do not desire this action then provide URLs and / or a data object.
|
||||
*
|
||||
* @method Phaser.Loader#bitmapFont
|
||||
* @param {string} key - Unique asset key of the bitmap font.
|
||||
* @param {string} textureURL - The url of the font image file.
|
||||
* @param {string} [xmlURL] - The url of the font data file (xml/fnt)
|
||||
* @param {string} [textureURL] - URL of the Bitmap Font texture file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "megaFont" then the URL will be "megaFont.png".
|
||||
* @param {string} [xmlURL] - URL of the Bitmap Font data file. If undefined or `null` and no data is given the url will be set to `<key>.xml`, i.e. if `key` was "megaFont" then the URL will be "megaFont.xml".
|
||||
* @param {object} [xmlData] - An optional XML data object.
|
||||
* @param {number} [xSpacing=0] - If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
|
||||
* @param {number} [ySpacing=0] - If you'd like to add additional vertical spacing between the lines then set the pixel value here.
|
||||
|
@ -936,11 +1122,21 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
bitmapFont: function (key, textureURL, xmlURL, xmlData, xSpacing, ySpacing) {
|
||||
|
||||
if (typeof textureURL === 'undefined' || textureURL === null)
|
||||
{
|
||||
textureURL = key + '.png';
|
||||
}
|
||||
|
||||
if (typeof xmlURL === 'undefined') { xmlURL = null; }
|
||||
if (typeof xmlData === 'undefined') { xmlData = null; }
|
||||
if (typeof xSpacing === 'undefined') { xSpacing = 0; }
|
||||
if (typeof ySpacing === 'undefined') { ySpacing = 0; }
|
||||
|
||||
if (!xmlURL && !xmlData)
|
||||
{
|
||||
xmlURL = key + '.xml';
|
||||
}
|
||||
|
||||
// A URL to a json/xml file has been given
|
||||
if (xmlURL)
|
||||
{
|
||||
|
@ -967,16 +1163,40 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new texture atlas ('textureatlas') to the loader. This atlas uses the JSON Array data format.
|
||||
* Adds a Texture Atlas file to the current load queue.
|
||||
*
|
||||
* Texture Atlases can be created with tools such as [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) and
|
||||
* Unlike `Loader.atlasJSONHash` this call expects the atlas data to be in a JSON Array format.
|
||||
*
|
||||
* To create the Texture Atlas you can use tools such as:
|
||||
*
|
||||
* [Texture Packer](https://www.codeandweb.com/texturepacker/phaser)
|
||||
* [Shoebox](http://renderhjs.net/shoebox/)
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to a json file.
|
||||
* Or you can pass in a JSON object or String via the `atlasData` parameter.
|
||||
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed.
|
||||
*
|
||||
* The URLs can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the textureURL isn't specified then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png".
|
||||
* The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
|
||||
* set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json".
|
||||
*
|
||||
* If you do not desire this action then provide URLs and / or a data object.
|
||||
*
|
||||
* @method Phaser.Loader#atlasJSONArray
|
||||
* @param {string} key - Unique asset key of the texture atlas file.
|
||||
* @param {string} textureURL - The url of the texture atlas image file.
|
||||
* @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
|
||||
* @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
|
||||
* @param {string} [textureURL] - URL of the texture atlas image file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {string} [atlasURL] - URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.json".
|
||||
* @param {object} [atlasData] - A JSON data object. You don't need this if the data is being loaded from a URL.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
atlasJSONArray: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
@ -986,16 +1206,40 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new texture atlas ('textureatlas') to the loader. This atlas uses the JSON Hash data format.
|
||||
* Adds a Texture Atlas file to the current load queue.
|
||||
*
|
||||
* Texture Atlases can be created with tools such as [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) and
|
||||
* Unlike `Loader.atlas` this call expects the atlas data to be in a JSON Hash format.
|
||||
*
|
||||
* To create the Texture Atlas you can use tools such as:
|
||||
*
|
||||
* [Texture Packer](https://www.codeandweb.com/texturepacker/phaser)
|
||||
* [Shoebox](http://renderhjs.net/shoebox/)
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to a json file.
|
||||
* Or you can pass in a JSON object or String via the `atlasData` parameter.
|
||||
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed.
|
||||
*
|
||||
* The URLs can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the textureURL isn't specified then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png".
|
||||
* The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
|
||||
* set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json".
|
||||
*
|
||||
* If you do not desire this action then provide URLs and / or a data object.
|
||||
*
|
||||
* @method Phaser.Loader#atlasJSONHash
|
||||
* @param {string} key - Unique asset key of the texture atlas file.
|
||||
* @param {string} textureURL - The url of the texture atlas image file.
|
||||
* @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
|
||||
* @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
|
||||
* @param {string} [textureURL] - URL of the texture atlas image file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {string} [atlasURL] - URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.json".
|
||||
* @param {object} [atlasData] - A JSON data object. You don't need this if the data is being loaded from a URL.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
atlasJSONHash: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
@ -1005,41 +1249,115 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Add a new texture atlas ('textureatlas') to the loader. This atlas uses the Starling XML data format.
|
||||
* Adds a Texture Atlas file to the current load queue.
|
||||
*
|
||||
* This call expects the atlas data to be in the Starling XML data format.
|
||||
*
|
||||
* To create the Texture Atlas you can use tools such as:
|
||||
*
|
||||
* [Texture Packer](https://www.codeandweb.com/texturepacker/phaser)
|
||||
* [Shoebox](http://renderhjs.net/shoebox/)
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to an xml file.
|
||||
* Or you can pass in an XML object or String via the `atlasData` parameter.
|
||||
* If you pass a String the data is automatically run through `Loader.parseXML` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getImage(key)`. XML files are automatically parsed upon load.
|
||||
* If you need to control when the XML is parsed then use `Loader.text` instead and parse the XML file as needed.
|
||||
*
|
||||
* The URLs can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the textureURL isn't specified then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png".
|
||||
* The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
|
||||
* set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.xml".
|
||||
*
|
||||
* If you do not desire this action then provide URLs and / or a data object.
|
||||
*
|
||||
* @method Phaser.Loader#atlasXML
|
||||
* @param {string} key - Unique asset key of the texture atlas file.
|
||||
* @param {string} textureURL - The url of the texture atlas image file.
|
||||
* @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
|
||||
* @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
|
||||
* @param {string} [textureURL] - URL of the texture atlas image file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {string} [atlasURL] - URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.xml".
|
||||
* @param {object} [atlasData] - An XML data object. You don't need this if the data is being loaded from a URL.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
atlasXML: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
||||
if (typeof atlasURL === 'undefined') { atlasURL = null; }
|
||||
if (typeof atlasData === 'undefined') { atlasData = null; }
|
||||
|
||||
if (!atlasURL && !atlasData)
|
||||
{
|
||||
atlasURL = key + '.xml';
|
||||
}
|
||||
|
||||
return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new texture atlas ('textureatlas') to the loader.
|
||||
* Adds a Texture Atlas file to the current load queue.
|
||||
*
|
||||
* Texture Atlases can be created with tools such as [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) and
|
||||
* To create the Texture Atlas you can use tools such as:
|
||||
*
|
||||
* [Texture Packer](https://www.codeandweb.com/texturepacker/phaser)
|
||||
* [Shoebox](http://renderhjs.net/shoebox/)
|
||||
*
|
||||
* You can choose to either load the data externally, by providing a URL to a json file.
|
||||
* Or you can pass in a JSON object or String via the `atlasData` parameter.
|
||||
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.
|
||||
*
|
||||
* If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue.
|
||||
*
|
||||
* The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.
|
||||
*
|
||||
* Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load.
|
||||
* If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed.
|
||||
*
|
||||
* The URLs can be relative or absolute. If relative it will take the Loader.baseURL into consideration.
|
||||
*
|
||||
* If the textureURL isn't specified then the Loader will take the key and create a filename from that.
|
||||
* For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png".
|
||||
* The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
|
||||
* set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json".
|
||||
*
|
||||
* If you do not desire this action then provide URLs and / or a data object.
|
||||
*
|
||||
* @method Phaser.Loader#atlas
|
||||
* @param {string} key - Unique asset key of the texture atlas file.
|
||||
* @param {string} textureURL - The url of the texture atlas image file.
|
||||
* @param {string} [atlasURL] - The url of the texture atlas data file (json/xml). You don't need this if you are passing an atlasData object instead.
|
||||
* @param {string} [textureURL] - URL of the texture atlas image file. If undefined or `null` the url will be set to `<key>.png`, i.e. if `key` was "bomb" then the URL will be "bomb.png".
|
||||
* @param {string} [atlasURL] - URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `<key>.json`, i.e. if `key` was "bomb" then the URL will be "bomb.json".
|
||||
* @param {object} [atlasData] - A JSON or XML data object. You don't need this if the data is being loaded from a URL.
|
||||
* @param {number} [format] - A value describing the format of the data, the default is Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY.
|
||||
* @param {number} [format] - The format of the data. Can be Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY (the default), Phaser.Loader.TEXTURE_ATLAS_JSON_HASH or Phaser.Loader.TEXTURE_ATLAS_XML_STARLING.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
atlas: function (key, textureURL, atlasURL, atlasData, format) {
|
||||
|
||||
if (typeof textureURL === 'undefined' || textureURL === null)
|
||||
{
|
||||
textureURL = key + '.png';
|
||||
}
|
||||
|
||||
if (typeof atlasURL === 'undefined') { atlasURL = null; }
|
||||
if (typeof atlasData === 'undefined') { atlasData = null; }
|
||||
if (typeof format === 'undefined') { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; }
|
||||
|
||||
if (!atlasURL && !atlasData)
|
||||
{
|
||||
if (format === Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
||||
{
|
||||
atlasURL = key + '.xml';
|
||||
}
|
||||
else
|
||||
{
|
||||
atlasURL = key + '.json';
|
||||
}
|
||||
}
|
||||
|
||||
// A URL to a json/xml file has been given
|
||||
if (atlasURL)
|
||||
{
|
||||
|
@ -1490,13 +1808,25 @@ Phaser.Loader.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Transforms the asset URL. The default implementation prepends the baseURL.
|
||||
* Transforms the asset URL.
|
||||
* The default implementation prepends the baseURL if the url doesn't being with http or //
|
||||
*
|
||||
* @method Phaser.Loader#transformUrl
|
||||
* @protected
|
||||
* @param {string} url - The url to transform
|
||||
* @return {string} The transformed url
|
||||
*/
|
||||
transformUrl: function (url /*, file */) {
|
||||
return this.baseURL + url;
|
||||
transformUrl: function (url) {
|
||||
|
||||
if (url.substr(0, 4) === 'http' || url.substr(0, 2) === '//')
|
||||
{
|
||||
return url;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.baseURL + url;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1541,7 +1871,7 @@ Phaser.Loader.prototype = {
|
|||
}
|
||||
else
|
||||
{
|
||||
this.fileError(file, null, 'no supported audio URL specified');
|
||||
this.fileError(file, null, 'No supported audio URL specified or device does not have audio playback support');
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1844,6 +2174,11 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
getAudioURL: function (urls) {
|
||||
|
||||
if (this.game.sound.noAudio)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < urls.length; i++)
|
||||
{
|
||||
var url = urls[i];
|
||||
|
|
|
@ -57,6 +57,11 @@ Phaser.Physics = function (game, config) {
|
|||
*/
|
||||
this.chipmunk = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.Matter} matter - The MatterJS Physics system (coming soon).
|
||||
*/
|
||||
this.matter = null;
|
||||
|
||||
this.parseConfig();
|
||||
|
||||
};
|
||||
|
@ -91,6 +96,12 @@ Phaser.Physics.BOX2D = 3;
|
|||
*/
|
||||
Phaser.Physics.CHIPMUNK = 4;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Physics.MATTERJS = 5;
|
||||
|
||||
Phaser.Physics.prototype = {
|
||||
|
||||
/**
|
||||
|
@ -104,7 +115,6 @@ Phaser.Physics.prototype = {
|
|||
{
|
||||
// If Arcade isn't specified, we create it automatically if we can
|
||||
this.arcade = new Phaser.Physics.Arcade(this.game);
|
||||
this.game.time.deltaCap = 0.2;
|
||||
}
|
||||
|
||||
if (this.config.hasOwnProperty('ninja') && this.config['ninja'] === true && Phaser.Physics.hasOwnProperty('Ninja'))
|
||||
|
@ -122,6 +132,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d = new Phaser.Physics.BOX2D(this.game, this.config);
|
||||
}
|
||||
|
||||
if (this.config.hasOwnProperty('matter') && this.config['matter'] === true && Phaser.Physics.hasOwnProperty('Matter'))
|
||||
{
|
||||
this.matter = new Phaser.Physics.Matter(this.game, this.config);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -176,6 +191,17 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.reset();
|
||||
}
|
||||
}
|
||||
else if (system === Phaser.Physics.MATTERJS)
|
||||
{
|
||||
if (this.matter === null)
|
||||
{
|
||||
this.matter = new Phaser.Physics.Matter(this.game, this.config);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.matter.reset();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
@ -188,6 +214,7 @@ Phaser.Physics.prototype = {
|
|||
* Phaser.Physics.P2JS - A full-body advanced physics system supporting multiple object shapes, polygon loading, contact materials, springs and constraints.
|
||||
* Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. Advanced AABB and Circle vs. Tile collision.
|
||||
* Phaser.Physics.BOX2D - A port of https://code.google.com/p/box2d-html5
|
||||
* Phaser.Physics.MATTER - A full-body and light-weight advanced physics system (still in development)
|
||||
* Phaser.Physics.CHIPMUNK is still in development.
|
||||
*
|
||||
* If you require more control over what type of body is created, for example to create a Ninja Physics Circle instead of the default AABB, then see the
|
||||
|
@ -219,6 +246,10 @@ Phaser.Physics.prototype = {
|
|||
{
|
||||
this.box2d.enable(object);
|
||||
}
|
||||
else if (system === Phaser.Physics.MATTERJS && this.matter)
|
||||
{
|
||||
this.matter.enable(object);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
@ -242,6 +273,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.preUpdate();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.preUpdate();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -264,6 +300,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.update();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.update();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -294,6 +335,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.setBoundsToWorld();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.setBoundsToWorld();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -314,6 +360,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.clear();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.clear();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -334,6 +385,11 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.reset();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.reset();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -353,10 +409,16 @@ Phaser.Physics.prototype = {
|
|||
this.box2d.destroy();
|
||||
}
|
||||
|
||||
if (this.matter)
|
||||
{
|
||||
this.matter.destroy();
|
||||
}
|
||||
|
||||
this.arcade = null;
|
||||
this.ninja = null;
|
||||
this.p2 = null;
|
||||
this.box2d = null;
|
||||
this.matter = null;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -546,6 +546,11 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
*/
|
||||
destroy: function () {
|
||||
|
||||
if (this.sprite.parent && this.sprite.parent instanceof Phaser.Group)
|
||||
{
|
||||
this.sprite.parent.removeFromHash(this.sprite);
|
||||
}
|
||||
|
||||
this.sprite.body = null;
|
||||
this.sprite = null;
|
||||
|
||||
|
|
|
@ -215,8 +215,11 @@ Phaser.Physics.Arcade.prototype = {
|
|||
|
||||
/**
|
||||
* Creates an Arcade Physics body on the given game object.
|
||||
*
|
||||
* A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled.
|
||||
*
|
||||
* When you add an Arcade Physics body to an object it will automatically add the object into its parent Groups hash array.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#enableBody
|
||||
* @param {object} object - The game object to create the physics body on. A body will only be created if this object has a null `body` property.
|
||||
*/
|
||||
|
@ -225,6 +228,11 @@ Phaser.Physics.Arcade.prototype = {
|
|||
if (object.hasOwnProperty('body') && object.body === null)
|
||||
{
|
||||
object.body = new Phaser.Physics.Arcade.Body(object);
|
||||
|
||||
if (object.parent && object.parent instanceof Phaser.Group)
|
||||
{
|
||||
object.parent.addToHash(object);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -278,7 +286,6 @@ Phaser.Physics.Arcade.prototype = {
|
|||
}
|
||||
else if (drag)
|
||||
{
|
||||
// var _drag = drag * this.game.time.physicsElapsed;
|
||||
drag *= this.game.time.physicsElapsed;
|
||||
|
||||
if (velocity - drag > 0)
|
||||
|
@ -425,71 +432,132 @@ Phaser.Physics.Arcade.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* This method will sort a Groups _hash array based on the sortDirection property.
|
||||
* A Sort function for sorting two bodies based on a LEFT to RIGHT sort direction.
|
||||
*
|
||||
* Each function should return -1 if `a > b`, 1 if `a < b` or 0 if `a === b`.
|
||||
* This is called automatically by World.sort
|
||||
*
|
||||
* @method sortLeftRight
|
||||
* @param {Phaser.Sprite} a - The first Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @param {Phaser.Sprite} b - The second Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @return {integer} A negative value if `a > b`, a positive value if `a < b` or 0 if `a === b` or the bodies are invalid.
|
||||
*/
|
||||
sortLeftRight: function (a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return a.body.x - b.body.x;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A Sort function for sorting two bodies based on a RIGHT to LEFT sort direction.
|
||||
*
|
||||
* This is called automatically by World.sort
|
||||
*
|
||||
* @method sortRightLeft
|
||||
* @param {Phaser.Sprite} a - The first Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @param {Phaser.Sprite} b - The second Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @return {integer} A negative value if `a > b`, a positive value if `a < b` or 0 if `a === b` or the bodies are invalid.
|
||||
*/
|
||||
sortRightLeft: function (a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return b.body.x - a.body.x;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A Sort function for sorting two bodies based on a TOP to BOTTOM sort direction.
|
||||
*
|
||||
* This is called automatically by World.sort
|
||||
*
|
||||
* @method sortTopBottom
|
||||
* @param {Phaser.Sprite} a - The first Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @param {Phaser.Sprite} b - The second Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @return {integer} A negative value if `a > b`, a positive value if `a < b` or 0 if `a === b` or the bodies are invalid.
|
||||
*/
|
||||
sortTopBottom: function (a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return a.body.y - b.body.y;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* A Sort function for sorting two bodies based on a BOTTOM to TOP sort direction.
|
||||
*
|
||||
* This is called automatically by World.sort
|
||||
*
|
||||
* @method sortBottomTop
|
||||
* @param {Phaser.Sprite} a - The first Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @param {Phaser.Sprite} b - The second Sprite to test. The Sprite must have an Arcade Physics Body.
|
||||
* @return {integer} A negative value if `a > b`, a positive value if `a < b` or 0 if `a === b` or the bodies are invalid.
|
||||
*/
|
||||
sortBottomTop: function (a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return b.body.y - a.body.y;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This method will sort a Groups hash array.
|
||||
*
|
||||
* If the Group has `physicsSortDirection` set it will use the sort direction defined.
|
||||
*
|
||||
* Otherwise if the sortDirection parameter is undefined, or Group.physicsSortDirection is null, it will use Phaser.Physics.Arcade.sortDirection.
|
||||
*
|
||||
* By changing Group.physicsSortDirection you can customise each Group to sort in a different order.
|
||||
*
|
||||
* @method sort
|
||||
* @protected
|
||||
* @param {Phaser.Group} group - The Group to sort.
|
||||
* @param {integer} [sortDirection] - The sort direction used to sort this Group.
|
||||
*/
|
||||
sort: function (group) {
|
||||
sort: function (group, sortDirection) {
|
||||
|
||||
if (this.sortDirection === Phaser.Physics.Arcade.LEFT_RIGHT)
|
||||
if (group.physicsSortDirection !== null)
|
||||
{
|
||||
sortDirection = group.physicsSortDirection;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (typeof sortDirection === 'undefined') { sortDirection = this.sortDirection; }
|
||||
}
|
||||
|
||||
if (sortDirection === Phaser.Physics.Arcade.LEFT_RIGHT)
|
||||
{
|
||||
// Game world is say 2000x600 and you start at 0
|
||||
group._hash.sort(function(a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return a.body.x - b.body.x;
|
||||
|
||||
});
|
||||
group.hash.sort(this.sortLeftRight);
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.RIGHT_LEFT)
|
||||
else if (sortDirection === Phaser.Physics.Arcade.RIGHT_LEFT)
|
||||
{
|
||||
// Game world is say 2000x600 and you start at 2000
|
||||
group._hash.sort(function(a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return b.body.x - a.body.x;
|
||||
|
||||
});
|
||||
group.hash.sort(this.sortRightLeft);
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.TOP_BOTTOM)
|
||||
else if (sortDirection === Phaser.Physics.Arcade.TOP_BOTTOM)
|
||||
{
|
||||
// Game world is say 800x2000 and you start at 0
|
||||
group._hash.sort(function(a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return a.body.y - b.body.y;
|
||||
|
||||
});
|
||||
group.hash.sort(this.sortTopBottom);
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.BOTTOM_TOP)
|
||||
else if (sortDirection === Phaser.Physics.Arcade.BOTTOM_TOP)
|
||||
{
|
||||
// Game world is say 800x2000 and you start at 2000
|
||||
group._hash.sort(function(a, b) {
|
||||
|
||||
if (!a.body || !b.body)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return b.body.y - a.body.y;
|
||||
|
||||
});
|
||||
group.hash.sort(this.sortBottomTop);
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -636,63 +704,67 @@ Phaser.Physics.Arcade.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
var body;
|
||||
|
||||
if (this.skipQuadTree || sprite.body.skipQuadTree)
|
||||
{
|
||||
for (var i = 0; i < group._hash.length; i++)
|
||||
for (var i = 0; i < group.hash.length; i++)
|
||||
{
|
||||
// Skip duff entries - we can't check a non-existent sprite or one with no body
|
||||
if (!group._hash[i] || !group._hash[i].exists || !group._hash[i].body)
|
||||
if (!group.hash[i] || !group.hash[i].exists || !group.hash[i].body)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
body = group.hash[i].body;
|
||||
|
||||
// Skip items either side of the sprite
|
||||
if (this.sortDirection === Phaser.Physics.Arcade.LEFT_RIGHT)
|
||||
{
|
||||
if (sprite.body.right < group._hash[i].body.x)
|
||||
if (sprite.body.right < body.x)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (group._hash[i].body.right < sprite.body.x)
|
||||
else if (body.right < sprite.body.x)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.RIGHT_LEFT)
|
||||
{
|
||||
if (sprite.body.x > group._hash[i].body.right)
|
||||
if (sprite.body.x > body.right)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (group._hash[i].body.x > sprite.body.right)
|
||||
else if (body.x > sprite.body.right)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.TOP_BOTTOM)
|
||||
{
|
||||
if (sprite.body.bottom < group._hash[i].body.y)
|
||||
if (sprite.body.bottom < body.y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (group._hash[i].body.bottom < sprite.body.y)
|
||||
else if (body.bottom < sprite.body.y)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (this.sortDirection === Phaser.Physics.Arcade.BOTTOM_TOP)
|
||||
{
|
||||
if (sprite.body.y > group._hash[i].body.bottom)
|
||||
if (sprite.body.y > body.bottom)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (group._hash[i].body.y > sprite.body.bottom)
|
||||
else if (body.y > sprite.body.bottom)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
this.collideSpriteVsSprite(sprite, group._hash[i], collideCallback, processCallback, callbackContext, overlapOnly);
|
||||
this.collideSpriteVsSprite(sprite, group.hash[i], collideCallback, processCallback, callbackContext, overlapOnly);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -742,25 +814,25 @@ Phaser.Physics.Arcade.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < group._hash.length; i++)
|
||||
for (var i = 0; i < group.hash.length; i++)
|
||||
{
|
||||
// Skip duff entries - we can't check a non-existent sprite or one with no body
|
||||
if (!group._hash[i] || !group._hash[i].exists || !group._hash[i].body)
|
||||
if (!group.hash[i] || !group.hash[i].exists || !group.hash[i].body)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var object1 = group._hash[i];
|
||||
var object1 = group.hash[i];
|
||||
|
||||
for (var j = i + 1; j < group._hash.length; j++)
|
||||
for (var j = i + 1; j < group.hash.length; j++)
|
||||
{
|
||||
// Skip duff entries - we can't check a non-existent sprite or one with no body
|
||||
if (!group._hash[j] || !group._hash[j].exists || !group._hash[j].body)
|
||||
if (!group.hash[j] || !group.hash[j].exists || !group.hash[j].body)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var object2 = group._hash[j];
|
||||
var object2 = group.hash[j];
|
||||
|
||||
// Skip items either side of the sprite
|
||||
if (this.sortDirection === Phaser.Physics.Arcade.LEFT_RIGHT)
|
||||
|
|
|
@ -797,8 +797,11 @@ Phaser.Physics.P2.Body.prototype = {
|
|||
}
|
||||
|
||||
this.debugBody = null;
|
||||
this.sprite.body = null;
|
||||
this.sprite = null;
|
||||
|
||||
if (this.sprite) {
|
||||
this.sprite.body = null;
|
||||
this.sprite = null;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -1296,6 +1296,8 @@ Phaser.Physics.P2.prototype = {
|
|||
|
||||
/**
|
||||
* Populates and returns an array of all current Constraints in the world.
|
||||
* You will get an array of p2 constraints back. This can be of mixed types, for example the array may contain
|
||||
* PrismaticConstraints, RevoluteConstraints or any other valid p2 constraint type.
|
||||
*
|
||||
* @method Phaser.Physics.P2#getConstraints
|
||||
* @return {array<Phaser.Physics.P2.Constraint>} An array containing all current Constraints in the world.
|
||||
|
@ -1307,7 +1309,7 @@ Phaser.Physics.P2.prototype = {
|
|||
|
||||
while (i--)
|
||||
{
|
||||
output.push(this.world.constraints[i].parent);
|
||||
output.push(this.world.constraints[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
|
2047
src/physics/p2/p2.js
2047
src/physics/p2/p2.js
File diff suppressed because it is too large
Load diff
|
@ -364,20 +364,37 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
|
|||
});
|
||||
|
||||
/*
|
||||
* Updates the object transform for rendering
|
||||
* Updates the object transform for rendering.
|
||||
*
|
||||
* If the object has no parent, and no parent parameter is provided, it will default to Phaser.Game.World as the parent.
|
||||
* If that is unavailable the transform fails to take place.
|
||||
*
|
||||
* The `parent` parameter has priority over the actual parent. Use it as a parent override.
|
||||
* Setting it does **not** change the actual parent of this DisplayObject, it just uses the parent for the transform update.
|
||||
*
|
||||
* @method updateTransform
|
||||
* @private
|
||||
* @param {DisplayObject} [parent] - Optional parent to parent this DisplayObject transform from.
|
||||
*/
|
||||
PIXI.DisplayObject.prototype.updateTransform = function()
|
||||
PIXI.DisplayObject.prototype.updateTransform = function(parent)
|
||||
{
|
||||
if (!this.parent)
|
||||
if (!parent && !this.parent && !this.game)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var p = this.parent;
|
||||
|
||||
if (parent)
|
||||
{
|
||||
p = parent;
|
||||
}
|
||||
else if (!this.parent)
|
||||
{
|
||||
p = this.game.world;
|
||||
}
|
||||
|
||||
// create some matrix refs for easy access
|
||||
var pt = this.parent.worldTransform;
|
||||
var pt = p.worldTransform;
|
||||
var wt = this.worldTransform;
|
||||
|
||||
// temporary matrix variables
|
||||
|
@ -435,7 +452,7 @@ PIXI.DisplayObject.prototype.updateTransform = function()
|
|||
}
|
||||
|
||||
// multiply the alphas..
|
||||
this.worldAlpha = this.alpha * this.parent.worldAlpha;
|
||||
this.worldAlpha = this.alpha * p.worldAlpha;
|
||||
|
||||
// Custom callback?
|
||||
if (this.transformCallback)
|
||||
|
|
|
@ -45,7 +45,7 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
|||
|
||||
var width = this.getLocalBounds().width;
|
||||
|
||||
if(width !== 0)
|
||||
if (width !== 0)
|
||||
{
|
||||
this.scale.x = value / width;
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
|||
this.scale.x = 1;
|
||||
}
|
||||
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
@ -77,7 +76,7 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
|||
|
||||
if (height !== 0)
|
||||
{
|
||||
this.scale.y = value / height ;
|
||||
this.scale.y = value / height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -284,15 +283,19 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
||||
{
|
||||
if(!this.visible)return;
|
||||
if (!this.visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.displayObjectUpdateTransform();
|
||||
|
||||
//PIXI.DisplayObject.prototype.updateTransform.call( this );
|
||||
if (this._cacheAsBitmap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(this._cacheAsBitmap)return;
|
||||
|
||||
for(var i=0,j=this.children.length; i<j; i++)
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
|
|
@ -260,16 +260,23 @@ PIXI.Sprite.prototype.getBounds = function(matrix)
|
|||
*
|
||||
* @method _renderWebGL
|
||||
* @param renderSession {RenderSession}
|
||||
* @param {Matrix} [matrix] - Optional matrix. If provided the Display Object will be rendered using this matrix, otherwise it will use its worldTransform.
|
||||
* @private
|
||||
*/
|
||||
PIXI.Sprite.prototype._renderWebGL = function(renderSession)
|
||||
PIXI.Sprite.prototype._renderWebGL = function(renderSession, matrix)
|
||||
{
|
||||
// if the sprite is not visible or the alpha is 0 then no need to render this element
|
||||
if (!this.visible || this.alpha <= 0 || !this.renderable) return;
|
||||
|
||||
var i, j;
|
||||
// They provided an alternative rendering matrix, so use it
|
||||
var wt = this.worldTransform;
|
||||
|
||||
// do a quick check to see if this element has a mask or a filter.
|
||||
if (matrix)
|
||||
{
|
||||
wt = matrix;
|
||||
}
|
||||
|
||||
// A quick check to see if this element has a mask or a filter.
|
||||
if (this._mask || this._filters)
|
||||
{
|
||||
var spriteBatch = renderSession.spriteBatch;
|
||||
|
@ -292,7 +299,7 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
|
|||
spriteBatch.render(this);
|
||||
|
||||
// now loop through the children and make sure they get rendered
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i]._renderWebGL(renderSession);
|
||||
}
|
||||
|
@ -307,12 +314,12 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
|
|||
}
|
||||
else
|
||||
{
|
||||
renderSession.spriteBatch.render(this);
|
||||
renderSession.spriteBatch.render(this, wt);
|
||||
|
||||
// simple render children!
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
// Render children!
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i]._renderWebGL(renderSession);
|
||||
this.children[i]._renderWebGL(renderSession, wt);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -323,13 +330,22 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
|
|||
*
|
||||
* @method _renderCanvas
|
||||
* @param renderSession {RenderSession}
|
||||
* @param {Matrix} [matrix] - Optional matrix. If provided the Display Object will be rendered using this matrix, otherwise it will use its worldTransform.
|
||||
* @private
|
||||
*/
|
||||
PIXI.Sprite.prototype._renderCanvas = function(renderSession)
|
||||
PIXI.Sprite.prototype._renderCanvas = function(renderSession, matrix)
|
||||
{
|
||||
// If the sprite is not visible or the alpha is 0 then no need to render this element
|
||||
if (this.visible === false || this.alpha === 0 || this.renderable === false || this.texture.crop.width <= 0 || this.texture.crop.height <= 0) return;
|
||||
|
||||
// They provided an alternative rendering matrix, so use it
|
||||
var wt = this.worldTransform;
|
||||
|
||||
if (matrix)
|
||||
{
|
||||
wt = matrix;
|
||||
}
|
||||
|
||||
if (this.blendMode !== renderSession.currentBlendMode)
|
||||
{
|
||||
renderSession.currentBlendMode = this.blendMode;
|
||||
|
@ -362,25 +378,13 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
|
|||
// Allow for pixel rounding
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
renderSession.context.setTransform(
|
||||
this.worldTransform.a,
|
||||
this.worldTransform.b,
|
||||
this.worldTransform.c,
|
||||
this.worldTransform.d,
|
||||
(this.worldTransform.tx * renderSession.resolution) | 0,
|
||||
(this.worldTransform.ty * renderSession.resolution) | 0);
|
||||
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, (wt.tx * renderSession.resolution) | 0, (wt.ty * renderSession.resolution) | 0);
|
||||
dx = dx | 0;
|
||||
dy = dy | 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderSession.context.setTransform(
|
||||
this.worldTransform.a,
|
||||
this.worldTransform.b,
|
||||
this.worldTransform.c,
|
||||
this.worldTransform.d,
|
||||
this.worldTransform.tx * renderSession.resolution,
|
||||
this.worldTransform.ty * renderSession.resolution);
|
||||
renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, wt.tx * renderSession.resolution, wt.ty * renderSession.resolution);
|
||||
}
|
||||
|
||||
if (this.tint !== 0xFFFFFF)
|
||||
|
@ -417,7 +421,6 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
|
|||
}
|
||||
}
|
||||
|
||||
// OVERWRITE
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i]._renderCanvas(renderSession);
|
||||
|
|
|
@ -22,7 +22,7 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
this._width = width || 100;
|
||||
this._width = width || 128;
|
||||
|
||||
/**
|
||||
* The height of the tiling sprite
|
||||
|
@ -30,7 +30,7 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
this._height = height || 100;
|
||||
this._height = height || 128;
|
||||
|
||||
/**
|
||||
* The scaling of the image that is being tiled
|
||||
|
@ -38,7 +38,7 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
* @property tileScale
|
||||
* @type Point
|
||||
*/
|
||||
this.tileScale = new PIXI.Point(1,1);
|
||||
this.tileScale = new PIXI.Point(1, 1);
|
||||
|
||||
/**
|
||||
* A point that represents the scale of the texture object
|
||||
|
@ -46,7 +46,7 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
* @property tileScaleOffset
|
||||
* @type Point
|
||||
*/
|
||||
this.tileScaleOffset = new PIXI.Point(1,1);
|
||||
this.tileScaleOffset = new PIXI.Point(1, 1);
|
||||
|
||||
/**
|
||||
* The offset position of the image that is being tiled
|
||||
|
@ -54,7 +54,7 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
* @property tilePosition
|
||||
* @type Point
|
||||
*/
|
||||
this.tilePosition = new PIXI.Point(0,0);
|
||||
this.tilePosition = new PIXI.Point();
|
||||
|
||||
/**
|
||||
* Whether this sprite is renderable or not
|
||||
|
@ -83,55 +83,57 @@ PIXI.TilingSprite = function(texture, width, height)
|
|||
*/
|
||||
this.blendMode = PIXI.blendModes.NORMAL;
|
||||
|
||||
/**
|
||||
* The CanvasBuffer object that the tiled texture is drawn to.
|
||||
*
|
||||
* @property canvasBuffer
|
||||
* @type PIXI.CanvasBuffer
|
||||
*/
|
||||
this.canvasBuffer = null;
|
||||
|
||||
/**
|
||||
* An internal Texture object that holds the tiling texture that was generated from TilingSprite.texture.
|
||||
*
|
||||
* @property tilingTexture
|
||||
* @type PIXI.Texture
|
||||
*/
|
||||
this.tilingTexture = null;
|
||||
|
||||
/**
|
||||
* The Context fill pattern that is used to draw the TilingSprite in Canvas mode only (will be null in WebGL).
|
||||
*
|
||||
* @property tilePattern
|
||||
* @type PIXI.Texture
|
||||
*/
|
||||
this.tilePattern = null;
|
||||
|
||||
/**
|
||||
* If true the TilingSprite will run generateTexture on its **next** render pass.
|
||||
* This is set by the likes of Phaser.LoadTexture.setFrame.
|
||||
*
|
||||
* @property refreshTexture
|
||||
* @type Boolean
|
||||
* @default true
|
||||
*/
|
||||
this.refreshTexture = true;
|
||||
|
||||
this.frameWidth = 0;
|
||||
this.frameHeight = 0;
|
||||
|
||||
};
|
||||
|
||||
// constructor
|
||||
PIXI.TilingSprite.prototype = Object.create(PIXI.Sprite.prototype);
|
||||
PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite;
|
||||
|
||||
|
||||
/**
|
||||
* The width of the sprite, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.TilingSprite.prototype, 'width', {
|
||||
get: function() {
|
||||
return this._width;
|
||||
},
|
||||
set: function(value) {
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the TilingSprite, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.TilingSprite.prototype, 'height', {
|
||||
get: function() {
|
||||
return this._height;
|
||||
},
|
||||
set: function(value) {
|
||||
this._height = value;
|
||||
}
|
||||
});
|
||||
|
||||
PIXI.TilingSprite.prototype.setTexture = function(texture)
|
||||
{
|
||||
if (this.texture === texture) return;
|
||||
if (this.texture !== texture)
|
||||
{
|
||||
this.texture = texture;
|
||||
this.refreshTexture = true;
|
||||
this.cachedTint = 0xFFFFFF;
|
||||
}
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
this.refreshTexture = true;
|
||||
|
||||
this.cachedTint = 0xFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -143,8 +145,10 @@ PIXI.TilingSprite.prototype.setTexture = function(texture)
|
|||
*/
|
||||
PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
||||
{
|
||||
if (this.visible === false || this.alpha === 0) return;
|
||||
var i,j;
|
||||
if (this.visible === false || this.alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._mask)
|
||||
{
|
||||
|
@ -159,32 +163,42 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
renderSession.filterManager.pushFilter(this._filterBlock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!this.tilingTexture || this.refreshTexture)
|
||||
if (this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
|
||||
if (this.tilingTexture && this.tilingTexture.needsUpdate)
|
||||
if (this.tilingTexture)
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.tilingTexture.baseTexture);
|
||||
this.tilingTexture.needsUpdate = false;
|
||||
if (this.tilingTexture.needsUpdate)
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.tilingTexture.baseTexture);
|
||||
this.tilingTexture.needsUpdate = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderSession.spriteBatch.renderTilingSprite(this);
|
||||
}
|
||||
// simple render children!
|
||||
for (i=0,j=this.children.length; i<j; i++)
|
||||
|
||||
renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i]._renderWebGL(renderSession);
|
||||
}
|
||||
|
||||
renderSession.spriteBatch.stop();
|
||||
|
||||
if (this._filters) renderSession.filterManager.popFilter();
|
||||
if (this._mask) renderSession.maskManager.popMask(this._mask, renderSession);
|
||||
if (this._filters)
|
||||
{
|
||||
renderSession.filterManager.popFilter();
|
||||
}
|
||||
|
||||
if (this._mask)
|
||||
{
|
||||
renderSession.maskManager.popMask(this._mask, renderSession);
|
||||
}
|
||||
|
||||
renderSession.spriteBatch.start();
|
||||
};
|
||||
|
@ -198,7 +212,10 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
*/
|
||||
PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
||||
{
|
||||
if (this.visible === false || this.alpha === 0)return;
|
||||
if (this.visible === false || this.alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var context = renderSession.context;
|
||||
|
||||
|
@ -209,26 +226,23 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
|
||||
context.globalAlpha = this.worldAlpha;
|
||||
|
||||
var transform = this.worldTransform;
|
||||
|
||||
var i,j;
|
||||
|
||||
var wt = this.worldTransform;
|
||||
var resolution = renderSession.resolution;
|
||||
|
||||
context.setTransform(transform.a * resolution,
|
||||
transform.b * resolution,
|
||||
transform.c * resolution,
|
||||
transform.d * resolution,
|
||||
transform.tx * resolution,
|
||||
transform.ty * resolution);
|
||||
context.setTransform(wt.a * resolution,
|
||||
wt.b * resolution,
|
||||
wt.c * resolution,
|
||||
wt.d * resolution,
|
||||
wt.tx * resolution,
|
||||
wt.ty * resolution);
|
||||
|
||||
if (!this.__tilePattern || this.refreshTexture)
|
||||
if (this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(false);
|
||||
|
||||
if (this.tilingTexture)
|
||||
{
|
||||
this.__tilePattern = context.createPattern(this.tilingTexture.baseTexture.source, 'repeat');
|
||||
this.tilePattern = context.createPattern(this.tilingTexture.baseTexture.source, 'repeat');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -236,7 +250,9 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
}
|
||||
}
|
||||
|
||||
// check blend mode
|
||||
var sessionBlendMode = renderSession.currentBlendMode;
|
||||
|
||||
// Check blend mode
|
||||
if (this.blendMode !== renderSession.currentBlendMode)
|
||||
{
|
||||
renderSession.currentBlendMode = this.blendMode;
|
||||
|
@ -249,17 +265,29 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
tilePosition.x %= this.tilingTexture.baseTexture.width;
|
||||
tilePosition.y %= this.tilingTexture.baseTexture.height;
|
||||
|
||||
// offset - make sure to account for the anchor point..
|
||||
context.scale(tileScale.x,tileScale.y);
|
||||
// Translate
|
||||
context.scale(tileScale.x, tileScale.y);
|
||||
context.translate(tilePosition.x + (this.anchor.x * -this._width), tilePosition.y + (this.anchor.y * -this._height));
|
||||
|
||||
context.fillStyle = this.__tilePattern;
|
||||
context.fillStyle = this.tilePattern;
|
||||
|
||||
context.fillRect(-tilePosition.x,
|
||||
-tilePosition.y,
|
||||
this._width / tileScale.x,
|
||||
this._height / tileScale.y);
|
||||
var tx = -tilePosition.x;
|
||||
var ty = -tilePosition.y;
|
||||
var tw = this._width / tileScale.x;
|
||||
var th = this._height / tileScale.y;
|
||||
|
||||
// Allow for pixel rounding
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
tx | 0;
|
||||
ty | 0;
|
||||
tw | 0;
|
||||
th | 0;
|
||||
}
|
||||
|
||||
context.fillRect(tx, ty, tw, th);
|
||||
|
||||
// Translate back again
|
||||
context.scale(1 / tileScale.x, 1 / tileScale.y);
|
||||
context.translate(-tilePosition.x + (this.anchor.x * this._width), -tilePosition.y + (this.anchor.y * this._height));
|
||||
|
||||
|
@ -268,12 +296,103 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
|||
renderSession.maskManager.popMask(renderSession);
|
||||
}
|
||||
|
||||
for (i=0,j=this.children.length; i<j; i++)
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i]._renderCanvas(renderSession);
|
||||
}
|
||||
|
||||
// Reset blend mode
|
||||
if (sessionBlendMode !== this.blendMode)
|
||||
{
|
||||
renderSession.currentBlendMode = sessionBlendMode;
|
||||
context.globalCompositeOperation = PIXI.blendModesCanvas[sessionBlendMode];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* When the texture is updated, this event will fire to update the scale and frame
|
||||
*
|
||||
* @method onTextureUpdate
|
||||
* @param event
|
||||
* @private
|
||||
*/
|
||||
PIXI.TilingSprite.prototype.onTextureUpdate = function()
|
||||
{
|
||||
// overriding the sprite version of this!
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method generateTilingTexture
|
||||
*
|
||||
* @param forcePowerOfTwo {Boolean} Whether we want to force the texture to be a power of two
|
||||
*/
|
||||
PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
||||
{
|
||||
if (!this.texture.baseTexture.hasLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var texture = this.texture;
|
||||
var frame = texture.frame;
|
||||
|
||||
var targetWidth = this._frame.sourceSizeW;
|
||||
var targetHeight = this._frame.sourceSizeH;
|
||||
|
||||
var dx = 0;
|
||||
var dy = 0;
|
||||
|
||||
if (this._frame.trimmed)
|
||||
{
|
||||
dx = this._frame.spriteSourceSizeX;
|
||||
dy = this._frame.spriteSourceSizeY;
|
||||
}
|
||||
|
||||
if (forcePowerOfTwo)
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(targetWidth);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(targetHeight);
|
||||
}
|
||||
|
||||
if (this.canvasBuffer)
|
||||
{
|
||||
this.canvasBuffer.resize(targetWidth, targetHeight);
|
||||
this.tilingTexture.baseTexture.width = targetWidth;
|
||||
this.tilingTexture.baseTexture.height = targetHeight;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(this.canvasBuffer.canvas);
|
||||
this.tilingTexture.isTiling = true;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
|
||||
// Debug
|
||||
this.canvasBuffer.context.strokeStyle = 'rgb(0,255,0)';
|
||||
this.canvasBuffer.context.strokeRect(0, 0, targetWidth, targetHeight);
|
||||
|
||||
this.canvasBuffer.context.drawImage(texture.baseTexture.source,
|
||||
texture.crop.x,
|
||||
texture.crop.y,
|
||||
texture.crop.width,
|
||||
texture.crop.height,
|
||||
dx,
|
||||
dy,
|
||||
texture.crop.width,
|
||||
texture.crop.height);
|
||||
|
||||
this.tileScaleOffset.x = frame.width / targetWidth;
|
||||
this.tileScaleOffset.y = frame.height / targetHeight;
|
||||
|
||||
this.refreshTexture = false;
|
||||
|
||||
this.tilingTexture.baseTexture._powerOf2 = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the framing rectangle of the sprite as a PIXI.Rectangle object
|
||||
|
@ -353,133 +472,6 @@ PIXI.TilingSprite.prototype.getBounds = function()
|
|||
return bounds;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* When the texture is updated, this event will fire to update the scale and frame
|
||||
*
|
||||
* @method onTextureUpdate
|
||||
* @param event
|
||||
* @private
|
||||
*/
|
||||
PIXI.TilingSprite.prototype.onTextureUpdate = function()
|
||||
{
|
||||
// overriding the sprite version of this!
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @method generateTilingTexture
|
||||
*
|
||||
* @param forcePowerOfTwo {Boolean} Whether we want to force the texture to be a power of two
|
||||
*/
|
||||
PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
||||
{
|
||||
if (!this.texture.baseTexture.hasLoaded) return;
|
||||
|
||||
var texture = this.originalTexture || this.texture;
|
||||
var frame = texture.frame;
|
||||
var targetWidth, targetHeight;
|
||||
|
||||
// Check that the frame is the same size as the base texture.
|
||||
var isFrame = frame.width !== texture.baseTexture.width || frame.height !== texture.baseTexture.height;
|
||||
|
||||
var newTextureRequired = false;
|
||||
|
||||
if (!forcePowerOfTwo)
|
||||
{
|
||||
if (isFrame)
|
||||
{
|
||||
if (texture.crop)
|
||||
{
|
||||
targetWidth = texture.crop.width;
|
||||
targetHeight = texture.crop.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = frame.width;
|
||||
targetHeight = frame.height;
|
||||
}
|
||||
|
||||
newTextureRequired = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (texture.crop)
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(texture.crop.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(texture.crop.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(frame.height);
|
||||
}
|
||||
newTextureRequired = true;
|
||||
|
||||
// If the BaseTexture dimensions don't match the texture frame then we need a new texture anyway because it's part of a texture atlas
|
||||
// if (frame.width !== targetWidth || frame.height !== targetHeight || texture.baseTexture.width !== targetWidth || texture.baseTexture.height || targetHeight) newTextureRequired = true;
|
||||
}
|
||||
|
||||
if (newTextureRequired)
|
||||
{
|
||||
var canvasBuffer;
|
||||
|
||||
if (this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
canvasBuffer = this.tilingTexture.canvasBuffer;
|
||||
canvasBuffer.resize(targetWidth, targetHeight);
|
||||
this.tilingTexture.baseTexture.width = targetWidth;
|
||||
this.tilingTexture.baseTexture.height = targetHeight;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
this.tilingTexture.canvasBuffer = canvasBuffer;
|
||||
this.tilingTexture.isTiling = true;
|
||||
}
|
||||
|
||||
canvasBuffer.context.drawImage(texture.baseTexture.source,
|
||||
texture.crop.x,
|
||||
texture.crop.y,
|
||||
texture.crop.width,
|
||||
texture.crop.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tileScaleOffset.x = frame.width / targetWidth;
|
||||
this.tileScaleOffset.y = frame.height / targetHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO - switching?
|
||||
if (this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
// destroy the tiling texture!
|
||||
// TODO could store this somewhere?
|
||||
this.tilingTexture.destroy(true);
|
||||
}
|
||||
|
||||
this.tileScaleOffset.x = 1;
|
||||
this.tileScaleOffset.y = 1;
|
||||
this.tilingTexture = texture;
|
||||
}
|
||||
|
||||
this.refreshTexture = false;
|
||||
|
||||
this.originalTexture = this.texture;
|
||||
this.texture = this.tilingTexture;
|
||||
|
||||
this.tilingTexture.baseTexture._powerOf2 = true;
|
||||
};
|
||||
|
||||
PIXI.TilingSprite.prototype.destroy = function () {
|
||||
|
||||
PIXI.Sprite.prototype.destroy.call(this);
|
||||
|
@ -495,3 +487,39 @@ PIXI.TilingSprite.prototype.destroy = function () {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The width of the sprite, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.TilingSprite.prototype, 'width', {
|
||||
|
||||
get: function() {
|
||||
return this._width;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this._width = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the TilingSprite, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.TilingSprite.prototype, 'height', {
|
||||
|
||||
get: function() {
|
||||
return this._height;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this._height = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -583,11 +583,16 @@ PIXI.Graphics.prototype.drawEllipse = function(x, y, width, height)
|
|||
* Draws a polygon using the given path.
|
||||
*
|
||||
* @method drawPolygon
|
||||
* @param path {Array} The path data used to construct the polygon. If you've got a Phaser.Polygon object then pass `polygon.points` here.
|
||||
* @param path {Array|Phaser.Polygon} The path data used to construct the polygon. Can either be an array of points or a Phaser.Polygon object.
|
||||
* @return {Graphics}
|
||||
*/
|
||||
PIXI.Graphics.prototype.drawPolygon = function(path)
|
||||
{
|
||||
if (path instanceof Phaser.Polygon || path instanceof PIXI.Polygon)
|
||||
{
|
||||
path = path.points;
|
||||
}
|
||||
|
||||
// prevents an argument assignment deopt
|
||||
// see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
|
||||
var points = path;
|
||||
|
@ -744,10 +749,8 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession)
|
|||
*/
|
||||
PIXI.Graphics.prototype._renderCanvas = function(renderSession)
|
||||
{
|
||||
if (this.isMask === true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// if the sprite is not visible or the alpha is 0 then no need to render this element
|
||||
if (this.visible === false || this.alpha === 0 || this.isMask === true) return;
|
||||
|
||||
// if the tint has changed, set the graphics object to dirty.
|
||||
if (this._prevTint !== this.tint) {
|
||||
|
|
|
@ -269,13 +269,14 @@ PIXI.CanvasRenderer.prototype.resize = function(width, height)
|
|||
* @method renderDisplayObject
|
||||
* @param displayObject {DisplayObject} The displayObject to render
|
||||
* @param context {CanvasRenderingContext2D} the context 2d method of the canvas
|
||||
* @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering.
|
||||
* @private
|
||||
*/
|
||||
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context)
|
||||
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context, matrix)
|
||||
{
|
||||
this.renderSession.context = context || this.context;
|
||||
this.renderSession.resolution = this.resolution;
|
||||
displayObject._renderCanvas(this.renderSession);
|
||||
displayObject._renderCanvas(this.renderSession, matrix);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -327,7 +327,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
|
|||
* @param projection {Point} The projection
|
||||
* @param buffer {Array} a standard WebGL buffer
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer)
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer, matrix)
|
||||
{
|
||||
this.renderSession.blendModeManager.setBlendMode(PIXI.blendModes.NORMAL);
|
||||
|
||||
|
@ -350,7 +350,7 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
this.filterManager.begin(this.renderSession, buffer);
|
||||
|
||||
// render the scene!
|
||||
displayObject._renderWebGL(this.renderSession);
|
||||
displayObject._renderWebGL(this.renderSession, matrix);
|
||||
|
||||
// finish the sprite batch
|
||||
this.spriteBatch.end();
|
||||
|
|
|
@ -335,7 +335,7 @@ PIXI.PixiShader.prototype.syncUniforms = function()
|
|||
gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]);
|
||||
}
|
||||
|
||||
// gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl));
|
||||
// gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl));
|
||||
gl.uniform1i(uniform.uniformLocation, this.textureCount);
|
||||
this.textureCount++;
|
||||
}
|
||||
|
|
|
@ -201,14 +201,22 @@ PIXI.WebGLSpriteBatch.prototype.end = function()
|
|||
/**
|
||||
* @method render
|
||||
* @param sprite {Sprite} the sprite to render when using this spritebatch
|
||||
* @param {Matrix} [matrix] - Optional matrix. If provided the Display Object will be rendered using this matrix, otherwise it will use its worldTransform.
|
||||
*/
|
||||
PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
|
||||
PIXI.WebGLSpriteBatch.prototype.render = function(sprite, matrix)
|
||||
{
|
||||
var texture = sprite.texture;
|
||||
|
||||
//TODO set blend modes..
|
||||
// They provided an alternative rendering matrix, so use it
|
||||
var wt = sprite.worldTransform;
|
||||
|
||||
if (matrix)
|
||||
{
|
||||
wt = matrix;
|
||||
}
|
||||
|
||||
// check texture..
|
||||
if(this.currentBatchSize >= this.size)
|
||||
if (this.currentBatchSize >= this.size)
|
||||
{
|
||||
this.flush();
|
||||
this.currentBaseTexture = texture.baseTexture;
|
||||
|
@ -216,10 +224,13 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
|
|||
|
||||
// get the uvs for the texture
|
||||
var uvs = texture._uvs;
|
||||
// if the uvs have not updated then no point rendering just yet!
|
||||
if(!uvs)return;
|
||||
|
||||
// TODO trim??
|
||||
// if the uvs have not updated then no point rendering just yet!
|
||||
if (!uvs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var aX = sprite.anchor.x;
|
||||
var aY = sprite.anchor.y;
|
||||
|
||||
|
@ -227,7 +238,7 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
|
|||
|
||||
if (texture.trim)
|
||||
{
|
||||
// if the sprite is trimmed then we need to add the extra space before transforming the sprite coords..
|
||||
// if the sprite is trimmed then we need to add the extra space before transforming the sprite coords.
|
||||
var trim = texture.trim;
|
||||
|
||||
w1 = trim.x - aX * trim.width;
|
||||
|
@ -235,129 +246,134 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
|
|||
|
||||
h1 = trim.y - aY * trim.height;
|
||||
h0 = h1 + texture.crop.height;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
w0 = (texture.frame.width ) * (1-aX);
|
||||
w1 = (texture.frame.width ) * -aX;
|
||||
w0 = (texture.frame.width) * (1-aX);
|
||||
w1 = (texture.frame.width) * -aX;
|
||||
|
||||
h0 = texture.frame.height * (1-aY);
|
||||
h1 = texture.frame.height * -aY;
|
||||
}
|
||||
|
||||
var index = this.currentBatchSize * 4 * this.vertSize;
|
||||
|
||||
var i = this.currentBatchSize * 4 * this.vertSize;
|
||||
var resolution = texture.baseTexture.resolution;
|
||||
|
||||
var worldTransform = sprite.worldTransform;
|
||||
|
||||
var a = worldTransform.a / resolution;
|
||||
var b = worldTransform.b / resolution;
|
||||
var c = worldTransform.c / resolution;
|
||||
var d = worldTransform.d / resolution;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
var a = wt.a / resolution;
|
||||
var b = wt.b / resolution;
|
||||
var c = wt.c / resolution;
|
||||
var d = wt.d / resolution;
|
||||
var tx = wt.tx;
|
||||
var ty = wt.ty;
|
||||
|
||||
var colors = this.colors;
|
||||
var positions = this.positions;
|
||||
|
||||
if(this.renderSession.roundPixels)
|
||||
if (this.renderSession.roundPixels)
|
||||
{
|
||||
// xy
|
||||
positions[index] = a * w1 + c * h1 + tx | 0;
|
||||
positions[index+1] = d * h1 + b * w1 + ty | 0;
|
||||
positions[i] = a * w1 + c * h1 + tx | 0;
|
||||
positions[i+1] = d * h1 + b * w1 + ty | 0;
|
||||
|
||||
// xy
|
||||
positions[index+5] = a * w0 + c * h1 + tx | 0;
|
||||
positions[index+6] = d * h1 + b * w0 + ty | 0;
|
||||
positions[i+5] = a * w0 + c * h1 + tx | 0;
|
||||
positions[i+6] = d * h1 + b * w0 + ty | 0;
|
||||
|
||||
// xy
|
||||
positions[index+10] = a * w0 + c * h0 + tx | 0;
|
||||
positions[index+11] = d * h0 + b * w0 + ty | 0;
|
||||
positions[i+10] = a * w0 + c * h0 + tx | 0;
|
||||
positions[i+11] = d * h0 + b * w0 + ty | 0;
|
||||
|
||||
// xy
|
||||
positions[index+15] = a * w1 + c * h0 + tx | 0;
|
||||
positions[index+16] = d * h0 + b * w1 + ty | 0;
|
||||
positions[i+15] = a * w1 + c * h0 + tx | 0;
|
||||
positions[i+16] = d * h0 + b * w1 + ty | 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// xy
|
||||
positions[index] = a * w1 + c * h1 + tx;
|
||||
positions[index+1] = d * h1 + b * w1 + ty;
|
||||
positions[i] = a * w1 + c * h1 + tx;
|
||||
positions[i+1] = d * h1 + b * w1 + ty;
|
||||
|
||||
// xy
|
||||
positions[index+5] = a * w0 + c * h1 + tx;
|
||||
positions[index+6] = d * h1 + b * w0 + ty;
|
||||
positions[i+5] = a * w0 + c * h1 + tx;
|
||||
positions[i+6] = d * h1 + b * w0 + ty;
|
||||
|
||||
// xy
|
||||
positions[index+10] = a * w0 + c * h0 + tx;
|
||||
positions[index+11] = d * h0 + b * w0 + ty;
|
||||
positions[i+10] = a * w0 + c * h0 + tx;
|
||||
positions[i+11] = d * h0 + b * w0 + ty;
|
||||
|
||||
// xy
|
||||
positions[index+15] = a * w1 + c * h0 + tx;
|
||||
positions[index+16] = d * h0 + b * w1 + ty;
|
||||
positions[i+15] = a * w1 + c * h0 + tx;
|
||||
positions[i+16] = d * h0 + b * w1 + ty;
|
||||
}
|
||||
|
||||
// uv
|
||||
positions[index+2] = uvs.x0;
|
||||
positions[index+3] = uvs.y0;
|
||||
positions[i+2] = uvs.x0;
|
||||
positions[i+3] = uvs.y0;
|
||||
|
||||
// uv
|
||||
positions[index+7] = uvs.x1;
|
||||
positions[index+8] = uvs.y1;
|
||||
positions[i+7] = uvs.x1;
|
||||
positions[i+8] = uvs.y1;
|
||||
|
||||
// uv
|
||||
positions[index+12] = uvs.x2;
|
||||
positions[index+13] = uvs.y2;
|
||||
positions[i+12] = uvs.x2;
|
||||
positions[i+13] = uvs.y2;
|
||||
|
||||
// uv
|
||||
positions[index+17] = uvs.x3;
|
||||
positions[index+18] = uvs.y3;
|
||||
positions[i+17] = uvs.x3;
|
||||
positions[i+18] = uvs.y3;
|
||||
|
||||
// color and alpha
|
||||
var tint = sprite.tint;
|
||||
colors[index+4] = colors[index+9] = colors[index+14] = colors[index+19] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24);
|
||||
|
||||
colors[i+4] = colors[i+9] = colors[i+14] = colors[i+19] = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24);
|
||||
|
||||
// increment the batchsize
|
||||
this.sprites[this.currentBatchSize++] = sprite;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a TilingSprite using the spriteBatch.
|
||||
*
|
||||
* @method renderTilingSprite
|
||||
* @param sprite {TilingSprite} the tilingSprite to render
|
||||
* @param sprite {TilingSprite} the sprite to render
|
||||
*/
|
||||
PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function(tilingSprite)
|
||||
PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function(sprite)
|
||||
{
|
||||
var texture = tilingSprite.tilingTexture;
|
||||
var texture = sprite.tilingTexture;
|
||||
|
||||
// check texture..
|
||||
if(this.currentBatchSize >= this.size)
|
||||
if (this.currentBatchSize >= this.size)
|
||||
{
|
||||
//return;
|
||||
this.flush();
|
||||
this.currentBaseTexture = texture.baseTexture;
|
||||
}
|
||||
|
||||
// set the textures uvs temporarily
|
||||
// TODO create a separate texture so that we can tile part of a texture
|
||||
// set the textures uvs temporarily
|
||||
if (!sprite._uvs)
|
||||
{
|
||||
sprite._uvs = new PIXI.TextureUvs();
|
||||
}
|
||||
|
||||
if(!tilingSprite._uvs)tilingSprite._uvs = new PIXI.TextureUvs();
|
||||
var uvs = sprite._uvs;
|
||||
|
||||
var uvs = tilingSprite._uvs;
|
||||
var w = texture.baseTexture.width;
|
||||
var h = texture.baseTexture.height;
|
||||
|
||||
tilingSprite.tilePosition.x %= texture.baseTexture.width * tilingSprite.tileScaleOffset.x;
|
||||
tilingSprite.tilePosition.y %= texture.baseTexture.height * tilingSprite.tileScaleOffset.y;
|
||||
// var w = sprite._frame.sourceSizeW;
|
||||
// var h = sprite._frame.sourceSizeH;
|
||||
|
||||
var offsetX = tilingSprite.tilePosition.x/(texture.baseTexture.width*tilingSprite.tileScaleOffset.x);
|
||||
var offsetY = tilingSprite.tilePosition.y/(texture.baseTexture.height*tilingSprite.tileScaleOffset.y);
|
||||
// w = 16;
|
||||
// h = 16;
|
||||
|
||||
var scaleX = (tilingSprite.width / texture.baseTexture.width) / (tilingSprite.tileScale.x * tilingSprite.tileScaleOffset.x);
|
||||
var scaleY = (tilingSprite.height / texture.baseTexture.height) / (tilingSprite.tileScale.y * tilingSprite.tileScaleOffset.y);
|
||||
sprite.tilePosition.x %= w * sprite.tileScaleOffset.x;
|
||||
sprite.tilePosition.y %= h * sprite.tileScaleOffset.y;
|
||||
|
||||
var offsetX = sprite.tilePosition.x / (w * sprite.tileScaleOffset.x);
|
||||
var offsetY = sprite.tilePosition.y / (h * sprite.tileScaleOffset.y);
|
||||
|
||||
var scaleX = (sprite.width / w) / (sprite.tileScale.x * sprite.tileScaleOffset.x);
|
||||
var scaleY = (sprite.height / h) / (sprite.tileScale.y * sprite.tileScaleOffset.y);
|
||||
|
||||
uvs.x0 = 0 - offsetX;
|
||||
uvs.y0 = 0 - offsetY;
|
||||
|
@ -371,76 +387,76 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function(tilingSprite)
|
|||
uvs.x3 = 0 - offsetX;
|
||||
uvs.y3 = (1 * scaleY) - offsetY;
|
||||
|
||||
// get the tilingSprites current alpha and tint and combining them into a single color
|
||||
var tint = tilingSprite.tint;
|
||||
var color = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (tilingSprite.alpha * 255 << 24);
|
||||
// Get the sprites current alpha and tint and combine them into a single color
|
||||
var tint = sprite.tint;
|
||||
var color = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16) + (sprite.alpha * 255 << 24);
|
||||
|
||||
var positions = this.positions;
|
||||
var colors = this.colors;
|
||||
|
||||
var width = tilingSprite.width;
|
||||
var height = tilingSprite.height;
|
||||
var width = sprite.width;
|
||||
var height = sprite.height;
|
||||
|
||||
// TODO trim??
|
||||
var aX = tilingSprite.anchor.x;
|
||||
var aY = tilingSprite.anchor.y;
|
||||
var aX = sprite.anchor.x;
|
||||
var aY = sprite.anchor.y;
|
||||
var w0 = width * (1-aX);
|
||||
var w1 = width * -aX;
|
||||
|
||||
var h0 = height * (1-aY);
|
||||
var h1 = height * -aY;
|
||||
|
||||
var index = this.currentBatchSize * 4 * this.vertSize;
|
||||
var i = this.currentBatchSize * 4 * this.vertSize;
|
||||
|
||||
var resolution = texture.baseTexture.resolution;
|
||||
|
||||
var worldTransform = tilingSprite.worldTransform;
|
||||
var wt = sprite.worldTransform;
|
||||
|
||||
var a = worldTransform.a / resolution;//[0];
|
||||
var b = worldTransform.b / resolution;//[3];
|
||||
var c = worldTransform.c / resolution;//[1];
|
||||
var d = worldTransform.d / resolution;//[4];
|
||||
var tx = worldTransform.tx;//[2];
|
||||
var ty = worldTransform.ty;//[5];
|
||||
var a = wt.a / resolution;
|
||||
var b = wt.b / resolution;
|
||||
var c = wt.c / resolution;
|
||||
var d = wt.d / resolution;
|
||||
var tx = wt.tx;
|
||||
var ty = wt.ty;
|
||||
|
||||
// xy
|
||||
positions[index++] = a * w1 + c * h1 + tx;
|
||||
positions[index++] = d * h1 + b * w1 + ty;
|
||||
positions[i++] = a * w1 + c * h1 + tx;
|
||||
positions[i++] = d * h1 + b * w1 + ty;
|
||||
// uv
|
||||
positions[index++] = uvs.x0;
|
||||
positions[index++] = uvs.y0;
|
||||
positions[i++] = uvs.x0;
|
||||
positions[i++] = uvs.y0;
|
||||
// color
|
||||
colors[index++] = color;
|
||||
colors[i++] = color;
|
||||
|
||||
// xy
|
||||
positions[index++] = (a * w0 + c * h1 + tx);
|
||||
positions[index++] = d * h1 + b * w0 + ty;
|
||||
positions[i++] = (a * w0 + c * h1 + tx);
|
||||
positions[i++] = d * h1 + b * w0 + ty;
|
||||
// uv
|
||||
positions[index++] = uvs.x1;
|
||||
positions[index++] = uvs.y1;
|
||||
positions[i++] = uvs.x1;
|
||||
positions[i++] = uvs.y1;
|
||||
// color
|
||||
colors[index++] = color;
|
||||
colors[i++] = color;
|
||||
|
||||
// xy
|
||||
positions[index++] = a * w0 + c * h0 + tx;
|
||||
positions[index++] = d * h0 + b * w0 + ty;
|
||||
positions[i++] = a * w0 + c * h0 + tx;
|
||||
positions[i++] = d * h0 + b * w0 + ty;
|
||||
// uv
|
||||
positions[index++] = uvs.x2;
|
||||
positions[index++] = uvs.y2;
|
||||
positions[i++] = uvs.x2;
|
||||
positions[i++] = uvs.y2;
|
||||
// color
|
||||
colors[index++] = color;
|
||||
colors[i++] = color;
|
||||
|
||||
// xy
|
||||
positions[index++] = a * w1 + c * h0 + tx;
|
||||
positions[index++] = d * h0 + b * w1 + ty;
|
||||
positions[i++] = a * w1 + c * h0 + tx;
|
||||
positions[i++] = d * h0 + b * w1 + ty;
|
||||
// uv
|
||||
positions[index++] = uvs.x3;
|
||||
positions[index++] = uvs.y3;
|
||||
positions[i++] = uvs.x3;
|
||||
positions[i++] = uvs.y3;
|
||||
// color
|
||||
colors[index++] = color;
|
||||
colors[i++] = color;
|
||||
|
||||
// increment the batchsize
|
||||
this.sprites[this.currentBatchSize++] = tilingSprite;
|
||||
this.sprites[this.currentBatchSize++] = sprite;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -451,14 +467,18 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function(tilingSprite)
|
|||
PIXI.WebGLSpriteBatch.prototype.flush = function()
|
||||
{
|
||||
// If the batch is length 0 then return as there is nothing to draw
|
||||
if (this.currentBatchSize===0)return;
|
||||
if (this.currentBatchSize === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
var shader;
|
||||
|
||||
if(this.dirty)
|
||||
if (this.dirty)
|
||||
{
|
||||
this.dirty = false;
|
||||
|
||||
// bind the main texture
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
|
@ -466,10 +486,10 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||
|
||||
shader = this.defaultShader.shaders[gl.id];
|
||||
shader = this.defaultShader.shaders[gl.id];
|
||||
|
||||
// this is the same for each shader?
|
||||
var stride = this.vertSize * 4;
|
||||
var stride = this.vertSize * 4;
|
||||
gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0);
|
||||
gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4);
|
||||
|
||||
|
@ -478,7 +498,7 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
}
|
||||
|
||||
// upload the verts to the buffer
|
||||
if(this.currentBatchSize > ( this.size * 0.5 ) )
|
||||
if (this.currentBatchSize > (this.size * 0.5))
|
||||
{
|
||||
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
|
||||
}
|
||||
|
@ -504,14 +524,22 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
|
||||
sprite = this.sprites[i];
|
||||
|
||||
nextTexture = sprite.texture.baseTexture;
|
||||
if (sprite.tilingTexture)
|
||||
{
|
||||
nextTexture = sprite.tilingTexture.baseTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextTexture = sprite.texture.baseTexture;
|
||||
}
|
||||
|
||||
nextBlendMode = sprite.blendMode;
|
||||
nextShader = sprite.shader || this.defaultShader;
|
||||
|
||||
blendSwap = currentBlendMode !== nextBlendMode;
|
||||
shaderSwap = currentShader !== nextShader; // should I use _UIDS???
|
||||
|
||||
if(currentBaseTexture !== nextTexture || blendSwap || shaderSwap)
|
||||
if (currentBaseTexture !== nextTexture || blendSwap || shaderSwap)
|
||||
{
|
||||
this.renderBatch(currentBaseTexture, batchSize, start);
|
||||
|
||||
|
@ -519,24 +547,24 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
batchSize = 0;
|
||||
currentBaseTexture = nextTexture;
|
||||
|
||||
if( blendSwap )
|
||||
if (blendSwap)
|
||||
{
|
||||
currentBlendMode = nextBlendMode;
|
||||
this.renderSession.blendModeManager.setBlendMode( currentBlendMode );
|
||||
this.renderSession.blendModeManager.setBlendMode(currentBlendMode);
|
||||
}
|
||||
|
||||
if( shaderSwap )
|
||||
if (shaderSwap)
|
||||
{
|
||||
currentShader = nextShader;
|
||||
|
||||
shader = currentShader.shaders[gl.id];
|
||||
|
||||
if(!shader)
|
||||
if (!shader)
|
||||
{
|
||||
shader = new PIXI.PixiShader(gl);
|
||||
|
||||
shader.fragmentSrc =currentShader.fragmentSrc;
|
||||
shader.uniforms =currentShader.uniforms;
|
||||
shader.fragmentSrc = currentShader.fragmentSrc;
|
||||
shader.uniforms = currentShader.uniforms;
|
||||
shader.init();
|
||||
|
||||
currentShader.shaders[gl.id] = shader;
|
||||
|
@ -545,14 +573,17 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
// set shader function???
|
||||
this.renderSession.shaderManager.setShader(shader);
|
||||
|
||||
if(shader.dirty)shader.syncUniforms();
|
||||
if (shader.dirty)
|
||||
{
|
||||
shader.syncUniforms();
|
||||
}
|
||||
|
||||
// both thease only need to be set if they are changing..
|
||||
// both these only need to be set if they are changing..
|
||||
// set the projection
|
||||
var projection = this.renderSession.projection;
|
||||
gl.uniform2f(shader.projectionVector, projection.x, projection.y);
|
||||
|
||||
// TODO - this is temprorary!
|
||||
// TODO - this is temporary!
|
||||
var offsetVector = this.renderSession.offset;
|
||||
gl.uniform2f(shader.offsetVector, offsetVector.x, offsetVector.y);
|
||||
|
||||
|
@ -577,12 +608,15 @@ PIXI.WebGLSpriteBatch.prototype.flush = function()
|
|||
*/
|
||||
PIXI.WebGLSpriteBatch.prototype.renderBatch = function(texture, size, startIndex)
|
||||
{
|
||||
if(size === 0)return;
|
||||
if (size === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
// check if a texture is dirty..
|
||||
if(texture._dirty[gl.id])
|
||||
if (texture._dirty[gl.id])
|
||||
{
|
||||
this.renderSession.renderer.updateTexture(texture);
|
||||
}
|
||||
|
@ -626,8 +660,8 @@ PIXI.WebGLSpriteBatch.prototype.destroy = function()
|
|||
this.vertices = null;
|
||||
this.indices = null;
|
||||
|
||||
this.gl.deleteBuffer( this.vertexBuffer );
|
||||
this.gl.deleteBuffer( this.indexBuffer );
|
||||
this.gl.deleteBuffer(this.vertexBuffer);
|
||||
this.gl.deleteBuffer(this.indexBuffer);
|
||||
|
||||
this.currentBaseTexture = null;
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ PIXI.Text = function(text, style)
|
|||
|
||||
this.setText(text);
|
||||
this.setStyle(style);
|
||||
|
||||
};
|
||||
|
||||
// constructor
|
||||
|
@ -107,43 +106,6 @@ Object.defineProperty(PIXI.Text.prototype, 'height', {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Set the style of the text
|
||||
*
|
||||
* @method setStyle
|
||||
* @param [style] {Object} The style parameters
|
||||
* @param [style.font='bold 20pt Arial'] {String} The style and size of the font
|
||||
* @param [style.fill='black'] {Object} A canvas fillstyle that will be used on the text eg 'red', '#00FF00'
|
||||
* @param [style.align='left'] {String} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
|
||||
* @param [style.stroke='black'] {String} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'
|
||||
* @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke)
|
||||
* @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used
|
||||
* @param [style.wordWrapWidth=100] {Number} The width at which text will wrap
|
||||
* @param [style.dropShadow=false] {Boolean} Set a drop shadow for the text
|
||||
* @param [style.dropShadowColor='#000000'] {String} A fill style to be used on the dropshadow e.g 'red', '#00FF00'
|
||||
* @param [style.dropShadowAngle=Math.PI/4] {Number} Set a angle of the drop shadow
|
||||
* @param [style.dropShadowDistance=5] {Number} Set a distance of the drop shadow
|
||||
*/
|
||||
PIXI.Text.prototype.setStyle = function(style)
|
||||
{
|
||||
style = style || {};
|
||||
style.font = style.font || 'bold 20pt Arial';
|
||||
style.fill = style.fill || 'black';
|
||||
style.align = style.align || 'left';
|
||||
style.stroke = style.stroke || 'black'; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
|
||||
style.strokeThickness = style.strokeThickness || 0;
|
||||
style.wordWrap = style.wordWrap || false;
|
||||
style.wordWrapWidth = style.wordWrapWidth || 100;
|
||||
|
||||
style.dropShadow = style.dropShadow || false;
|
||||
style.dropShadowAngle = style.dropShadowAngle || Math.PI / 6;
|
||||
style.dropShadowDistance = style.dropShadowDistance || 4;
|
||||
style.dropShadowColor = style.dropShadowColor || 'black';
|
||||
|
||||
this.style = style;
|
||||
this.dirty = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the copy for the text object. To split a line you can use '\n'.
|
||||
*
|
||||
|
@ -156,132 +118,6 @@ PIXI.Text.prototype.setText = function(text)
|
|||
this.dirty = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders text and updates it when needed
|
||||
*
|
||||
* @method updateText
|
||||
* @private
|
||||
*/
|
||||
PIXI.Text.prototype.updateText = function()
|
||||
{
|
||||
this.texture.baseTexture.resolution = this.resolution;
|
||||
|
||||
this.context.font = this.style.font;
|
||||
|
||||
var outputText = this.text;
|
||||
|
||||
// word wrap
|
||||
// preserve original text
|
||||
if(this.style.wordWrap)outputText = this.wordWrap(this.text);
|
||||
|
||||
//split text into lines
|
||||
var lines = outputText.split(/(?:\r\n|\r|\n)/);
|
||||
|
||||
//calculate text width
|
||||
var lineWidths = [];
|
||||
var maxLineWidth = 0;
|
||||
var fontProperties = this.determineFontProperties(this.style.font);
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
var lineWidth = this.context.measureText(lines[i]).width;
|
||||
lineWidths[i] = lineWidth;
|
||||
maxLineWidth = Math.max(maxLineWidth, lineWidth);
|
||||
}
|
||||
|
||||
var width = maxLineWidth + this.style.strokeThickness;
|
||||
if(this.style.dropShadow)width += this.style.dropShadowDistance;
|
||||
|
||||
this.canvas.width = ( width + this.context.lineWidth ) * this.resolution;
|
||||
|
||||
//calculate text height
|
||||
var lineHeight = fontProperties.fontSize + this.style.strokeThickness;
|
||||
|
||||
var height = lineHeight * lines.length;
|
||||
if(this.style.dropShadow)height += this.style.dropShadowDistance;
|
||||
|
||||
this.canvas.height = height * this.resolution;
|
||||
|
||||
this.context.scale( this.resolution, this.resolution);
|
||||
|
||||
if(navigator.isCocoonJS) this.context.clearRect(0,0,this.canvas.width,this.canvas.height);
|
||||
|
||||
// used for debugging..
|
||||
//this.context.fillStyle ="#FF0000"
|
||||
//this.context.fillRect(0, 0, this.canvas.width,this.canvas.height);
|
||||
|
||||
this.context.font = this.style.font;
|
||||
this.context.strokeStyle = this.style.stroke;
|
||||
this.context.lineWidth = this.style.strokeThickness;
|
||||
this.context.textBaseline = 'alphabetic';
|
||||
//this.context.lineJoin = 'round';
|
||||
|
||||
var linePositionX;
|
||||
var linePositionY;
|
||||
|
||||
if(this.style.dropShadow)
|
||||
{
|
||||
this.context.fillStyle = this.style.dropShadowColor;
|
||||
|
||||
var xShadowOffset = Math.sin(this.style.dropShadowAngle) * this.style.dropShadowDistance;
|
||||
var yShadowOffset = Math.cos(this.style.dropShadowAngle) * this.style.dropShadowDistance;
|
||||
|
||||
for (i = 0; i < lines.length; i++)
|
||||
{
|
||||
linePositionX = this.style.strokeThickness / 2;
|
||||
linePositionY = (this.style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent;
|
||||
|
||||
if(this.style.align === 'right')
|
||||
{
|
||||
linePositionX += maxLineWidth - lineWidths[i];
|
||||
}
|
||||
else if(this.style.align === 'center')
|
||||
{
|
||||
linePositionX += (maxLineWidth - lineWidths[i]) / 2;
|
||||
}
|
||||
|
||||
if(this.style.fill)
|
||||
{
|
||||
this.context.fillText(lines[i], linePositionX + xShadowOffset, linePositionY + yShadowOffset);
|
||||
}
|
||||
|
||||
// if(dropShadow)
|
||||
}
|
||||
}
|
||||
|
||||
//set canvas text styles
|
||||
this.context.fillStyle = this.style.fill;
|
||||
|
||||
//draw lines line by line
|
||||
for (i = 0; i < lines.length; i++)
|
||||
{
|
||||
linePositionX = this.style.strokeThickness / 2;
|
||||
linePositionY = (this.style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent;
|
||||
|
||||
if(this.style.align === 'right')
|
||||
{
|
||||
linePositionX += maxLineWidth - lineWidths[i];
|
||||
}
|
||||
else if(this.style.align === 'center')
|
||||
{
|
||||
linePositionX += (maxLineWidth - lineWidths[i]) / 2;
|
||||
}
|
||||
|
||||
if(this.style.stroke && this.style.strokeThickness)
|
||||
{
|
||||
this.context.strokeText(lines[i], linePositionX, linePositionY);
|
||||
}
|
||||
|
||||
if(this.style.fill)
|
||||
{
|
||||
this.context.fillText(lines[i], linePositionX, linePositionY);
|
||||
}
|
||||
|
||||
// if(dropShadow)
|
||||
}
|
||||
|
||||
this.updateTexture();
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates texture size based on canvas size
|
||||
*
|
||||
|
@ -460,54 +296,6 @@ PIXI.Text.prototype.determineFontProperties = function(fontStyle)
|
|||
return properties;
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies newlines to a string to have it optimally fit into the horizontal
|
||||
* bounds set by the Text object's wordWrapWidth property.
|
||||
*
|
||||
* @method wordWrap
|
||||
* @param text {String}
|
||||
* @private
|
||||
*/
|
||||
PIXI.Text.prototype.wordWrap = function(text)
|
||||
{
|
||||
// Greedy wrapping algorithm that will wrap words as the line grows longer
|
||||
// than its horizontal bounds.
|
||||
var result = '';
|
||||
var lines = text.split('\n');
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
var spaceLeft = this.style.wordWrapWidth;
|
||||
var words = lines[i].split(' ');
|
||||
for (var j = 0; j < words.length; j++)
|
||||
{
|
||||
var wordWidth = this.context.measureText(words[j]).width;
|
||||
var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width;
|
||||
if(j === 0 || wordWidthWithSpace > spaceLeft)
|
||||
{
|
||||
// Skip printing the newline if it's the first word of the line that is
|
||||
// greater than the word wrap width.
|
||||
if(j > 0)
|
||||
{
|
||||
result += '\n';
|
||||
}
|
||||
result += words[j];
|
||||
spaceLeft = this.style.wordWrapWidth - wordWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
spaceLeft -= wordWidthWithSpace;
|
||||
result += ' ' + words[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (i < lines.length-1)
|
||||
{
|
||||
result += '\n';
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account.
|
||||
*
|
||||
|
@ -526,21 +314,6 @@ PIXI.Text.prototype.getBounds = function(matrix)
|
|||
return PIXI.Sprite.prototype.getBounds.call(this, matrix);
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys this text object.
|
||||
*
|
||||
* @method destroy
|
||||
* @param destroyBaseTexture {Boolean} whether to destroy the base texture as well
|
||||
*/
|
||||
PIXI.Text.prototype.destroy = function(destroyBaseTexture)
|
||||
{
|
||||
// make sure to reset the the context and canvas.. dont want this hanging around in memory!
|
||||
this.context = null;
|
||||
this.canvas = null;
|
||||
|
||||
this.texture.destroy(destroyBaseTexture === undefined ? true : destroyBaseTexture);
|
||||
};
|
||||
|
||||
PIXI.Text.fontPropertiesCache = {};
|
||||
PIXI.Text.fontPropertiesCanvas = document.createElement('canvas');
|
||||
PIXI.Text.fontPropertiesContext = PIXI.Text.fontPropertiesCanvas.getContext('2d');
|
||||
|
|
|
@ -90,7 +90,6 @@ PIXI.BaseTexture = function(source, scaleMode)
|
|||
this._glTextures = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used
|
||||
* Also the texture must be a power of two size to work
|
||||
*
|
||||
|
@ -98,8 +97,6 @@ PIXI.BaseTexture = function(source, scaleMode)
|
|||
* @type {Boolean}
|
||||
*/
|
||||
this.mipmap = false;
|
||||
// used for webGL texture updating...
|
||||
// TODO - this needs to be addressed
|
||||
|
||||
/**
|
||||
* @property _dirty
|
||||
|
@ -119,7 +116,6 @@ PIXI.BaseTexture = function(source, scaleMode)
|
|||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
var scope = this;
|
||||
|
||||
this.source.onload = function() {
|
||||
|
@ -137,7 +133,6 @@ PIXI.BaseTexture = function(source, scaleMode)
|
|||
this.source.onerror = function() {
|
||||
scope.dispatchEvent( { type: 'error', content: scope } );
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,8 +151,7 @@ PIXI.BaseTexture = function(source, scaleMode)
|
|||
};
|
||||
|
||||
PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture;
|
||||
|
||||
// PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype);
|
||||
PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype);
|
||||
|
||||
/**
|
||||
* Destroys this base texture
|
||||
|
|
|
@ -128,6 +128,8 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode, resolution)
|
|||
*/
|
||||
this.valid = true;
|
||||
|
||||
this.tempMatrix = new Phaser.Matrix();
|
||||
|
||||
this._updateUvs();
|
||||
};
|
||||
|
||||
|
@ -198,44 +200,44 @@ PIXI.RenderTexture.prototype.clear = function()
|
|||
*/
|
||||
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, matrix, clear)
|
||||
{
|
||||
if(!this.valid)return;
|
||||
//TOOD replace position with matrix..
|
||||
|
||||
//Lets create a nice matrix to apply to our display object. Frame buffers come in upside down so we need to flip the matrix
|
||||
var wt = displayObject.worldTransform;
|
||||
wt.identity();
|
||||
wt.translate(0, this.projection.y * 2);
|
||||
if(matrix)wt.append(matrix);
|
||||
wt.scale(1,-1);
|
||||
|
||||
// setWorld Alpha to ensure that the object is renderer at full opacity
|
||||
displayObject.worldAlpha = 1;
|
||||
|
||||
// Time to update all the children of the displayObject with the new matrix..
|
||||
var children = displayObject.children;
|
||||
|
||||
for(var i=0,j=children.length; i<j; i++)
|
||||
if (!this.valid)
|
||||
{
|
||||
children[i].updateTransform();
|
||||
return;
|
||||
}
|
||||
|
||||
// time for the webGL fun stuff!
|
||||
// Frame buffers come in upside down so we need to flip the matrix
|
||||
matrix.translate(0, this.projection.y * 2);
|
||||
matrix.scale(1, -1);
|
||||
|
||||
// Set worldAlpha to ensure that the object is renderer at full opacity
|
||||
displayObject.worldAlpha = 1;
|
||||
|
||||
// Time to update all the children of the displayObject with the new matrix.
|
||||
for (var i = 0; i < displayObject.children.length; i++)
|
||||
{
|
||||
displayObject.children[i].updateTransform();
|
||||
}
|
||||
|
||||
// Time for the webGL fun stuff!
|
||||
var gl = this.renderer.gl;
|
||||
|
||||
gl.viewport(0, 0, this.width * this.resolution, this.height * this.resolution);
|
||||
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, this.textureBuffer.frameBuffer );
|
||||
|
||||
if(clear)this.textureBuffer.clear();
|
||||
if (clear)
|
||||
{
|
||||
this.textureBuffer.clear();
|
||||
}
|
||||
|
||||
this.renderer.spriteBatch.dirty = true;
|
||||
|
||||
this.renderer.renderDisplayObject(displayObject, this.projection, this.textureBuffer.frameBuffer);
|
||||
this.renderer.renderDisplayObject(displayObject, this.projection, this.textureBuffer.frameBuffer, matrix);
|
||||
|
||||
this.renderer.spriteBatch.dirty = true;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This function will draw the display object to the texture.
|
||||
*
|
||||
|
@ -247,24 +249,24 @@ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, matrix, clear
|
|||
*/
|
||||
PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, matrix, clear)
|
||||
{
|
||||
if(!this.valid)return;
|
||||
|
||||
var wt = displayObject.worldTransform;
|
||||
wt.identity();
|
||||
if(matrix)wt.append(matrix);
|
||||
if (!this.valid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// setWorld Alpha to ensure that the object is renderer at full opacity
|
||||
displayObject.worldAlpha = 1;
|
||||
|
||||
// Time to update all the children of the displayObject with the new matrix..
|
||||
var children = displayObject.children;
|
||||
|
||||
for(var i = 0, j = children.length; i < j; i++)
|
||||
// Time to update all the children of the displayObject with the new matrix (what new matrix? there isn't one!)
|
||||
for (var i = 0; i < displayObject.children.length; i++)
|
||||
{
|
||||
children[i].updateTransform();
|
||||
displayObject.children[i].updateTransform();
|
||||
}
|
||||
|
||||
if(clear)this.textureBuffer.clear();
|
||||
if (clear)
|
||||
{
|
||||
this.textureBuffer.clear();
|
||||
}
|
||||
|
||||
var context = this.textureBuffer.context;
|
||||
|
||||
|
@ -272,7 +274,7 @@ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, matrix, clea
|
|||
|
||||
this.renderer.resolution = this.resolution;
|
||||
|
||||
this.renderer.renderDisplayObject(displayObject, context);
|
||||
this.renderer.renderDisplayObject(displayObject, context, matrix);
|
||||
|
||||
this.renderer.resolution = realResolution;
|
||||
};
|
||||
|
|
|
@ -81,6 +81,14 @@ PIXI.Texture = function(baseTexture, frame, crop, trim)
|
|||
*/
|
||||
this.valid = false;
|
||||
|
||||
/**
|
||||
* Is this a tiling texture? As used by the likes of a TilingSprite.
|
||||
*
|
||||
* @property isTiling
|
||||
* @type Boolean
|
||||
*/
|
||||
this.isTiling = false;
|
||||
|
||||
/**
|
||||
* This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)
|
||||
*
|
||||
|
@ -128,14 +136,14 @@ PIXI.Texture = function(baseTexture, frame, crop, trim)
|
|||
if (this.noFrame) frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height);
|
||||
this.setFrame(frame);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// baseTexture.addEventListener('loaded', this.onBaseTextureLoaded.bind(this));
|
||||
// }
|
||||
else
|
||||
{
|
||||
baseTexture.addEventListener('loaded', this.onBaseTextureLoaded.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
PIXI.Texture.prototype.constructor = PIXI.Texture;
|
||||
// PIXI.EventTarget.mixin(PIXI.Texture.prototype);
|
||||
PIXI.EventTarget.mixin(PIXI.Texture.prototype);
|
||||
|
||||
/**
|
||||
* Called when the base texture is loaded
|
||||
|
@ -146,13 +154,16 @@ PIXI.Texture.prototype.constructor = PIXI.Texture;
|
|||
PIXI.Texture.prototype.onBaseTextureLoaded = function()
|
||||
{
|
||||
var baseTexture = this.baseTexture;
|
||||
// baseTexture.removeEventListener('loaded', this.onLoaded);
|
||||
baseTexture.removeEventListener('loaded', this.onLoaded);
|
||||
|
||||
if (this.noFrame) this.frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height);
|
||||
if (this.noFrame)
|
||||
{
|
||||
this.frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height);
|
||||
}
|
||||
|
||||
this.setFrame(this.frame);
|
||||
|
||||
// this.dispatchEvent( { type: 'update', content: this } );
|
||||
this.dispatchEvent( { type: 'update', content: this } );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,46 +9,72 @@
|
|||
* @param source {HTMLVideoElement}
|
||||
* @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
|
||||
*/
|
||||
PIXI.VideoTexture = function( source, scaleMode )
|
||||
PIXI.VideoTexture = function(source, scaleMode)
|
||||
{
|
||||
if( !source ){
|
||||
if (!source)
|
||||
{
|
||||
throw new Error( 'No video source element specified.' );
|
||||
}
|
||||
|
||||
// hook in here to check if video is already available.
|
||||
// PIXI.BaseTexture looks for a source.complete boolean, plus width & height.
|
||||
|
||||
if( (source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA ) && source.width && source.height )
|
||||
if ((source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA ) && source.width && source.height)
|
||||
{
|
||||
source.complete = true;
|
||||
}
|
||||
|
||||
PIXI.BaseTexture.call( this, source, scaleMode );
|
||||
this.video = this.source;
|
||||
|
||||
this.ended = false;
|
||||
|
||||
PIXI.BaseTexture.call(this, source, scaleMode);
|
||||
|
||||
this.autoUpdate = false;
|
||||
this.updateBound = this._onUpdate.bind(this);
|
||||
|
||||
if( !source.complete )
|
||||
if (!source.complete)
|
||||
{
|
||||
this._onCanPlay = this.onCanPlay.bind(this);
|
||||
|
||||
source.addEventListener( 'canplay', this._onCanPlay );
|
||||
source.addEventListener( 'canplaythrough', this._onCanPlay );
|
||||
source.addEventListener('canplay', this._onCanPlay);
|
||||
source.addEventListener('canplaythrough', this._onCanPlay);
|
||||
source.addEventListener('ended', this._onEnded.bind(this));
|
||||
|
||||
// started playing..
|
||||
source.addEventListener( 'play', this.onPlayStart.bind(this) );
|
||||
source.addEventListener( 'pause', this.onPlayStop.bind(this) );
|
||||
source.addEventListener('play', this.onPlayStart.bind(this));
|
||||
source.addEventListener('pause', this.onPlayStop.bind(this));
|
||||
}
|
||||
|
||||
this.onPlay = new Phaser.Signal();
|
||||
this.onComplete = new Phaser.Signal();
|
||||
|
||||
};
|
||||
|
||||
PIXI.VideoTexture.prototype = Object.create( PIXI.BaseTexture.prototype );
|
||||
|
||||
PIXI.VideoTexture.prototype = Object.create(PIXI.BaseTexture.prototype);
|
||||
PIXI.VideoTexture.constructor = PIXI.VideoTexture;
|
||||
|
||||
PIXI.VideoTexture.prototype.play = function()
|
||||
{
|
||||
this.source.play();
|
||||
this.onPlay.dispatch();
|
||||
};
|
||||
|
||||
PIXI.VideoTexture.prototype.stop = function()
|
||||
{
|
||||
this.source.stop();
|
||||
this.onComplete.dispatch();
|
||||
};
|
||||
|
||||
PIXI.VideoTexture.prototype._onEnded = function()
|
||||
{
|
||||
this.ended = true;
|
||||
this.onComplete.dispatch();
|
||||
};
|
||||
|
||||
PIXI.VideoTexture.prototype._onUpdate = function()
|
||||
{
|
||||
if(this.autoUpdate)
|
||||
if (this.autoUpdate)
|
||||
{
|
||||
window.requestAnimationFrame(this.updateBound);
|
||||
this.dirty();
|
||||
|
@ -57,7 +83,7 @@ PIXI.VideoTexture.prototype._onUpdate = function()
|
|||
|
||||
PIXI.VideoTexture.prototype.onPlayStart = function()
|
||||
{
|
||||
if(!this.autoUpdate)
|
||||
if (!this.autoUpdate)
|
||||
{
|
||||
window.requestAnimationFrame(this.updateBound);
|
||||
this.autoUpdate = true;
|
||||
|
@ -71,21 +97,21 @@ PIXI.VideoTexture.prototype.onPlayStop = function()
|
|||
|
||||
PIXI.VideoTexture.prototype.onCanPlay = function()
|
||||
{
|
||||
if( event.type === 'canplaythrough' )
|
||||
if (event.type === 'canplaythrough')
|
||||
{
|
||||
this.hasLoaded = true;
|
||||
this.hasLoaded = true;
|
||||
|
||||
|
||||
if( this.source )
|
||||
if (this.source)
|
||||
{
|
||||
this.source.removeEventListener( 'canplay', this._onCanPlay );
|
||||
this.source.removeEventListener( 'canplaythrough', this._onCanPlay );
|
||||
this.source.removeEventListener('canplay', this._onCanPlay);
|
||||
this.source.removeEventListener('canplaythrough', this._onCanPlay);
|
||||
|
||||
this.width = this.source.videoWidth;
|
||||
this.height = this.source.videoHeight;
|
||||
this.width = this.source.videoWidth;
|
||||
this.height = this.source.videoHeight;
|
||||
|
||||
// prevent multiple loaded dispatches..
|
||||
if( !this.__loaded ){
|
||||
if (!this.__loaded )
|
||||
{
|
||||
this.__loaded = true;
|
||||
this.dispatchEvent( { type: 'loaded', content: this } );
|
||||
}
|
||||
|
@ -95,10 +121,10 @@ PIXI.VideoTexture.prototype.onCanPlay = function()
|
|||
|
||||
PIXI.VideoTexture.prototype.destroy = function()
|
||||
{
|
||||
if( this.source && this.source._pixiId )
|
||||
if (this.source && this.source._pixiId)
|
||||
{
|
||||
PIXI.BaseTextureCache[ this.source._pixiId ] = null;
|
||||
delete PIXI.BaseTextureCache[ this.source._pixiId ];
|
||||
delete PIXI.BaseTextureCache[this.source._pixiId];
|
||||
|
||||
this.source._pixiId = null;
|
||||
delete this.source._pixiId;
|
||||
|
@ -116,19 +142,19 @@ PIXI.VideoTexture.prototype.destroy = function()
|
|||
* @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
|
||||
* @return {VideoTexture}
|
||||
*/
|
||||
PIXI.VideoTexture.baseTextureFromVideo = function( video, scaleMode )
|
||||
PIXI.VideoTexture.baseTextureFromVideo = function(video, scaleMode)
|
||||
{
|
||||
if( !video._pixiId )
|
||||
if (!video._pixiId)
|
||||
{
|
||||
video._pixiId = 'video_' + PIXI.TextureCacheIdGenerator++;
|
||||
}
|
||||
|
||||
var baseTexture = PIXI.BaseTextureCache[ video._pixiId ];
|
||||
var baseTexture = PIXI.BaseTextureCache[video._pixiId];
|
||||
|
||||
if( !baseTexture )
|
||||
if (!baseTexture)
|
||||
{
|
||||
baseTexture = new PIXI.VideoTexture( video, scaleMode );
|
||||
PIXI.BaseTextureCache[ video._pixiId ] = baseTexture;
|
||||
baseTexture = new PIXI.VideoTexture(video, scaleMode);
|
||||
PIXI.BaseTextureCache[video._pixiId] = baseTexture;
|
||||
}
|
||||
|
||||
return baseTexture;
|
||||
|
@ -143,10 +169,11 @@ PIXI.VideoTexture.baseTextureFromVideo = function( video, scaleMode )
|
|||
* @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
|
||||
* @return {Texture} A Texture, but not a VideoTexture.
|
||||
*/
|
||||
PIXI.VideoTexture.textureFromVideo = function( video, scaleMode )
|
||||
PIXI.VideoTexture.textureFromVideo = function(video, scaleMode)
|
||||
{
|
||||
var baseTexture = PIXI.VideoTexture.baseTextureFromVideo( video, scaleMode );
|
||||
return new PIXI.Texture( baseTexture );
|
||||
var baseTexture = PIXI.VideoTexture.baseTextureFromVideo(video, scaleMode);
|
||||
|
||||
return new PIXI.Texture(baseTexture);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -156,13 +183,27 @@ PIXI.VideoTexture.textureFromVideo = function( video, scaleMode )
|
|||
* @method fromUrl
|
||||
* @param videoSrc {String} The URL for the video.
|
||||
* @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
|
||||
* @param autoPlay {boolean} Automatically start the video playing? Until you do this you can't get the width / height of the resulting texture.
|
||||
* @return {VideoTexture}
|
||||
*/
|
||||
PIXI.VideoTexture.fromUrl = function( videoSrc, scaleMode )
|
||||
PIXI.VideoTexture.fromUrl = function(videoSrc, scaleMode, autoPlay)
|
||||
{
|
||||
if (typeof scaleMode === 'undefined') { scaleMode = PIXI.scaleModes.DEFAULT; }
|
||||
if (typeof autoPlay === 'undefined') { autoPlay = true; }
|
||||
|
||||
var video = document.createElement('video');
|
||||
|
||||
video.src = videoSrc;
|
||||
video.autoPlay = true;
|
||||
video.play();
|
||||
return PIXI.VideoTexture.textureFromVideo( video, scaleMode);
|
||||
|
||||
if (autoPlay)
|
||||
{
|
||||
video.autoPlay = true;
|
||||
video.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
video.autoPlay = false;
|
||||
}
|
||||
|
||||
return PIXI.VideoTexture.textureFromVideo(video, scaleMode);
|
||||
};
|
||||
|
|
|
@ -95,19 +95,19 @@ Phaser.SoundManager = function (game) {
|
|||
this.context = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} usingWebAudio - true if this sound is being played with Web Audio.
|
||||
* @property {boolean} usingWebAudio - True the SoundManager and device are both using Web Audio.
|
||||
* @readonly
|
||||
*/
|
||||
this.usingWebAudio = true;
|
||||
this.usingWebAudio = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} usingAudioTag - true if the sound is being played via the Audio tag.
|
||||
* @property {boolean} usingAudioTag - True the SoundManager and device are both using the Audio tag instead of Web Audio.
|
||||
* @readonly
|
||||
*/
|
||||
this.usingAudioTag = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} noAudio - Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead.
|
||||
* @property {boolean} noAudio - True if audio been disabled via the PhaserGlobal (useful if you need to use a 3rd party audio library) or the device doesn't support any audio.
|
||||
* @default
|
||||
*/
|
||||
this.noAudio = false;
|
||||
|
@ -159,22 +159,22 @@ Phaser.SoundManager.prototype = {
|
|||
this.touchLocked = false;
|
||||
}
|
||||
|
||||
// PhaserGlobal overrides
|
||||
if (window['PhaserGlobal'])
|
||||
{
|
||||
// Check to see if all audio playback is disabled (i.e. handled by a 3rd party class)
|
||||
if (window['PhaserGlobal'].disableAudio === true)
|
||||
{
|
||||
this.usingWebAudio = false;
|
||||
this.noAudio = true;
|
||||
this.touchLocked = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the Web Audio API is disabled (for testing Audio Tag playback during development)
|
||||
if (window['PhaserGlobal'].disableWebAudio === true)
|
||||
{
|
||||
this.usingWebAudio = false;
|
||||
this.usingAudioTag = true;
|
||||
this.noAudio = false;
|
||||
this.touchLocked = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ Phaser.SoundManager.prototype = {
|
|||
} catch (error) {
|
||||
this.context = null;
|
||||
this.usingWebAudio = false;
|
||||
this.noAudio = true;
|
||||
this.touchLocked = false;
|
||||
}
|
||||
}
|
||||
else if (!!window['webkitAudioContext'])
|
||||
|
@ -202,20 +202,28 @@ Phaser.SoundManager.prototype = {
|
|||
} catch (error) {
|
||||
this.context = null;
|
||||
this.usingWebAudio = false;
|
||||
this.noAudio = true;
|
||||
this.touchLocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!!window['Audio'] && this.context === null)
|
||||
if (this.context === null)
|
||||
{
|
||||
this.usingWebAudio = false;
|
||||
this.usingAudioTag = true;
|
||||
this.noAudio = false;
|
||||
// No Web Audio support - how about legacy Audio?
|
||||
if (window['Audio'] === undefined)
|
||||
{
|
||||
this.noAudio = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.usingAudioTag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.context !== null)
|
||||
else
|
||||
{
|
||||
this.usingWebAudio = true;
|
||||
|
||||
if (typeof this.context.createGain === 'undefined')
|
||||
{
|
||||
this.masterGain = this.context.createGainNode();
|
||||
|
@ -280,6 +288,11 @@ Phaser.SoundManager.prototype = {
|
|||
*/
|
||||
stopAll: function () {
|
||||
|
||||
if (this.noAudio)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i])
|
||||
|
@ -297,6 +310,11 @@ Phaser.SoundManager.prototype = {
|
|||
*/
|
||||
pauseAll: function () {
|
||||
|
||||
if (this.noAudio)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i])
|
||||
|
@ -314,6 +332,11 @@ Phaser.SoundManager.prototype = {
|
|||
*/
|
||||
resumeAll: function () {
|
||||
|
||||
if (this.noAudio)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._sounds.length; i++)
|
||||
{
|
||||
if (this._sounds[i])
|
||||
|
|
|
@ -390,10 +390,35 @@ Phaser.Tilemap.prototype = {
|
|||
}
|
||||
|
||||
var sprite;
|
||||
var found = false;
|
||||
|
||||
for (var i = 0, len = this.objects[name].length; i < len; i++)
|
||||
{
|
||||
if (this.objects[name][i].gid === gid)
|
||||
if (typeof this.objects[name][i].gid !== 'undefined' && typeof gid === 'number')
|
||||
{
|
||||
if (this.objects[name][i].gid === gid)
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof this.objects[name][i].id !== 'undefined' && typeof gid === 'number')
|
||||
{
|
||||
if (this.objects[name][i].id === gid)
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof this.objects[name][i].name !== 'undefined' && typeof gid === 'string')
|
||||
{
|
||||
if (this.objects[name][i].name === gid)
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
sprite = new CustomClass(this.game, this.objects[name][i].x, this.objects[name][i].y, key, frame);
|
||||
|
||||
|
@ -402,6 +427,9 @@ Phaser.Tilemap.prototype = {
|
|||
sprite.autoCull = autoCull;
|
||||
sprite.exists = exists;
|
||||
|
||||
sprite.width = this.objects[name][i].width;
|
||||
sprite.height = this.objects[name][i].height;
|
||||
|
||||
if (this.objects[name][i].rotation)
|
||||
{
|
||||
sprite.angle = this.objects[name][i].rotation;
|
||||
|
@ -1455,9 +1483,10 @@ Phaser.Tilemap.prototype = {
|
|||
* @param {number} [tileWidth] - The width of the tiles. If not given the map default is used.
|
||||
* @param {number} [tileHeight] - The height of the tiles. If not given the map default is used.
|
||||
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to get the tile from.
|
||||
* @param {boolean} [nonNull=false] - If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
|
||||
* @return {Phaser.Tile} The tile at the given coordinates.
|
||||
*/
|
||||
getTileWorldXY: function (x, y, tileWidth, tileHeight, layer) {
|
||||
getTileWorldXY: function (x, y, tileWidth, tileHeight, layer, nonNull) {
|
||||
|
||||
if (typeof tileWidth === 'undefined') { tileWidth = this.tileWidth; }
|
||||
if (typeof tileHeight === 'undefined') { tileHeight = this.tileHeight; }
|
||||
|
@ -1467,7 +1496,7 @@ Phaser.Tilemap.prototype = {
|
|||
x = this.game.math.snapToFloor(x, tileWidth) / tileWidth;
|
||||
y = this.game.math.snapToFloor(y, tileHeight) / tileHeight;
|
||||
|
||||
return this.getTile(x, y, layer);
|
||||
return this.getTile(x, y, layer, nonNull);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -12,7 +12,15 @@
|
|||
* By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior.
|
||||
*
|
||||
* @class Phaser.TilemapLayer
|
||||
* @extends {Phaser.Image}
|
||||
* @extends PIXI.Sprite
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Bounds
|
||||
* @extends Phaser.Component.BringToTop
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.InputEnabled
|
||||
* @extends Phaser.Component.Reset
|
||||
* @extends Phaser.Component.Smoothed
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
|
||||
|
@ -261,15 +269,17 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
|||
Phaser.TilemapLayer.prototype = Object.create(PIXI.Sprite.prototype);
|
||||
Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer;
|
||||
|
||||
var components = [
|
||||
Phaser.Component.Core.install.call(Phaser.TilemapLayer.prototype, [
|
||||
'Bounds',
|
||||
'BringToTop',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'InputEnabled',
|
||||
'Reset',
|
||||
'Smoothed'
|
||||
];
|
||||
]);
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.TilemapLayer.prototype, components);
|
||||
Phaser.TilemapLayer.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
/**
|
||||
* The shared double-copy canvas, created as needed.
|
||||
|
@ -306,9 +316,7 @@ Phaser.TilemapLayer.ensureSharedCopyCanvas = function () {
|
|||
*/
|
||||
Phaser.TilemapLayer.prototype.preUpdate = function() {
|
||||
|
||||
Phaser.Component.Core.preUpdate.call(this);
|
||||
|
||||
return true;
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
||||
|
||||
|
@ -320,7 +328,9 @@ Phaser.TilemapLayer.prototype.preUpdate = function() {
|
|||
*/
|
||||
Phaser.TilemapLayer.prototype.postUpdate = function () {
|
||||
|
||||
Phaser.Component.Core.prototype.postUpdate.call(this);
|
||||
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
||||
|
||||
// this.postUpdateCore();
|
||||
|
||||
// Stops you being able to auto-scroll the camera if it's not following a sprite
|
||||
var camera = this.game.camera;
|
||||
|
|
|
@ -441,9 +441,6 @@ Phaser.Color = {
|
|||
|
||||
var out = { r: r || 0, g: g || 0, b: b || 0, a: a || 1, h: h || 0, s: s || 0, l: l || 0, v: v || 0, color: 0, color32: 0, rgba: '' };
|
||||
|
||||
out.color = Phaser.Color.getColor(out.r, out.g, out.b);
|
||||
out.color32 = Phaser.Color.getColor32(out.a, out.r, out.g, out.b);
|
||||
|
||||
return Phaser.Color.updateColor(out);
|
||||
|
||||
},
|
||||
|
@ -459,6 +456,8 @@ Phaser.Color = {
|
|||
updateColor: function (out) {
|
||||
|
||||
out.rgba = 'rgba(' + out.r.toString() + ',' + out.g.toString() + ',' + out.b.toString() + ',' + out.a.toString() + ')';
|
||||
out.color = Phaser.Color.getColor(out.r, out.g, out.b);
|
||||
out.color32 = Phaser.Color.getColor32(out.a, out.r, out.g, out.b);
|
||||
|
||||
return out;
|
||||
|
||||
|
@ -615,6 +614,7 @@ Phaser.Color = {
|
|||
out.g = parseInt(result[2], 10);
|
||||
out.b = parseInt(result[3], 10);
|
||||
out.a = result[4] !== undefined ? parseFloat(result[4]) : 1;
|
||||
Phaser.Color.updateColor(out);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
6
tasks/manifests/creature.json
Normal file
6
tasks/manifests/creature.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
"src/animation/creature/gl-matrix.js",
|
||||
"src/animation/creature/CreatureMeshBone.js",
|
||||
"src/animation/creature/CreaturePixiJSRenderer.js",
|
||||
"src/gameobjects/Creature.js"
|
||||
]
|
|
@ -10,6 +10,7 @@
|
|||
"src/pixi/text/BitmapText.js",
|
||||
"src/pixi/display/Stage.js",
|
||||
|
||||
"src/pixi/utils/EventTarget.js",
|
||||
"src/pixi/utils/Utils.js",
|
||||
"src/pixi/utils/Polyk.js",
|
||||
|
||||
|
@ -45,6 +46,7 @@
|
|||
"src/pixi/textures/BaseTexture.js",
|
||||
"src/pixi/textures/Texture.js",
|
||||
"src/pixi/textures/RenderTexture.js",
|
||||
"src/pixi/textures/VideoTexture.js",
|
||||
|
||||
"src/pixi/filters/AbstractFilter.js",
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@ module.exports = {
|
|||
'!src/Intro.js',
|
||||
'!src/Outro.js',
|
||||
'!src/pixi/**/*',
|
||||
'!src/physics/p2/p2.js'
|
||||
'!src/physics/p2/p2.js',
|
||||
'!src/animation/creature/gl-matrix.js',
|
||||
'!src/animation/creature/CreatureMeshBone.js',
|
||||
'!src/animation/creature/CreaturePixiJSRenderer.js',
|
||||
'!src/gameobjects/Creature.js'
|
||||
],
|
||||
options: { jshintrc: '.jshintrc' }
|
||||
},
|
||||
|
|
2
typescript/phaser.comments.d.ts
vendored
2
typescript/phaser.comments.d.ts
vendored
|
@ -10540,7 +10540,7 @@ declare module Phaser {
|
|||
|
||||
apply(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
|
||||
applyInverse(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
|
||||
fromArray(array: number[]);
|
||||
fromArray(array: number[]): void;
|
||||
toArray(transpose: boolean): number[];
|
||||
translate(x: number, y: number): Phaser.Matrix;
|
||||
scale(x: number, y: number): Phaser.Matrix;
|
||||
|
|
4
typescript/phaser.d.ts
vendored
4
typescript/phaser.d.ts
vendored
|
@ -2056,7 +2056,7 @@ declare module Phaser {
|
|||
|
||||
apply(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
|
||||
applyInverse(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
|
||||
fromArray(array: number[]);
|
||||
fromArray(array: number[]): void;
|
||||
toArray(transpose: boolean): number[];
|
||||
translate(x: number, y: number): Phaser.Matrix;
|
||||
scale(x: number, y: number): Phaser.Matrix;
|
||||
|
@ -4117,7 +4117,7 @@ declare module Phaser {
|
|||
world: Phaser.World;
|
||||
|
||||
create(): void;
|
||||
init(): void;
|
||||
init(...args: any[]): void;
|
||||
loadRender(): void;
|
||||
loadUpdate(): void;
|
||||
paused(): void;
|
||||
|
|
Loading…
Reference in a new issue