Пример #1
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);
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #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 bool initWithTMXFile(string tmxFile)
 {
     this.m_pTilesets          = new List <CCTMXTilesetInfo>();
     this.m_pLayers            = new List <CCTMXLayerInfo>();
     this.m_sTMXFileName       = CCFileUtils.fullPathFromRelativePath(tmxFile);
     this.m_pObjectGroups      = new List <CCTMXObjectGroup>();
     this.m_pProperties        = new Dictionary <string, string>();
     this.m_pTileProperties    = new Dictionary <int, Dictionary <string, string> >();
     this.m_sCurrentString     = null;
     this.m_bStoringCharacters = false;
     this.m_nLayerAttribs      = 1;
     this.m_nParentElement     = 0;
     return(this.parseXMLFile(this.m_sTMXFileName));
 }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// initializes a TMX format witha  tmx file
        /// </summary>
        public bool initWithTMXFile(string tmxFile)
        {
            m_pTilesets       = new List <CCTMXTilesetInfo>();
            m_pLayers         = new List <CCTMXLayerInfo>();
            m_sTMXFileName    = CCFileUtils.fullPathFromRelativePath(tmxFile);
            m_pObjectGroups   = new List <CCTMXObjectGroup>();
            m_pProperties     = new Dictionary <string, string>();
            m_pTileProperties = new Dictionary <int, Dictionary <string, string> >();

            // tmp vars
            m_sCurrentString     = null;
            m_bStoringCharacters = false;
            m_nLayerAttribs      = (int)TMXLayerAttrib.TMXLayerAttribNone;
            m_nParentElement     = (int)TMXProperty.TMXPropertyNone;

            return(parseXMLFile(m_sTMXFileName));
        }
Пример #8
0
        public void startElement(object ctx, string name, string[] atts)
        {
            CCTMXMapInfo mUFirstGid          = this;
            string       str                 = name;
            Dictionary <string, string> strs = new Dictionary <string, string>();

            if (atts != null && atts[0] != null)
            {
                for (int i = 0; i + 1 < (int)atts.Length; i = i + 2)
                {
                    string str1 = atts[i];
                    strs.Add(str1, atts[i + 1]);
                }
            }
            if (str == "map")
            {
                string item = strs["version"];
                if (item != "1.0")
                {
                    CCLog.Log("cocos2d: TMXFormat: Unsupported TMX version: {0}", new object[] { item });
                }
                string item1 = strs["orientation"];
                if (item1 == "orthogonal")
                {
                    mUFirstGid.Orientation = 0;
                }
                else if (item1 == "isometric")
                {
                    mUFirstGid.Orientation = 2;
                }
                else if (item1 != "hexagonal")
                {
                    object[] orientation = new object[] { mUFirstGid.Orientation };
                    CCLog.Log("cocos2d: TMXFomat: Unsupported orientation: {0}", orientation);
                }
                else
                {
                    mUFirstGid.Orientation = 1;
                }
                CCSize cCSize = new CCSize()
                {
                    width  = ccUtils.ccParseFloat(strs["width"]),
                    height = ccUtils.ccParseFloat(strs["height"])
                };
                mUFirstGid.MapSize = cCSize;
                CCSize cCSize1 = new CCSize()
                {
                    width  = ccUtils.ccParseFloat(strs["tilewidth"]),
                    height = ccUtils.ccParseFloat(strs["tileheight"])
                };
                mUFirstGid.TileSize      = cCSize1;
                mUFirstGid.ParentElement = 1;
            }
            else if (str == "tileset")
            {
                if (!strs.Keys.Contains <string>("source"))
                {
                    CCTMXTilesetInfo cCTMXTilesetInfo = new CCTMXTilesetInfo()
                    {
                        m_sName     = strs["name"],
                        m_uFirstGid = ccUtils.ccParseInt(strs["firstgid"])
                    };
                    if (strs.Keys.Contains <string>("spacing"))
                    {
                        cCTMXTilesetInfo.m_uSpacing = ccUtils.ccParseInt(strs["spacing"]);
                    }
                    if (strs.Keys.Contains <string>("margin"))
                    {
                        cCTMXTilesetInfo.m_uMargin = ccUtils.ccParseInt(strs["margin"]);
                    }
                    CCSize cCSize2 = new CCSize()
                    {
                        width  = ccUtils.ccParseFloat(strs["tilewidth"]),
                        height = ccUtils.ccParseFloat(strs["tileheight"])
                    };
                    cCTMXTilesetInfo.m_tTileSize = cCSize2;
                    mUFirstGid.Tilesets.Add(cCTMXTilesetInfo);
                }
                else
                {
                    string item2 = strs["source"];
                    item2 = CCFileUtils.fullPathFromRelativeFile(item2, mUFirstGid.TMXFileName);
                    mUFirstGid.parseXMLFile(item2);
                }
            }
            else if (str == "tile")
            {
                CCTMXTilesetInfo            cCTMXTilesetInfo1 = mUFirstGid.Tilesets.LastOrDefault <CCTMXTilesetInfo>();
                Dictionary <string, string> strs1             = new Dictionary <string, string>();
                mUFirstGid.ParentGID = cCTMXTilesetInfo1.m_uFirstGid + ccUtils.ccParseInt(strs["id"]);
                mUFirstGid.TileProperties.Add(mUFirstGid.ParentGID, strs1);
                mUFirstGid.ParentElement = 5;
            }
            else if (str == "layer")
            {
                CCTMXLayerInfo cCTMXLayerInfo = new CCTMXLayerInfo()
                {
                    m_sName = strs["name"]
                };
                CCSize cCSize3 = new CCSize()
                {
                    width  = ccUtils.ccParseFloat(strs["width"]),
                    height = ccUtils.ccParseFloat(strs["height"])
                };
                cCTMXLayerInfo.m_tLayerSize = cCSize3;
                cCTMXLayerInfo.m_pTiles     = new int[(int)cCSize3.width * (int)cCSize3.height];
                if (!strs.Keys.Contains <string>("visible"))
                {
                    cCTMXLayerInfo.m_bVisible = true;
                }
                else
                {
                    cCTMXLayerInfo.m_bVisible = !(strs["visible"] == "0");
                }
                if (!strs.Keys.Contains <string>("opacity"))
                {
                    cCTMXLayerInfo.m_cOpacity = 255;
                }
                else
                {
                    string str2 = strs["opacity"];
                    cCTMXLayerInfo.m_cOpacity = (byte)(255f * ccUtils.ccParseFloat(str2));
                }
                float single = (strs.Keys.Contains <string>("x") ? ccUtils.ccParseFloat(strs["x"]) : 0f);
                cCTMXLayerInfo.m_tOffset = new CCPoint(single, (strs.Keys.Contains <string>("y") ? ccUtils.ccParseFloat(strs["y"]) : 0f));
                mUFirstGid.Layers.Add(cCTMXLayerInfo);
                mUFirstGid.ParentElement = 2;
            }
            else if (str == "objectgroup")
            {
                CCTMXObjectGroup cCTMXObjectGroup = new CCTMXObjectGroup()
                {
                    GroupName = strs["name"]
                };
                CCPoint cCPoint = new CCPoint();
                if (strs.ContainsKey("x"))
                {
                    cCPoint.x = ccUtils.ccParseFloat(strs["x"]) * mUFirstGid.TileSize.width;
                }
                if (strs.ContainsKey("y"))
                {
                    cCPoint.y = ccUtils.ccParseFloat(strs["y"]) * mUFirstGid.TileSize.height;
                }
                cCTMXObjectGroup.PositionOffset = cCPoint;
                mUFirstGid.ObjectGroups.Add(cCTMXObjectGroup);
                mUFirstGid.ParentElement = 3;
            }
            else if (str == "image")
            {
                CCTMXTilesetInfo cCTMXTilesetInfo2 = mUFirstGid.Tilesets.LastOrDefault <CCTMXTilesetInfo>();
                string           item3             = strs["source"];
                cCTMXTilesetInfo2.m_sSourceImage = CCFileUtils.fullPathFromRelativeFile(item3, mUFirstGid.TMXFileName);
            }
            else if (str == "data")
            {
                string str3 = (strs.ContainsKey("encoding") ? strs["encoding"] : "");
                string str4 = (strs.ContainsKey("compression") ? strs["compression"] : "");
                if (str3 == "base64")
                {
                    mUFirstGid.LayerAttribs      = mUFirstGid.LayerAttribs | 2;
                    mUFirstGid.StoringCharacters = true;
                    if (str4 == "gzip")
                    {
                        mUFirstGid.LayerAttribs = mUFirstGid.LayerAttribs | 4;
                    }
                    else if (str4 == "zlib")
                    {
                        mUFirstGid.LayerAttribs = mUFirstGid.LayerAttribs | 8;
                    }
                }
            }
            else if (str == "object")
            {
                CCTMXObjectGroup            cCTMXObjectGroup1 = mUFirstGid.ObjectGroups.LastOrDefault <CCTMXObjectGroup>();
                Dictionary <string, string> strs2             = new Dictionary <string, string>();
                string str5 = "name";
                strs2.Add(str5, (strs.ContainsKey("name") ? strs["name"] : ""));
                str5 = "type";
                strs2.Add(str5, (strs.ContainsKey("type") ? strs["type"] : ""));
                int num = ccUtils.ccParseInt(strs["x"]) + (int)cCTMXObjectGroup1.PositionOffset.x;
                str5 = "x";
                strs2.Add(str5, num.ToString());
                int mapSize = ccUtils.ccParseInt(strs["y"]) + (int)cCTMXObjectGroup1.PositionOffset.y;
                mapSize = (int)(mUFirstGid.MapSize.height * mUFirstGid.TileSize.height) - mapSize - (strs.ContainsKey("height") ? ccUtils.ccParseInt(strs["height"]) : 0);
                str5    = "y";
                strs2.Add(str5, mapSize.ToString());
                str5 = "width";
                strs2.Add(str5, (strs.ContainsKey("width") ? strs["width"] : ""));
                str5 = "height";
                strs2.Add(str5, (strs.ContainsKey("height") ? strs["height"] : ""));
                cCTMXObjectGroup1.Objects.Add(strs2);
                mUFirstGid.ParentElement = 4;
            }
            else if (str == "property")
            {
                if (mUFirstGid.ParentElement == 0)
                {
                    object[] objArray = new object[] { strs["name"], strs["value"] };
                    CCLog.Log("TMX tile map: Parent element is unsupported. Cannot add property named '{0}' with value '{1}'", objArray);
                }
                else if (mUFirstGid.ParentElement == 1)
                {
                    string item4 = strs["value"];
                    string item5 = strs["name"];
                    mUFirstGid.Properties.Add(item5, item4);
                }
                else if (mUFirstGid.ParentElement == 2)
                {
                    CCTMXLayerInfo cCTMXLayerInfo1 = mUFirstGid.Layers.LastOrDefault <CCTMXLayerInfo>();
                    string         item6           = strs["value"];
                    string         str6            = strs["name"];
                    cCTMXLayerInfo1.Properties.Add(str6, item6);
                }
                else if (mUFirstGid.ParentElement == 3)
                {
                    CCTMXObjectGroup cCTMXObjectGroup2 = mUFirstGid.ObjectGroups.LastOrDefault <CCTMXObjectGroup>();
                    string           item7             = strs["value"];
                    string           str7 = strs["name"];
                    cCTMXObjectGroup2.Properties.Add(str7, item7);
                }
                else if (mUFirstGid.ParentElement == 4)
                {
                    CCTMXObjectGroup            cCTMXObjectGroup3 = mUFirstGid.ObjectGroups.LastOrDefault <CCTMXObjectGroup>();
                    Dictionary <string, string> strs3             = cCTMXObjectGroup3.Objects.LastOrDefault <Dictionary <string, string> >();
                    strs3.Add(strs["name"], strs["value"]);
                }
                else if (mUFirstGid.ParentElement == 5)
                {
                    Dictionary <string, string> strs4 = mUFirstGid.TileProperties[mUFirstGid.ParentGID];
                    strs4.Add(strs["name"], strs["value"]);
                }
            }
            if (strs != null)
            {
                strs = null;
            }
        }
Пример #9
0
 public void removeSpriteFramesFromFile(string plist)
 {
     this.removeSpriteFramesFromDictionary(CCFileUtils.dictionaryWithContentsOfFile(CCFileUtils.fullPathFromRelativePath(plist)));
 }
Пример #10
0
        public void addSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture)
        {
            string str = CCFileUtils.fullPathFromRelativePath(pszPlist);

            this.addSpriteFramesWithDictionary(CCFileUtils.dictionaryWithContentsOfFile(str), pobTexture);
        }
Пример #11
0
        public bool initWithDictionary(Dictionary <string, object> dictionary)
        {
            bool flag = false;
            int  num  = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("maxParticles", dictionary)));

            if (this.initWithTotalParticles((uint)num))
            {
                this.m_fAngle           = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("angle", dictionary)));
                this.m_fAngleVar        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("angleVariance", dictionary)));
                this.m_fDuration        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("duration", dictionary)));
                this.m_tBlendFunc.src   = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("blendFuncSource", dictionary)));
                this.m_tBlendFunc.dst   = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("blendFuncDestination", dictionary)));
                this.m_tStartColor.r    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorRed", dictionary)));
                this.m_tStartColor.g    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorGreen", dictionary)));
                this.m_tStartColor.b    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorBlue", dictionary)));
                this.m_tStartColor.a    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorAlpha", dictionary)));
                this.m_tStartColorVar.r = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceRed", dictionary)));
                this.m_tStartColorVar.g = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceGreen", dictionary)));
                this.m_tStartColorVar.b = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceBlue", dictionary)));
                this.m_tStartColorVar.a = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceAlpha", dictionary)));
                this.m_tEndColor.r      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorRed", dictionary)));
                this.m_tEndColor.g      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorGreen", dictionary)));
                this.m_tEndColor.b      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorBlue", dictionary)));
                this.m_tEndColor.a      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorAlpha", dictionary)));
                this.m_tEndColorVar.r   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceRed", dictionary)));
                this.m_tEndColorVar.g   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceGreen", dictionary)));
                this.m_tEndColorVar.b   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceBlue", dictionary)));
                this.m_tEndColorVar.a   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceAlpha", dictionary)));
                this.m_fStartSize       = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startParticleSize", dictionary)));
                this.m_fStartSizeVar    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startParticleSizeVariance", dictionary)));
                this.m_fEndSize         = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishParticleSize", dictionary)));
                this.m_fEndSizeVar      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishParticleSizeVariance", dictionary)));
                float x = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionx", dictionary)));
                float y = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositiony", dictionary)));
                this.position        = new CCPoint(x, y);
                this.m_tPosVar.x     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionVariancex", dictionary)));
                this.m_tPosVar.y     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionVariancey", dictionary)));
                this.m_fStartSpin    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationStart", dictionary)));
                this.m_fStartSpinVar = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationStartVariance", dictionary)));
                this.m_fEndSpin      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationEnd", dictionary)));
                this.m_fEndSpinVar   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationEndVariance", dictionary)));
                this.m_nEmitterMode  = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("emitterType", dictionary)), NumberStyles.AllowDecimalPoint);
                if (this.m_nEmitterMode == 0)
                {
                    this.modeA.gravity.x = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("gravityx", dictionary)));
                    this.modeA.gravity.y = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("gravityy", dictionary)));
                    this.modeA.speed     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("speed", dictionary)));
                    this.modeA.speedVar  = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("speedVariance", dictionary)));
                    string str = this.valueForKey("radialAcceleration", dictionary);
                    this.modeA.radialAccel = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("radialAccelVariance", dictionary);
                    this.modeA.radialAccelVar = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("tangentialAcceleration", dictionary);
                    this.modeA.tangentialAccel = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("tangentialAccelVariance", dictionary);
                    this.modeA.tangentialAccelVar = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                }
                else
                {
                    if (this.m_nEmitterMode != 1)
                    {
                        return(flag);
                    }
                    this.modeB.startRadius        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("maxRadius", dictionary)));
                    this.modeB.startRadiusVar     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("maxRadiusVariance", dictionary)));
                    this.modeB.endRadius          = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("minRadius", dictionary)));
                    this.modeB.endRadiusVar       = 0f;
                    this.modeB.rotatePerSecond    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotatePerSecond", dictionary)));
                    this.modeB.rotatePerSecondVar = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotatePerSecondVariance", dictionary)));
                }
                this.m_fLife         = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("particleLifespan", dictionary)));
                this.m_fLifeVar      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("particleLifespanVariance", dictionary)));
                this.m_fEmissionRate = ((float)this.m_uTotalParticles) / this.m_fLife;
                string      pszFilename = this.valueForKey("textureFileName", dictionary);
                string      fileimage   = CCFileUtils.fullPathFromRelativeFile(pszFilename, this.m_sPlistFile);
                CCTexture2D textured    = null;
                if (pszFilename.Length > 0)
                {
                    bool isPopupNotify = CCFileUtils.IsPopupNotify;
                    CCFileUtils.IsPopupNotify = false;
                    textured = CCTextureCache.sharedTextureCache().addImage(fileimage);
                    CCFileUtils.IsPopupNotify = isPopupNotify;
                }
                if (textured == null)
                {
                    throw new NotImplementedException();
                }
                this.m_pTexture = textured;
                if (this.m_pTexture != null)
                {
                    flag = true;
                }
            }
            return(flag);
        }
Пример #12
0
        // the XML parser calls here with all the elements
        public void startElement(object ctx, string name, string[] atts)
        {
            CCTMXMapInfo pTMXMapInfo = this;
            string       elementName = name;
            Dictionary <string, string> attributeDict = new Dictionary <string, string>();

            if (atts != null && atts[0] != null)
            {
                for (int i = 0; i + 1 < atts.Length; i += 2)
                {
                    string key   = atts[i];
                    string value = atts[i + 1];
                    attributeDict.Add(key, value);
                }
            }
            if (elementName == "map")
            {
                string version = attributeDict["version"];
                if (version != "1.0")
                {
                    CCLog.Log("cocos2d: TMXFormat: Unsupported TMX version: {0}", version);
                }
                string orientationStr = attributeDict["orientation"];
                if (orientationStr == "orthogonal")
                {
                    pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationOrtho);
                }
                else if (orientationStr == "isometric")
                {
                    pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationIso);
                }
                else if (orientationStr == "hexagonal")
                {
                    pTMXMapInfo.Orientation = (int)(CCTMXOrientatio.CCTMXOrientationHex);
                }
                else
                {
                    CCLog.Log("cocos2d: TMXFomat: Unsupported orientation: {0}", pTMXMapInfo.Orientation);
                }

                CCSize sMapSize = new CCSize();
                sMapSize.width      = ccUtils.ccParseFloat(attributeDict["width"]);
                sMapSize.height     = ccUtils.ccParseFloat(attributeDict["height"]);
                pTMXMapInfo.MapSize = sMapSize;

                CCSize sTileSize = new CCSize();
                sTileSize.width      = ccUtils.ccParseFloat(attributeDict["tilewidth"]);
                sTileSize.height     = ccUtils.ccParseFloat(attributeDict["tileheight"]);
                pTMXMapInfo.TileSize = sTileSize;

                // The parent element is now "map"
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyMap;
            }
            else if (elementName == "tileset")
            {
                // If this is an external tileset then start parsing that

                if (attributeDict.Keys.Contains("source"))
                {
                    string externalTilesetFilename = attributeDict["source"];

                    externalTilesetFilename = CCFileUtils.fullPathFromRelativeFile(externalTilesetFilename, pTMXMapInfo.TMXFileName);
                    pTMXMapInfo.parseXMLFile(externalTilesetFilename);
                }
                else
                {
                    CCTMXTilesetInfo tileset = new CCTMXTilesetInfo();
                    tileset.m_sName     = attributeDict["name"];
                    tileset.m_uFirstGid = ccUtils.ccParseInt(attributeDict["firstgid"]);

                    if (attributeDict.Keys.Contains("spacing"))
                    {
                        tileset.m_uSpacing = ccUtils.ccParseInt(attributeDict["spacing"]);
                    }

                    if (attributeDict.Keys.Contains("margin"))
                    {
                        tileset.m_uMargin = ccUtils.ccParseInt(attributeDict["margin"]);
                    }
                    CCSize s = new CCSize();
                    s.width             = ccUtils.ccParseFloat(attributeDict["tilewidth"]);
                    s.height            = ccUtils.ccParseFloat(attributeDict["tileheight"]);
                    tileset.m_tTileSize = s;

                    pTMXMapInfo.Tilesets.Add(tileset);
                }
            }
            else if (elementName == "tile")
            {
                CCTMXTilesetInfo            info = pTMXMapInfo.Tilesets.LastOrDefault();
                Dictionary <string, string> dict = new Dictionary <string, string>();
                pTMXMapInfo.ParentGID = (info.m_uFirstGid + ccUtils.ccParseInt(attributeDict["id"]));
                pTMXMapInfo.TileProperties.Add(pTMXMapInfo.ParentGID, dict);

                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyTile;
            }
            else if (elementName == "layer")
            {
                CCTMXLayerInfo layer = new CCTMXLayerInfo();
                layer.m_sName = attributeDict["name"];

                CCSize s = new CCSize();
                s.width            = ccUtils.ccParseFloat(attributeDict["width"]);
                s.height           = ccUtils.ccParseFloat(attributeDict["height"]);
                layer.m_tLayerSize = s;

                layer.m_pTiles = new int[(int)s.width * (int)s.height];

                if (attributeDict.Keys.Contains("visible"))
                {
                    string visible = attributeDict["visible"];
                    layer.m_bVisible = !(visible == "0");
                }
                else
                {
                    layer.m_bVisible = true;
                }

                if (attributeDict.Keys.Contains("opacity"))
                {
                    string opacity = attributeDict["opacity"];
                    layer.m_cOpacity = (byte)(255 * ccUtils.ccParseFloat(opacity));
                }
                else
                {
                    layer.m_cOpacity = 255;
                }

                float x = attributeDict.Keys.Contains("x") ? ccUtils.ccParseFloat(attributeDict["x"]) : 0;
                float y = attributeDict.Keys.Contains("y") ? ccUtils.ccParseFloat(attributeDict["y"]) : 0;
                layer.m_tOffset = new CCPoint(x, y);

                pTMXMapInfo.Layers.Add(layer);

                // The parent element is now "layer"
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyLayer;
            }
            else if (elementName == "objectgroup")
            {
                CCTMXObjectGroup objectGroup = new CCTMXObjectGroup();
                objectGroup.GroupName = attributeDict["name"];
                CCPoint positionOffset = new CCPoint();
                if (attributeDict.ContainsKey("x"))
                {
                    positionOffset.x = ccUtils.ccParseFloat(attributeDict["x"]) * pTMXMapInfo.TileSize.width;
                }
                if (attributeDict.ContainsKey("y"))
                {
                    positionOffset.y = ccUtils.ccParseFloat(attributeDict["y"]) * pTMXMapInfo.TileSize.height;
                }
                objectGroup.PositionOffset = positionOffset;

                pTMXMapInfo.ObjectGroups.Add(objectGroup);

                // The parent element is now "objectgroup"
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyObjectGroup;
            }
            else if (elementName == "image")
            {
                CCTMXTilesetInfo tileset = pTMXMapInfo.Tilesets.LastOrDefault();

                // build full path
                string imagename = attributeDict["source"];
                tileset.m_sSourceImage = CCFileUtils.fullPathFromRelativeFile(imagename, pTMXMapInfo.TMXFileName);
            }
            else if (elementName == "data")
            {
                string encoding    = attributeDict.ContainsKey("encoding") ? attributeDict["encoding"] : "";
                string compression = attributeDict.ContainsKey("compression") ? attributeDict["compression"] : "";

                if (encoding == "base64")
                {
                    int layerAttribs = pTMXMapInfo.LayerAttribs;
                    pTMXMapInfo.LayerAttribs      = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribBase64;
                    pTMXMapInfo.StoringCharacters = true;

                    if (compression == "gzip")
                    {
                        layerAttribs             = pTMXMapInfo.LayerAttribs;
                        pTMXMapInfo.LayerAttribs = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribGzip;
                    }
                    else
                    if (compression == "zlib")
                    {
                        layerAttribs             = pTMXMapInfo.LayerAttribs;
                        pTMXMapInfo.LayerAttribs = layerAttribs | (int)TMXLayerAttrib.TMXLayerAttribZlib;
                    }
                    Debug.Assert(compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method");
                }
                Debug.Assert(pTMXMapInfo.LayerAttribs != (int)TMXLayerAttrib.TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported");
            }
            else if (elementName == "object")
            {
                char[]           buffer      = new char[32];
                CCTMXObjectGroup objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault();

                // The value for "type" was blank or not a valid class name
                // Create an instance of TMXObjectInfo to store the object and its properties
                Dictionary <string, string> dict = new Dictionary <string, string>();

                // Set the name of the object to the value for "name"
                string key   = "name";
                string value = attributeDict.ContainsKey("name") ? attributeDict["name"] : "";
                dict.Add(key, value);

                // Assign all the attributes as key/name pairs in the properties dictionary
                key   = "type";
                value = attributeDict.ContainsKey("type") ? attributeDict["type"] : "";
                dict.Add(key, value);

                int x = ccUtils.ccParseInt(attributeDict["x"]) + (int)objectGroup.PositionOffset.x;
                key   = "x";
                value = x.ToString();
                dict.Add(key, value);

                int y = ccUtils.ccParseInt(attributeDict["y"]) + (int)objectGroup.PositionOffset.y;
                // Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
                y     = (int)(pTMXMapInfo.MapSize.height * pTMXMapInfo.TileSize.height) - y - (attributeDict.ContainsKey("height") ? ccUtils.ccParseInt(attributeDict["height"]) : 0);
                key   = "y";
                value = y.ToString();
                dict.Add(key, value);

                key   = "width";
                value = attributeDict.ContainsKey("width") ? attributeDict["width"] : "";
                dict.Add(key, value);

                key   = "height";
                value = attributeDict.ContainsKey("height") ? attributeDict["height"] : "";
                dict.Add(key, value);

                // Add the object to the objectGroup
                objectGroup.Objects.Add(dict);

                // The parent element is now "object"
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyObject;
            }
            else if (elementName == "property")
            {
                if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyNone)
                {
                    CCLog.Log("TMX tile map: Parent element is unsupported. Cannot add property named '{0}' with value '{1}'",
                              attributeDict["name"], attributeDict["value"]);
                }
                else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyMap)
                {
                    // The parent element is the map
                    string value = attributeDict["value"];
                    string key   = attributeDict["name"];
                    pTMXMapInfo.Properties.Add(key, value);
                }
                else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyLayer)
                {
                    // The parent element is the last layer
                    CCTMXLayerInfo layer = pTMXMapInfo.Layers.LastOrDefault();
                    string         value = attributeDict["value"];
                    string         key   = attributeDict["name"];
                    // Add the property to the layer
                    layer.Properties.Add(key, value);
                }
                else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyObjectGroup)
                {
                    // The parent element is the last object group
                    CCTMXObjectGroup objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault();
                    string           value       = attributeDict["value"];
                    string           key         = attributeDict["name"];
                    objectGroup.Properties.Add(key, value);
                }
                else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyObject)
                {
                    // The parent element is the last object
                    CCTMXObjectGroup            objectGroup = pTMXMapInfo.ObjectGroups.LastOrDefault();
                    Dictionary <string, string> dict        = objectGroup.Objects.LastOrDefault();

                    string propertyName  = attributeDict["name"];
                    string propertyValue = attributeDict["value"];
                    dict.Add(propertyName, propertyValue);
                }
                else if (pTMXMapInfo.ParentElement == (int)TMXProperty.TMXPropertyTile)
                {
                    Dictionary <string, string> dict = pTMXMapInfo.TileProperties[pTMXMapInfo.ParentGID];

                    string propertyName  = attributeDict["name"];
                    string propertyValue = attributeDict["value"];
                    dict.Add(propertyName, propertyValue);
                }
            }
            if (attributeDict != null)
            {
                attributeDict = null;
            }
        }