Skip to content

Commit ffd5ddc

Browse files
committed
Tidying up the repo and adding in new documentation.
1 parent 4a51ac4 commit ffd5ddc

375 files changed

Lines changed: 5008 additions & 33315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ <h1 class="page-title">Source: animation/Animation.js</h1>
382382
*/
383383
this.looped = looped;
384384

385+
/**
386+
* @property {boolean} looped - The loop state of the Animation.
387+
*/
388+
this.killOnComplete = false;
389+
385390
/**
386391
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
387392
* @default
@@ -443,10 +448,11 @@ <h1 class="page-title">Source: animation/Animation.js</h1>
443448
* @method Phaser.Animation#play
444449
* @memberof Phaser.Animation
445450
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
446-
* @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
451+
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
452+
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
447453
* @return {Phaser.Animation} - A reference to this Animation instance.
448454
*/
449-
play: function (frameRate, loop) {
455+
play: function (frameRate, loop, killOnComplete) {
450456

451457
if (typeof frameRate === 'number')
452458
{
@@ -460,6 +466,12 @@ <h1 class="page-title">Source: animation/Animation.js</h1>
460466
this.looped = loop;
461467
}
462468

469+
if (typeof killOnComplete !== 'undefined')
470+
{
471+
// Remove the parent sprite once the animation has finished?
472+
this.killOnComplete = killOnComplete;
473+
}
474+
463475
this.isPlaying = true;
464476
this.isFinished = false;
465477

@@ -621,6 +633,11 @@ <h1 class="page-title">Source: animation/Animation.js</h1>
621633
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
622634
}
623635

636+
if (this.killOnComplete)
637+
{
638+
this._parent.kill();
639+
}
640+
624641
}
625642

626643
};
@@ -765,7 +782,7 @@ <h1 class="page-title">Source: animation/Animation.js</h1>
765782

766783
<span class="jsdoc-message">
767784
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a>
768-
on Thu Oct 03 2013 02:35:44 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
785+
on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
769786
</span>
770787
</footer>
771788
</div>
Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
359359
*/
360360
this.updateIfVisible = true;
361361

362+
/**
363+
* @property {boolean} isLoaded - Set to true once animation data has been loaded.
364+
* @default
365+
*/
366+
this.isLoaded = false;
367+
362368
/**
363369
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
364370
* @private
@@ -394,6 +400,7 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
394400

395401
this._frameData = frameData;
396402
this.frame = 0;
403+
this.isLoaded = true;
397404

398405
},
399406

@@ -420,7 +427,19 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
420427
frameRate = frameRate || 60;
421428

422429
if (typeof loop === 'undefined') { loop = false; }
423-
if (typeof useNumericIndex === 'undefined') { useNumericIndex = true; }
430+
431+
// If they didn't set the useNumericIndex then let's at least try and guess it
432+
if (typeof useNumericIndex === 'undefined')
433+
{
434+
if (frames && typeof frames[0] === 'number')
435+
{
436+
useNumericIndex = true;
437+
}
438+
else
439+
{
440+
useNumericIndex = false;
441+
}
442+
}
424443

425444
// Create the signals the AnimationManager will emit
426445
if (this.sprite.events.onAnimationStart == null)
@@ -484,24 +503,25 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
484503
* @method Phaser.AnimationManager#play
485504
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
486505
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
487-
* @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
506+
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
507+
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
488508
* @return {Phaser.Animation} A reference to playing Animation instance.
489509
*/
490-
play: function (name, frameRate, loop) {
510+
play: function (name, frameRate, loop, killOnComplete) {
491511

492512
if (this._anims[name])
493513
{
494514
if (this.currentAnim == this._anims[name])
495515
{
496516
if (this.currentAnim.isPlaying == false)
497517
{
498-
return this.currentAnim.play(frameRate, loop);
518+
return this.currentAnim.play(frameRate, loop, killOnComplete);
499519
}
500520
}
501521
else
502522
{
503523
this.currentAnim = this._anims[name];
504-
return this.currentAnim.play(frameRate, loop);
524+
return this.currentAnim.play(frameRate, loop, killOnComplete);
505525
}
506526
}
507527

@@ -562,6 +582,18 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
562582

563583
},
564584

585+
/**
586+
* Refreshes the current frame data back to the parent Sprite and also resets the texture data.
587+
*
588+
* @method Phaser.AnimationManager#refreshFrame
589+
*/
590+
refreshFrame: function () {
591+
592+
this.sprite.currentFrame = this.currentFrame;
593+
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
594+
595+
},
596+
565597
/**
566598
* Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation.
567599
*
@@ -650,7 +682,7 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
650682

651683
set: function (value) {
652684

653-
if (this._frameData && this._frameData.getFrame(value) !== null)
685+
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null)
654686
{
655687
this.currentFrame = this._frameData.getFrame(value);
656688
this._frameIndex = value;
@@ -679,7 +711,7 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
679711

680712
set: function (value) {
681713

682-
if (this._frameData && this._frameData.getFrameByName(value) !== null)
714+
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null)
683715
{
684716
this.currentFrame = this._frameData.getFrameByName(value);
685717
this._frameIndex = this.currentFrame.index;
@@ -714,7 +746,7 @@ <h1 class="page-title">Source: animation/AnimationManager.js</h1>
714746

715747
<span class="jsdoc-message">
716748
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a>
717-
on Thu Oct 03 2013 02:35:44 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
749+
on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
718750
</span>
719751
</footer>
720752
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ <h1 class="page-title">Source: animation/AnimationParser.js</h1>
660660

661661
<span class="jsdoc-message">
662662
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a>
663-
on Thu Oct 03 2013 02:35:44 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
663+
on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
664664
</span>
665665
</footer>
666666
</div>
Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
379379
*/
380380
this._tilemaps = {};
381381

382+
/**
383+
* @property {object} _tilesets - Tileset key-value container.
384+
* @private
385+
*/
386+
this._tilesets = {};
382387

383388
this.addDefaultImage();
384389

@@ -441,22 +446,44 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
441446

442447
},
443448

449+
/**
450+
* Add a new tile set in to the cache.
451+
*
452+
* @method Phaser.Cache#addTileset
453+
* @param {string} key - The unique key by which you will reference this object.
454+
* @param {string} url - URL of this tile set file.
455+
* @param {object} data - Extra tile set data.
456+
* @param {number} tileWidth - Width of the sprite sheet.
457+
* @param {number} tileHeight - Height of the sprite sheet.
458+
* @param {number} tileMax - How many tiles stored in the sprite sheet.
459+
* @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here.
460+
* @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here.
461+
*/
462+
addTileset: function (key, url, data, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
463+
464+
this._tilesets[key] = { url: url, data: data, tileWidth: tileWidth, tileHeight: tileHeight, tileMargin: tileMargin, tileSpacing: tileSpacing };
465+
466+
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
467+
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
468+
469+
this._tilesets[key].tileData = Phaser.TilemapParser.tileset(this.game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing);
470+
471+
},
472+
444473
/**
445474
* Add a new tilemap.
446475
*
447476
* @method Phaser.Cache#addTilemap
448477
* @param {string} key - The unique key by which you will reference this object.
449478
* @param {string} url - URL of the tilemap image.
450-
* @param {object} data - Tilemap data.
451479
* @param {object} mapData - The tilemap data object.
452480
* @param {number} format - The format of the tilemap data.
453481
*/
454-
addTilemap: function (key, url, data, mapData, format) {
482+
addTilemap: function (key, url, mapData, format) {
455483

456-
this._tilemaps[key] = { url: url, data: data, spriteSheet: true, mapData: mapData, format: format };
484+
this._tilemaps[key] = { url: url, data: mapData, format: format };
457485

458-
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
459-
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
486+
this._tilemaps[key].layers = Phaser.TilemapParser.parse(this.game, mapData, format);
460487

461488
},
462489

@@ -520,16 +547,31 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
520547
*/
521548
addDefaultImage: function () {
522549

523-
this._images['__default'] = { url: null, data: null, spriteSheet: false };
550+
var img = new Image();
551+
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
552+
553+
this._images['__default'] = { url: null, data: img, spriteSheet: false };
524554
this._images['__default'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
525555

526-
var base = new PIXI.BaseTexture();
527-
base.width = 32;
528-
base.height = 32;
529-
base.hasLoaded = true; // avoids a hanging event listener
556+
PIXI.BaseTextureCache['__default'] = new PIXI.BaseTexture(img);
557+
PIXI.TextureCache['__default'] = new PIXI.Texture(PIXI.BaseTextureCache['__default']);
530558

531-
PIXI.BaseTextureCache['__default'] = base;
532-
PIXI.TextureCache['__default'] = new PIXI.Texture(base);
559+
},
560+
561+
/**
562+
* Add a new text data.
563+
*
564+
* @method Phaser.Cache#addText
565+
* @param {string} key - Asset key for the text data.
566+
* @param {string} url - URL of this text data file.
567+
* @param {object} data - Extra text data.
568+
*/
569+
addText: function (key, url, data) {
570+
571+
this._text[key] = {
572+
url: url,
573+
data: data
574+
};
533575

534576
},
535577

@@ -641,23 +683,6 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
641683
this._sounds[key].decoded = true;
642684
this._sounds[key].isDecoding = false;
643685

644-
},
645-
646-
/**
647-
* Add a new text data.
648-
*
649-
* @method Phaser.Cache#addText
650-
* @param {string} key - Asset key for the text data.
651-
* @param {string} url - URL of this text data file.
652-
* @param {object} data - Extra text data.
653-
*/
654-
addText: function (key, url, data) {
655-
656-
this._text[key] = {
657-
url: url,
658-
data: data
659-
};
660-
661686
},
662687

663688
/**
@@ -712,14 +737,50 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
712737
return null;
713738
},
714739

740+
/**
741+
* Get tile set image data by key.
742+
*
743+
* @method Phaser.Cache#getTileSetImage
744+
* @param {string} key - Asset key of the image you want.
745+
* @return {object} The image data you want.
746+
*/
747+
getTilesetImage: function (key) {
748+
749+
if (this._tilesets[key])
750+
{
751+
return this._tilesets[key].data;
752+
}
753+
754+
return null;
755+
756+
},
757+
758+
/**
759+
* Get tile set image data by key.
760+
*
761+
* @method Phaser.Cache#getTileset
762+
* @param {string} key - Asset key of the image you want.
763+
* @return {Phaser.Tileset} The tileset data. The tileset image is in the data property, the tile data in tileData.
764+
*/
765+
getTileset: function (key) {
766+
767+
if (this._tilesets[key])
768+
{
769+
return this._tilesets[key].tileData;
770+
}
771+
772+
return null;
773+
774+
},
775+
715776
/**
716777
* Get tilemap data by key.
717778
*
718779
* @method Phaser.Cache#getTilemap
719780
* @param {string} key - Asset key of the tilemap you want.
720-
* @return {Phaser.Tilemap} The tilemap data. The tileset image is in the data property, the map data in mapData.
781+
* @return {Object} The tilemap data. The tileset image is in the data property, the map data in mapData.
721782
*/
722-
getTilemap: function (key) {
783+
getTilemapData: function (key) {
723784

724785
if (this._tilemaps[key])
725786
{
@@ -1077,7 +1138,7 @@ <h1 class="page-title">Source: loader/Cache.js</h1>
10771138

10781139
<span class="jsdoc-message">
10791140
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a>
1080-
on Thu Oct 03 2013 02:35:44 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
1141+
on Wed Oct 23 2013 13:51:58 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
10811142
</span>
10821143
</footer>
10831144
</div>

0 commit comments

Comments
 (0)