@@ -93,6 +93,23 @@ Phaser.Cache = function (game) {
9393 */
9494 this . onSoundUnlock = new Phaser . Signal ( ) ;
9595
96+ /**
97+ * @property {array } _cacheMap - Const to cache object look-up array.
98+ */
99+ this . _cacheMap = [ ] ;
100+
101+ this . _cacheMap [ Phaser . Cache . CANVAS ] = this . _canvases ;
102+ this . _cacheMap [ Phaser . Cache . IMAGE ] = this . _images ;
103+ this . _cacheMap [ Phaser . Cache . TEXTURE ] = this . _textures ;
104+ this . _cacheMap [ Phaser . Cache . SOUND ] = this . _sounds ;
105+ this . _cacheMap [ Phaser . Cache . TEXT ] = this . _text ;
106+ this . _cacheMap [ Phaser . Cache . PHYSICS ] = this . _physics ;
107+ this . _cacheMap [ Phaser . Cache . TILEMAP ] = this . _tilemaps ;
108+ this . _cacheMap [ Phaser . Cache . BINARY ] = this . _binary ;
109+ this . _cacheMap [ Phaser . Cache . BITMAPDATA ] = this . _bitmapDatas ;
110+ this . _cacheMap [ Phaser . Cache . BITMAPFONT ] = this . _bitmapFont ;
111+ this . _cacheMap [ Phaser . Cache . JSON ] = this . _json ;
112+
96113} ;
97114
98115/**
@@ -632,15 +649,16 @@ Phaser.Cache.prototype = {
632649 } ,
633650
634651 /**
635- * Checks if an image key exists.
652+ * Checks if a key for the given cache object type exists.
636653 *
637- * @method Phaser.Cache#checkImageKey
654+ * @method Phaser.Cache#checkKey
655+ * @param {number } type - The Cache type to check against. I.e. Phaser.Cache.CANVAS, Phaser.Cache.IMAGE, Phaser.Cache.JSON, etc.
638656 * @param {string } key - Asset key of the image to check is in the Cache.
639657 * @return {boolean } True if the key exists, otherwise false.
640658 */
641- checkImageKey : function ( key ) {
659+ checkKey : function ( type , key ) {
642660
643- if ( this . _images [ key ] )
661+ if ( this . _cacheMap [ type ] [ key ] )
644662 {
645663 return true ;
646664 }
@@ -649,6 +667,149 @@ Phaser.Cache.prototype = {
649667
650668 } ,
651669
670+ /**
671+ * Checks if the given key exists in the Canvas Cache.
672+ *
673+ * @method Phaser.Cache#checkCanvasKey
674+ * @param {string } key - Asset key of the image to check is in the Cache.
675+ * @return {boolean } True if the key exists, otherwise false.
676+ */
677+ checkCanvasKey : function ( key ) {
678+
679+ return this . checkKey ( Phaser . Cache . CANVAS , key ) ;
680+
681+ } ,
682+
683+ /**
684+ * Checks if the given key exists in the Image Cache. Note that this also includes Texture Atlases, Sprite Sheets and Retro Fonts.
685+ *
686+ * @method Phaser.Cache#checkImageKey
687+ * @param {string } key - Asset key of the image to check is in the Cache.
688+ * @return {boolean } True if the key exists, otherwise false.
689+ */
690+ checkImageKey : function ( key ) {
691+
692+ return this . checkKey ( Phaser . Cache . IMAGE , key ) ;
693+
694+ } ,
695+
696+ /**
697+ * Checks if the given key exists in the Texture Cache.
698+ *
699+ * @method Phaser.Cache#checkTextureKey
700+ * @param {string } key - Asset key of the image to check is in the Cache.
701+ * @return {boolean } True if the key exists, otherwise false.
702+ */
703+ checkTextureKey : function ( key ) {
704+
705+ return this . checkKey ( Phaser . Cache . TEXTURE , key ) ;
706+
707+ } ,
708+
709+ /**
710+ * Checks if the given key exists in the Sound Cache.
711+ *
712+ * @method Phaser.Cache#checkSoundKey
713+ * @param {string } key - Asset key of the image to check is in the Cache.
714+ * @return {boolean } True if the key exists, otherwise false.
715+ */
716+ checkSoundKey : function ( key ) {
717+
718+ return this . checkKey ( Phaser . Cache . SOUND , key ) ;
719+
720+ } ,
721+
722+ /**
723+ * Checks if the given key exists in the Text Cache.
724+ *
725+ * @method Phaser.Cache#checkTextKey
726+ * @param {string } key - Asset key of the image to check is in the Cache.
727+ * @return {boolean } True if the key exists, otherwise false.
728+ */
729+ checkTextKey : function ( key ) {
730+
731+ return this . checkKey ( Phaser . Cache . TEXT , key ) ;
732+
733+ } ,
734+
735+ /**
736+ * Checks if the given key exists in the Physics Cache.
737+ *
738+ * @method Phaser.Cache#checkPhysicsKey
739+ * @param {string } key - Asset key of the image to check is in the Cache.
740+ * @return {boolean } True if the key exists, otherwise false.
741+ */
742+ checkPhysicsKey : function ( key ) {
743+
744+ return this . checkKey ( Phaser . Cache . PHYSICS , key ) ;
745+
746+ } ,
747+
748+ /**
749+ * Checks if the given key exists in the Tilemap Cache.
750+ *
751+ * @method Phaser.Cache#checkTilemapKey
752+ * @param {string } key - Asset key of the image to check is in the Cache.
753+ * @return {boolean } True if the key exists, otherwise false.
754+ */
755+ checkTilemapKey : function ( key ) {
756+
757+ return this . checkKey ( Phaser . Cache . TILEMAP , key ) ;
758+
759+ } ,
760+
761+ /**
762+ * Checks if the given key exists in the Binary Cache.
763+ *
764+ * @method Phaser.Cache#checkBinaryKey
765+ * @param {string } key - Asset key of the image to check is in the Cache.
766+ * @return {boolean } True if the key exists, otherwise false.
767+ */
768+ checkBinaryKey : function ( key ) {
769+
770+ return this . checkKey ( Phaser . Cache . BINARY , key ) ;
771+
772+ } ,
773+
774+ /**
775+ * Checks if the given key exists in the BitmapData Cache.
776+ *
777+ * @method Phaser.Cache#checkBitmapDataKey
778+ * @param {string } key - Asset key of the image to check is in the Cache.
779+ * @return {boolean } True if the key exists, otherwise false.
780+ */
781+ checkBitmapDataKey : function ( key ) {
782+
783+ return this . checkKey ( Phaser . Cache . BITMAPDATA , key ) ;
784+
785+ } ,
786+
787+ /**
788+ * Checks if the given key exists in the BitmapFont Cache.
789+ *
790+ * @method Phaser.Cache#checkBitmapFontKey
791+ * @param {string } key - Asset key of the image to check is in the Cache.
792+ * @return {boolean } True if the key exists, otherwise false.
793+ */
794+ checkBitmapFontKey : function ( key ) {
795+
796+ return this . checkKey ( Phaser . Cache . BITMAPFONT , key ) ;
797+
798+ } ,
799+
800+ /**
801+ * Checks if the given key exists in the JSON Cache.
802+ *
803+ * @method Phaser.Cache#checkJSONKey
804+ * @param {string } key - Asset key of the image to check is in the Cache.
805+ * @return {boolean } True if the key exists, otherwise false.
806+ */
807+ checkJSONKey : function ( key ) {
808+
809+ return this . checkKey ( Phaser . Cache . JSON , key ) ;
810+
811+ } ,
812+
652813 /**
653814 * Get image data by key.
654815 *
0 commit comments