public void AddAnimationsWithFile(string plist)
        {
            Debug.Assert(!string.IsNullOrEmpty(plist), "Invalid texture file name");

            string path = CCFileUtils.FullPathFromRelativePath(plist);

            PlistDocument document = null;

            try
            {
                document = CCApplication.SharedApplication.Content.Load <PlistDocument>(path);
            }
            catch (System.Exception)
            {
                string xml = CCContent.LoadContentFile(path);
                if (xml != null)
                {
                    document = new PlistDocument(xml);
                }
            }
            if (document == null)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + path));
            }

            PlistDictionary dict = document.Root.AsDictionary;

            Debug.Assert(dict != null, "CCAnimationCache: File could not be found");

            AddAnimationsWithDictionary(dict);
        }
示例#2
0
        /// <summary>
        /// @brief Get resource file data
        /// @param[in]  pszFileName The resource file name which contain the path
        /// @param[in]  pszMode The read mode of the file
        /// @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
        /// @return if success,the pointer of data will be returned,or NULL is returned
        /// @warning If you get the file data succeed,you must delete it after used.
        /// </summary>
        /// <param name="pszFileName"></param>
        /// <returns></returns>
        public static string GetFileData(string pszFileName)
        {
            ContentManager content = CCApplication.SharedApplication.Content;
            CCContent      data    = content.Load <CCContent>(pszFileName);

            return(data.Content);
        }
        public void RemoveSpriteFramesFromFile(string plist)
        {
            //string path = CCFileUtils.fullPathFromRelativePath(plist);
            //Dictionary<string, object> dict = CCFileUtils.dictionaryWithContentsOfFile(path);
            PlistDocument document = null;

            try
            {
                document = CCApplication.SharedApplication.Content.Load <PlistDocument>(plist);
            }
            catch (System.Exception)
            {
                string xml = CCContent.LoadContentFile(plist);
                if (xml != null)
                {
                    document = new PlistDocument(xml);
                }
            }
            if (document == null)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + plist));
            }

            PlistDictionary dict = document.Root.AsDictionary;

            RemoveSpriteFramesFromDictionary(dict);
        }
        public bool InitWithFile(string plistFile)
        {
            bool bRet;

            m_sPlistFile = CCFileUtils.FullPathFromRelativePath(plistFile);

            PlistDocument doc = null;

            try
            {
                doc = CCApplication.SharedApplication.Content.Load <PlistDocument>(m_sPlistFile);
            }
            catch (Exception)
            {
                string xml = CCContent.LoadContentFile(m_sPlistFile);
                if (xml != null)
                {
                    doc = new PlistDocument(xml);
                }
            }
            if (doc == null)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + m_sPlistFile));
            }
            Debug.Assert(doc != null, "Particles: file not found");
            Debug.Assert(doc.Root != null, "Particles: file not found");

            bRet = InitWithDictionary(doc.Root.AsDictionary);

            return(bRet);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pszPlist"></param>
        /// <param name="pobTexture"></param>
        /// <param name="framePrefix"></param>
        /// <returns>The framePrefix parameter</returns>
        public string AddSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture, string framePrefix)
        {
            //string pszPath = CCFileUtils.fullPathFromRelativePath(pszPlist);
            //Dictionary<string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);
            PlistDocument document = null;

            try
            {
                document = CCApplication.SharedApplication.Content.Load <PlistDocument>(pszPlist);
            }
            catch (System.Exception)
            {
                string xml = CCContent.LoadContentFile(pszPlist);
                if (xml != null)
                {
                    document = new PlistDocument(xml);
                }
            }
            if (document == null)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + pszPlist));
            }

            PlistDictionary dict = document.Root.AsDictionary;

            AddSpriteFramesWithDictionary(dict, pobTexture, framePrefix);
            return(framePrefix);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pszPlist"></param>
        /// <returns>The scope parameter derived from the pszPlist parameter.</returns>
        public string AddSpriteFramesWithFile(string pszPlist)
        {
            string path = CCFileUtils.FullPathFromRelativePath(pszPlist);
            //Dictionary<string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);
            PlistDocument document = null;

            try
            {
                document = CCApplication.SharedApplication.Content.Load <PlistDocument>(path);
            }
            catch (System.Exception)
            {
                string xml = CCContent.LoadContentFile(path);
                if (xml != null)
                {
                    document = new PlistDocument(xml);
                }
            }
            if (document == null)
            {
                throw (new Microsoft.Xna.Framework.Content.ContentLoadException("Failed to load the particle definition file from " + path));
            }

            PlistDictionary dict         = document.Root.AsDictionary;
            string          texturePath  = "";
            PlistDictionary metadataDict = dict.ContainsKey("metadata") ? dict["metadata"].AsDictionary : null;

            string framePrefix = string.Empty;

            if (metadataDict != null)
            {
                // try to read  texture file name from meta data
                if (metadataDict.ContainsKey("textureFileName"))
                {
                    texturePath = metadataDict["textureFileName"].AsString;
                    framePrefix = ExtractPrefix(texturePath);
                }
            }

            if (!string.IsNullOrEmpty(texturePath))
            {
                // build texture path relative to plist file
                texturePath = CCFileUtils.FullPathFromRelativeFile(texturePath, path);
            }
            else
            {
                // build texture path by replacing file extension
                texturePath = path;

                // remove .xxx
                texturePath = CCFileUtils.RemoveExtension(texturePath);

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

            CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(texturePath);

            if (pTexture != null)
            {
                AddSpriteFramesWithDictionary(dict, pTexture, framePrefix);
            }
            else
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture");
            }
            return(framePrefix);
        }
示例#7
0
        protected virtual bool InitWithFNTFile(string fntFile)
        {
            string content = CCContent.LoadContentFile(fntFile);

            return(InitWithString(content, fntFile));
        }
        public bool Parse(string pszFile)
        {
            string content = CCContent.LoadContentFile(pszFile);

            return(Parse(content, content.Length));
        }
示例#9
0
 /// <summary>
 /// @brief Get resource file data
 /// @param[in]  pszFileName The resource file name which contain the path
 /// @param[in]  pszMode The read mode of the file
 /// @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
 /// @return if success,the pointer of data will be returned,or NULL is returned
 /// @warning If you get the file data succeed,you must delete it after used.
 /// </summary>
 /// <param name="pszFileName"></param>
 /// <returns></returns>
 public static string GetFileData(string pszFileName)
 {
     return(CCContent.LoadContentFile(pszFileName));
 }