Пример #1
0
        /// <summary>
        /// Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames.
        /// </summary>
        public void addSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture)
        {
            string pszPath = CCFileUtils.fullPathFromRelativePath(pszPlist);
            Dictionary <string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);

            addSpriteFramesWithDictionary(dict, pobTexture);
        }
Пример #2
0
        /// <summary>
        /// Removes multiple Sprite Frames from a plist file.
        /// Sprite Frames stored in this file will be removed.
        /// It is convinient to call this method when a specific texture needs to be removed.
        /// @since v0.99.5
        /// </summary>
        public void removeSpriteFramesFromFile(string plist)
        {
            string path = CCFileUtils.fullPathFromRelativePath(plist);
            Dictionary <string, object> dict = CCFileUtils.dictionaryWithContentsOfFile(path);

            removeSpriteFramesFromDictionary(dict);
        }
Пример #3
0
        public bool initWithFile(string plistFile)
        {
            this.m_sPlistFile = CCFileUtils.fullPathFromRelativePath(plistFile);
            Dictionary <string, object> dictionary = CCFileUtils.dictionaryWithContentsOfFile(this.m_sPlistFile);

            return(this.initWithDictionary(dictionary));
        }
Пример #4
0
        /// <summary>
        /// Adds multiple Sprite Frames from a plist file.
        /// A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
        /// If you want to use another texture, you should use the addSpriteFramesWithFile:texture method.
        /// </summary>
        public void addSpriteFramesWithFile(string pszPlist)
        {
            string pszPath = CCFileUtils.fullPathFromRelativePath(pszPlist);
            Dictionary <string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);

            string texturePath = "";
            Dictionary <string, Object> metadataDict = dict.Keys.Contains("metadata") ?
                                                       (Dictionary <string, Object>)dict["metadata"] : null;

            if (metadataDict != null)
            {
                // C.A suggested to use metadataDict here instead of 'dict' to prevent the file not found error.
                // try to read  texture file name from meta data
                if (metadataDict.Keys.Contains("textureFileName"))
                {
                    texturePath = (valueForKey("textureFileName", metadataDict));
                }
            }

            if (!string.IsNullOrEmpty(texturePath))
            {
                // build texture path relative to plist file
                texturePath = CCFileUtils.fullPathFromRelativeFile(texturePath, pszPath);
            }
            else
            {
                // build texture path by replacing file path,case xna resource has no extension,so we move the image to images folder
                texturePath = pszPath;
                int index = pszPath.IndexOf("/");
                if (index < 0)
                {
                    index = pszPath.IndexOf(@"\");
                }
                if (index > 0)
                {
                    texturePath = pszPath.Substring(0, index) + "/images" + pszPath.Substring(index);
                }

                CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath);
            }

            CCTexture2D pTexture = CCTextureCache.sharedTextureCache().addImage(texturePath);

            if (pTexture != null)
            {
                addSpriteFramesWithDictionary(dict, pTexture);
            }
            else
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture");
            }
        }
Пример #5
0
        public void addSpriteFramesWithFile(string pszPlist)
        {
            Dictionary <string, object> item;
            string str = CCFileUtils.fullPathFromRelativePath(pszPlist);
            Dictionary <string, object> strs = CCFileUtils.dictionaryWithContentsOfFile(str);
            string str1 = "";

            if (strs.Keys.Contains <string>("metadata"))
            {
                item = (Dictionary <string, object>)strs["metadata"];
            }
            else
            {
                item = null;
            }
            Dictionary <string, object> strs1 = item;

            if (strs1 != null && strs1.Keys.Contains <string>("textureFileName"))
            {
                str1 = this.valueForKey("textureFileName", strs1);
            }
            if (string.IsNullOrEmpty(str1))
            {
                str1 = str;
                int num = str.IndexOf("/");
                if (num < 0)
                {
                    num = str.IndexOf("\\");
                }
                if (num > 0)
                {
                    str1 = string.Concat(str.Substring(0, num), "/images", str.Substring(num));
                }
                CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", new object[] { str1 });
            }
            else
            {
                str1 = CCFileUtils.fullPathFromRelativeFile(str1, str);
            }
            CCTexture2D cCTexture2D = CCTextureCache.sharedTextureCache().addImage(str1);

            if (cCTexture2D == null)
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture");
                return;
            }
            this.addSpriteFramesWithDictionary(strs, cCTexture2D);
        }
Пример #6
0
 public void removeSpriteFramesFromFile(string plist)
 {
     this.removeSpriteFramesFromDictionary(CCFileUtils.dictionaryWithContentsOfFile(CCFileUtils.fullPathFromRelativePath(plist)));
 }
Пример #7
0
        public void addSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture)
        {
            string str = CCFileUtils.fullPathFromRelativePath(pszPlist);

            this.addSpriteFramesWithDictionary(CCFileUtils.dictionaryWithContentsOfFile(str), pobTexture);
        }