mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
Tilemap.createCollisionObjects will parse Tiled data for objectgroups and convert polyline instances into physics objects you can collide with in the world.
After defining tiles that collide on a Tilemap, you need to call Tilemap.generateCollisionData(layer) to populate the physics world with the data required. Debug.renderPhysicsBody updated to take camera location and body rotation into account. Body movement functions put back to velocity :) Updated to latest dev version of pixi and latest p2.js Updated docs
This commit is contained in:
+340
-54
@@ -58,6 +58,10 @@
|
||||
<a href="Phaser.BitmapData.html">BitmapData</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapFont.html">BitmapFont</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapText.html">BitmapText</a>
|
||||
</li>
|
||||
@@ -90,10 +94,6 @@
|
||||
<a href="Phaser.Device.html">Device</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.DOMSprite.html">DOMSprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Easing.html">Easing</a>
|
||||
</li>
|
||||
@@ -142,6 +142,10 @@
|
||||
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Ellipse.html">Ellipse</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Events.html">Events</a>
|
||||
</li>
|
||||
@@ -250,10 +254,6 @@
|
||||
<a href="Phaser.Physics.Arcade.html">Arcade</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Plugin.html">Plugin</a>
|
||||
</li>
|
||||
@@ -314,6 +314,10 @@
|
||||
<a href="Phaser.Sprite.html">Sprite</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Stage.html">Stage</a>
|
||||
</li>
|
||||
@@ -412,6 +416,10 @@
|
||||
<a href="global.html#canUseNewCanvasBlendModes">canUseNewCanvasBlendModes</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#getBounds">getBounds</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#getNextPowerOfTwo">getNextPowerOfTwo</a>
|
||||
</li>
|
||||
@@ -500,6 +508,12 @@ Phaser.Cache = function (game) {
|
||||
*/
|
||||
this._text = {};
|
||||
|
||||
/**
|
||||
* @property {object} _physics - Physics data key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._physics = {};
|
||||
|
||||
/**
|
||||
* @property {object} _tilemaps - Tilemap key-value container.
|
||||
* @private
|
||||
@@ -518,6 +532,12 @@ Phaser.Cache = function (game) {
|
||||
*/
|
||||
this._bitmapDatas = {};
|
||||
|
||||
/**
|
||||
* @property {object} _bitmapFont - BitmapFont key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._bitmapFont = {};
|
||||
|
||||
this.addDefaultImage();
|
||||
this.addMissingImage();
|
||||
|
||||
@@ -528,10 +548,71 @@ Phaser.Cache = function (game) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.CANVAS = 1;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.IMAGE = 2;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.TEXTURE = 3;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.SOUND = 4;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.TEXT = 5;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.PHYSICS = 6;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.TILEMAP = 7;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.BINARY = 8;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.BITMAPDATA = 9;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
Phaser.Cache.BITMAPFONT = 10;
|
||||
|
||||
Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new canvas object in to the cache.
|
||||
*
|
||||
* @method Phaser.Cache#addCanvas
|
||||
* @param {string} key - Asset key for this canvas.
|
||||
* @param {HTMLCanvasElement} canvas - Canvas DOM element.
|
||||
@@ -545,6 +626,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a binary object in to the cache.
|
||||
*
|
||||
* @method Phaser.Cache#addBinary
|
||||
* @param {string} key - Asset key for this binary data.
|
||||
* @param {object} binaryData - The binary object to be addded to the cache.
|
||||
@@ -557,6 +639,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a BitmapData object in to the cache.
|
||||
*
|
||||
* @method Phaser.Cache#addBitmapData
|
||||
* @param {string} key - Asset key for this BitmapData.
|
||||
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
|
||||
@@ -585,6 +668,19 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a Phaser.BitmapFont in to the cache.
|
||||
*
|
||||
* @method Phaser.Cache#addBitmapFont
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {Phaser.BitmapFont} texture - The BitmapFont object to be stored. This can be applied to any Image/Sprite as a texture.
|
||||
*/
|
||||
addBitmapFont: function (key, texture) {
|
||||
|
||||
this._bitmapFont[key] = texture;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new sprite sheet in to the cache.
|
||||
*
|
||||
@@ -610,7 +706,7 @@ Phaser.Cache.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new tilemap.
|
||||
* Add a new tilemap to the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#addTilemap
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
@@ -625,7 +721,7 @@ Phaser.Cache.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new texture atlas.
|
||||
* Add a new texture atlas to the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#addTextureAtlas
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
@@ -657,23 +753,39 @@ Phaser.Cache.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new Bitmap Font.
|
||||
* Add a new Bitmap Font to the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#addBitmapFont
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {string} url - URL of this font xml file.
|
||||
* @param {object} data - Extra font data.
|
||||
* @param xmlData {object} Texture atlas frames data.
|
||||
* @param {object} xmlData - Texture atlas frames data.
|
||||
* @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.
|
||||
*/
|
||||
addBitmapFont: function (key, url, data, xmlData) {
|
||||
addBitmapFont: function (key, url, data, xmlData, xSpacing, ySpacing) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: true };
|
||||
|
||||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
||||
|
||||
Phaser.LoaderParser.bitmapFont(this.game, xmlData, key);
|
||||
// this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, xmlData, key);
|
||||
Phaser.LoaderParser.bitmapFont(this.game, xmlData, key, xSpacing, ySpacing);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new physics data object to the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#addTilemap
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {string} url - URL of the physics json data.
|
||||
* @param {object} JSONData - The physics data object (a JSON file).
|
||||
* @param {number} format - The format of the physics data.
|
||||
*/
|
||||
addPhysicsData: function (key, url, JSONData, format) {
|
||||
|
||||
this._physics[key] = { url: url, data: JSONData, format: format };
|
||||
|
||||
},
|
||||
|
||||
@@ -681,6 +793,7 @@ Phaser.Cache.prototype = {
|
||||
* Adds a default image to be used in special cases such as WebGL Filters. Is mapped to the key __default.
|
||||
*
|
||||
* @method Phaser.Cache#addDefaultImage
|
||||
* @protected
|
||||
*/
|
||||
addDefaultImage: function () {
|
||||
|
||||
@@ -699,6 +812,7 @@ Phaser.Cache.prototype = {
|
||||
* Adds an image to be used when a key is wrong / missing. Is mapped to the key __missing.
|
||||
*
|
||||
* @method Phaser.Cache#addMissingImage
|
||||
* @protected
|
||||
*/
|
||||
addMissingImage: function () {
|
||||
|
||||
@@ -723,10 +837,7 @@ Phaser.Cache.prototype = {
|
||||
*/
|
||||
addText: function (key, url, data) {
|
||||
|
||||
this._text[key] = {
|
||||
url: url,
|
||||
data: data
|
||||
};
|
||||
this._text[key] = { url: url, data: data };
|
||||
|
||||
},
|
||||
|
||||
@@ -883,6 +994,64 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a BitmapFont object from the cache by its key.
|
||||
*
|
||||
* @method Phaser.Cache#getBitmapFont
|
||||
* @param {string} key - Asset key of the BitmapFont object to retrieve from the Cache.
|
||||
* @return {Phaser.BitmapFont} The requested BitmapFont object if found, or null if not.
|
||||
*/
|
||||
getBitmapFont: function (key) {
|
||||
|
||||
if (this._bitmapFont[key])
|
||||
{
|
||||
return this._bitmapFont[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getBitmapFont: Invalid key: "' + key + '"');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a physics data object from the cache by its key. You can get either the entire data set or just a single object from it.
|
||||
*
|
||||
* @method Phaser.Cache#getPhysicsData
|
||||
* @param {string} key - Asset key of the physics data object to retrieve from the Cache.
|
||||
* @param {string} [object=null] - If specified it will return just the physics object that is part of the given key, if null it will return them all.
|
||||
* @return {object} The requested physics object data if found.
|
||||
*/
|
||||
getPhysicsData: function (key, object) {
|
||||
|
||||
if (typeof object === 'undefined' || object === null)
|
||||
{
|
||||
// Get 'em all
|
||||
if (this._physics[key])
|
||||
{
|
||||
return this._physics[key].data;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getPhysicsData: Invalid key: "' + key + '"');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._physics[key] && this._physics[key].data[object])
|
||||
{
|
||||
return this._physics[key].data[object][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('Phaser.Cache.getPhysicsData: Invalid key/object: "' + key + ' / ' + object + '"');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if an image key exists.
|
||||
*
|
||||
@@ -958,6 +1127,23 @@ Phaser.Cache.prototype = {
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces a set of frameData with a new Phaser.FrameData object.
|
||||
*
|
||||
* @method Phaser.Cache#updateFrameData
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {number} frameData - The new FrameData.
|
||||
*/
|
||||
updateFrameData: function (key, frameData) {
|
||||
|
||||
if (this._images[key])
|
||||
{
|
||||
this._images[key].spriteSheet = true;
|
||||
this._images[key].frameData = frameData;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a single frame out of a frameData set by key.
|
||||
*
|
||||
@@ -1174,14 +1360,63 @@ Phaser.Cache.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the cache keys from a given array of objects.
|
||||
* Normally you don't call this directly but instead use getImageKeys, getSoundKeys, etc.
|
||||
* Gets all keys used by the Cache for the given data type.
|
||||
*
|
||||
* @method Phaser.Cache#getKeys
|
||||
* @param {Array} array - An array of items to return the keys for.
|
||||
* @param {number} [type=Phaser.Cache.IMAGE] - The type of Cache keys you wish to get. Can be Cache.CANVAS, Cache.IMAGE, Cache.SOUND, etc.
|
||||
* @return {Array} The array of item keys.
|
||||
*/
|
||||
getKeys: function (array) {
|
||||
getKeys: function (type) {
|
||||
|
||||
var array = null;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Phaser.Cache.CANVAS:
|
||||
array = this._canvases;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.IMAGE:
|
||||
array = this._images;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.TEXTURE:
|
||||
array = this._textures;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.SOUND:
|
||||
array = this._sounds;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.TEXT:
|
||||
array = this._text;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.PHYSICS:
|
||||
array = this._physics;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.TILEMAP:
|
||||
array = this._tilemaps;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.BINARY:
|
||||
array = this._binary;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.BITMAPDATA:
|
||||
array = this._bitmapDatas;
|
||||
break;
|
||||
|
||||
case Phaser.Cache.BITMAPFONT:
|
||||
array = this._bitmapFont;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!array)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var output = [];
|
||||
|
||||
@@ -1197,36 +1432,6 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the keys of Images in the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#getImageKeys
|
||||
* @return {Array} The string based keys in the Cache.
|
||||
*/
|
||||
getImageKeys: function () {
|
||||
return this.getKeys(this._images);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the keys of Sounds in the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#getSoundKeys
|
||||
* @return {Array} The string based keys in the Cache.
|
||||
*/
|
||||
getSoundKeys: function () {
|
||||
return this.getKeys(this._sounds);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the keys of Text Files in the Cache.
|
||||
*
|
||||
* @method Phaser.Cache#getTextKeys
|
||||
* @return {Array} The string based keys in the Cache.
|
||||
*/
|
||||
getTextKeys: function () {
|
||||
return this.getKeys(this._text);
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a canvas from the cache.
|
||||
*
|
||||
@@ -1267,6 +1472,56 @@ Phaser.Cache.prototype = {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a physics data file from the cache.
|
||||
*
|
||||
* @method Phaser.Cache#removePhysics
|
||||
* @param {string} key - Key of the asset you want to remove.
|
||||
*/
|
||||
removePhysics: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a tilemap from the cache.
|
||||
*
|
||||
* @method Phaser.Cache#removeTilemap
|
||||
* @param {string} key - Key of the asset you want to remove.
|
||||
*/
|
||||
removeTilemap: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a binary file from the cache.
|
||||
*
|
||||
* @method Phaser.Cache#removeBinary
|
||||
* @param {string} key - Key of the asset you want to remove.
|
||||
*/
|
||||
removeBinary: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a bitmap data from the cache.
|
||||
*
|
||||
* @method Phaser.Cache#removeBitmapData
|
||||
* @param {string} key - Key of the asset you want to remove.
|
||||
*/
|
||||
removeBitmapData: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a bitmap font from the cache.
|
||||
*
|
||||
* @method Phaser.Cache#removeBitmapFont
|
||||
* @param {string} key - Key of the asset you want to remove.
|
||||
*/
|
||||
removeBitmapFont: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears the cache. Removes every local cache object reference.
|
||||
*
|
||||
@@ -1293,6 +1548,37 @@ Phaser.Cache.prototype = {
|
||||
{
|
||||
delete this._text[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._textures)
|
||||
{
|
||||
delete this._textures[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._physics)
|
||||
{
|
||||
delete this._physics[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._tilemaps)
|
||||
{
|
||||
delete this._tilemaps[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._binary)
|
||||
{
|
||||
delete this._binary[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._bitmapDatas)
|
||||
{
|
||||
delete this._bitmapDatas[item['key']];
|
||||
}
|
||||
|
||||
for (var item in this._bitmapFont)
|
||||
{
|
||||
delete this._bitmapFont[item['key']];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1319,7 +1605,7 @@ Phaser.Cache.prototype.constructor = Phaser.Cache;
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Sat Feb 08 2014 07:19:40 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Tue Feb 18 2014 03:01:16 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user