Example #1
0
        public CCNode ReadNodeGraphFromFile(string fileName, object owner, CCSize parentSize)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            string strCCBFileName = fileName;
            string strSuffix      = ".ccbi";

            // Add ccbi suffix
            if (!CCBReader.EndsWith(strCCBFileName, strSuffix))
            {
                strCCBFileName += strSuffix;
            }

            string strPath = CCFileUtils.FullPathFromRelativePath(strCCBFileName);

            var pBytes = CCFileUtils.GetFileBytes(strPath);

            byte[] data = pBytes;

            CCNode ret = ReadNodeGraphFromData(data, owner, parentSize);

            return(ret);
        }
Example #2
0
        public CCNode ReadNodeGraphFromFile(string fileName, object owner, CCSize parentSize, ref CCBAnimationManager animationManager)
        {
            string pPath = CCFileUtils.FullPathFromRelativePath(fileName);

            byte[] pBytes = CCFileUtils.GetFileBytes(pPath);
            CCNode ret    = ReadNodeGraphFromData(pBytes, owner, parentSize, ref animationManager);

            return(ret);
        }
Example #3
0
        public void AddAnimationsWithFile(string plist)
        {
            Debug.Assert(!string.IsNullOrEmpty(plist), "Invalid texture file name");

            string path = CCFileUtils.FullPathFromRelativePath(plist);

            var             document = CCApplication.SharedApplication.Content.Load <PlistDocument>(path);
            PlistDictionary dict     = document.Root.AsDictionary;

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

            AddAnimationsWithDictionary(dict);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pszPlist"></param>
        /// <returns>The scope parameter derived from the pszPlist parameter.</returns>
        public string AddSpriteFramesWithFile(string pszPlist)
        {
            string pszPath = CCFileUtils.FullPathFromRelativePath(pszPlist);
            //Dictionary<string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);
            PlistDictionary dict = CCApplication.SharedApplication.Content.Load <PlistDocument>(pszPlist).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, pszPath);
            }
            else
            {
                // build texture path by replacing file extension
                texturePath = pszPath;

                // 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);
        }
        public bool InitWithFile(string plistFile)
        {
            bool bRet;

            m_sPlistFile = CCFileUtils.FullPathFromRelativePath(plistFile);

            //var content = CCApplication.SharedApplication.content.Load<CCContent>(m_sPlistFile);
            //PlistDocument dict = PlistDocument.Create(content.Content);

            var dict = CCApplication.SharedApplication.Content.Load <PlistDocument>(m_sPlistFile);

            Debug.Assert(dict != null, "Particles: file not found");
            Debug.Assert(dict.Root != null, "Particles: file not found");

            bRet = InitWithDictionary(dict.Root.AsDictionary);

            return(bRet);
        }
        /// <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);
        }
Example #7
0
        private void LoadTgAfile(string file)
        {
            Debug.Assert(!string.IsNullOrEmpty(file), "file must be non-nil");

            m_pTGAInfo = ImageTGA.Load(CCFileUtils.FullPathFromRelativePath(file));
        }