Esempio n. 1
0
        public override CCObject copyWithZone(CCZone pZone)
        {
            CCSpriteFrame pCopy = new CCSpriteFrame();

            pCopy.initWithTexture(m_pobTexture, m_obRectInPixels, m_bRotated, m_obOffsetInPixels, m_obOriginalSizeInPixels);
            return(pCopy);
        }
Esempio n. 2
0
        public override CCObject copyWithZone(CCZone pZone)
        {
            CCSpriteFrame cCSpriteFrame = new CCSpriteFrame();

            cCSpriteFrame.initWithTexture(this.m_pobTexture, this.m_obRectInPixels, this.m_bRotated, this.m_obOffsetInPixels, this.m_obOriginalSizeInPixels);
            return(cCSpriteFrame);
        }
Esempio n. 3
0
        public static CCSpriteFrame frameWithTexture(CCTexture2D pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
        {
            CCSpriteFrame cCSpriteFrame = new CCSpriteFrame();

            cCSpriteFrame.initWithTexture(pobTexture, rect, rotated, offset, originalSize);
            return(cCSpriteFrame);
        }
Esempio n. 4
0
        public static CCSpriteFrame frameWithTexture(CCTexture2D pobTexture, CCRect rect)
        {
            CCSpriteFrame cCSpriteFrame = new CCSpriteFrame();

            cCSpriteFrame.initWithTexture(pobTexture, rect);
            return(cCSpriteFrame);
        }
Esempio n. 5
0
        /// <summary>
        /// Create a CCSpriteFrame with a texture, rect in points.
        /// It is assumed that the frame was not trimmed.
        /// </summary>
        public static CCSpriteFrame frameWithTexture(Texture pobTexture, CCRect rect)
        {
            CCSpriteFrame pSpriteFrame = new CCSpriteFrame();;

            pSpriteFrame.initWithTexture(pobTexture, rect);

            return(pSpriteFrame);
        }
Esempio n. 6
0
        /// <summary>
        /// Create a CCSpriteFrame with a texture, rect in points.
        /// It is assumed that the frame was not trimmed.
        /// </summary>
        public static CCSpriteFrame frameWithTexture(Texture pobTexture, CCRect rect)
        {
            CCSpriteFrame pSpriteFrame = new CCSpriteFrame(); ;
            pSpriteFrame.initWithTexture(pobTexture, rect);

            return pSpriteFrame;
        }
Esempio n. 7
0
 public override CCObject copyWithZone(CCZone pZone)
 {
     CCSpriteFrame pCopy = new CCSpriteFrame();
     pCopy.initWithTexture(m_pobTexture, m_obRectInPixels, m_bRotated, m_obOffsetInPixels, m_obOriginalSizeInPixels);
     return pCopy;
 }
Esempio n. 8
0
        /// <summary>
        /// Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
        /// The originalSize is the size in points of the frame before being trimmed.
        /// </summary>
        public static CCSpriteFrame frameWithTexture(Texture pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
        {
            CCSpriteFrame pSpriteFrame = new CCSpriteFrame();
            pSpriteFrame.initWithTexture(pobTexture, rect, rotated, offset, originalSize);

            return pSpriteFrame;
        }
        /// <summary>
        /// Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
        /// </summary>
        public void addSpriteFramesWithDictionary(Dictionary<string, Object> pobDictionary, CCTexture2D pobTexture)
        {
            /*
            Supported Zwoptex Formats:

            ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
            ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
            ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
            ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
            */
            Dictionary<string, Object> metadataDict = null;
            if (pobDictionary.Keys.Contains("metadata"))
            {
                metadataDict = (Dictionary<string, Object>)pobDictionary["metadata"];
            }

            Dictionary<string, Object> framesDict = null;
            if (pobDictionary.Keys.Contains("frames"))
            {
                framesDict = (Dictionary<string, Object>)pobDictionary["frames"];
            }

            int format = 0;

            // get the format
            if (metadataDict != null)
            {
                format = int.Parse(metadataDict["format"].ToString());
            }

            // check the format
            Debug.Assert(format >= 0 && format <= 3);

            foreach (var key in framesDict.Keys)
            {
                Dictionary<string, Object> frameDict = framesDict[key] as Dictionary<string, Object>;
                CCSpriteFrame spriteFrame = new CCSpriteFrame();

                if (format == 0)
                {
                    float x = float.Parse(frameDict["x"].ToString());
                    float y = float.Parse(frameDict["y"].ToString());
                    float w = float.Parse(frameDict["width"].ToString());
                    float h = float.Parse(frameDict["height"].ToString());
                    float ox = float.Parse(frameDict["offsetX"].ToString());
                    float oy = float.Parse(frameDict["offsetY"].ToString());
                    int ow = int.Parse(frameDict["originalWidth"].ToString());
                    int oh = int.Parse(frameDict["originalHeight"].ToString());
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        Debug.WriteLine("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);
                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                new CCRect(x, y, w, h),
                                                false,
                                                new CCPoint(ox, oy),
                                                new CCSize((float)ow, (float)oh)
                                                );
                }
                else if (format == 1 || format == 2)
                {
                    CCRect frame = CCNS.CCRectFromString(frameDict["frame"].ToString());
                    bool rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.Keys.Contains("rotated"))
                        {
                            rotated = int.Parse(valueForKey("rotated", frameDict)) == 0 ? false : true;
                        }
                    }

                    CCPoint offset = CCNS.CCPointFromString(valueForKey("offset", frameDict));
                    CCSize sourceSize = CCNS.CCSizeFromString(valueForKey("sourceSize", frameDict));

                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                        frame,
                        rotated,
                        offset,
                        sourceSize
                        );
                }
                else
                    if (format == 3)
                    {
                        // get values
                        CCSize spriteSize = CCNS.CCSizeFromString(valueForKey("spriteSize", frameDict));
                        CCPoint spriteOffset = CCNS.CCPointFromString(valueForKey("spriteOffset", frameDict));
                        CCSize spriteSourceSize = CCNS.CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
                        CCRect textureRect = CCNS.CCRectFromString(valueForKey("textureRect", frameDict));
                        bool textureRotated = false;
                        if (frameDict.Keys.Contains("textureRotated"))
                        {
                            textureRotated = int.Parse(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
                        }

                        // get aliases
                        var list = frameDict["aliases"];
                        List<object> aliases = (frameDict["aliases"] as List<object>);
                        string frameKey = key;
                        foreach (var item2 in aliases)
                        {
                            string oneAlias = item2.ToString();
                            if (m_pSpriteFramesAliases.Keys.Contains(oneAlias))
                            {
                                if (m_pSpriteFramesAliases[oneAlias] != null)
                                {
                                    Debug.WriteLine("cocos2d: WARNING: an alias with name {0} already exists", oneAlias);
                                }
                            }
                            if (!m_pSpriteFramesAliases.Keys.Contains(frameKey))
                            {
                                m_pSpriteFramesAliases.Add(frameKey, oneAlias);
                            }
                        }

                        // create frame
                        spriteFrame = new CCSpriteFrame();
                        spriteFrame.initWithTexture(pobTexture,
                                        new CCRect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                                        textureRotated,
                                        spriteOffset,
                                        spriteSourceSize);
                    }

                // add sprite frame
                if (!m_pSpriteFrames.Keys.Contains(key))
                {
                    m_pSpriteFrames.Add(key, spriteFrame);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
        /// </summary>
        public void addSpriteFramesWithDictionary(Dictionary <string, Object> pobDictionary, CCTexture2D pobTexture)
        {
            /*
             * Supported Zwoptex Formats:
             *
             * ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
             * ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
             * ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
             * ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
             */
            Dictionary <string, Object> metadataDict = null;

            if (pobDictionary.Keys.Contains("metadata"))
            {
                metadataDict = (Dictionary <string, Object>)pobDictionary["metadata"];
            }

            Dictionary <string, Object> framesDict = null;

            if (pobDictionary.Keys.Contains("frames"))
            {
                framesDict = (Dictionary <string, Object>)pobDictionary["frames"];
            }

            int format = 0;

            // get the format
            if (metadataDict != null)
            {
                format = ccUtils.ccParseInt(metadataDict["format"].ToString());
            }

            // check the format
            Debug.Assert(format >= 0 && format <= 3);

            foreach (var key in framesDict.Keys)
            {
                Dictionary <string, Object> frameDict = framesDict[key] as Dictionary <string, Object>;
                CCSpriteFrame spriteFrame             = new CCSpriteFrame();

                if (format == 0)
                {
                    float x  = ccUtils.ccParseFloat(frameDict["x"].ToString());
                    float y  = ccUtils.ccParseFloat(frameDict["y"].ToString());
                    float w  = ccUtils.ccParseFloat(frameDict["width"].ToString());
                    float h  = ccUtils.ccParseFloat(frameDict["height"].ToString());
                    float ox = ccUtils.ccParseFloat(frameDict["offsetX"].ToString());
                    float oy = ccUtils.ccParseFloat(frameDict["offsetY"].ToString());
                    int   ow = ccUtils.ccParseInt(frameDict["originalWidth"].ToString());
                    int   oh = ccUtils.ccParseInt(frameDict["originalHeight"].ToString());
                    // check ow/oh
                    if (ow == 0 || oh == 0)
                    {
                        CCLog.Log("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
                    }
                    // abs ow/oh
                    ow = Math.Abs(ow);
                    oh = Math.Abs(oh);
                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                new CCRect(x, y, w, h),
                                                false,
                                                new CCPoint(ox, oy),
                                                new CCSize((float)ow, (float)oh)
                                                );
                }
                else if (format == 1 || format == 2)
                {
                    CCRect frame   = CCNS.CCRectFromString(frameDict["frame"].ToString());
                    bool   rotated = false;

                    // rotation
                    if (format == 2)
                    {
                        if (frameDict.Keys.Contains("rotated"))
                        {
                            rotated = ccUtils.ccParseInt(valueForKey("rotated", frameDict)) == 0 ? false : true;
                        }
                    }

                    CCPoint offset     = CCNS.CCPointFromString(valueForKey("offset", frameDict));
                    CCSize  sourceSize = CCNS.CCSizeFromString(valueForKey("sourceSize", frameDict));

                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                frame,
                                                rotated,
                                                offset,
                                                sourceSize
                                                );
                }
                else
                if (format == 3)
                {
                    // get values
                    CCSize  spriteSize       = CCNS.CCSizeFromString(valueForKey("spriteSize", frameDict));
                    CCPoint spriteOffset     = CCNS.CCPointFromString(valueForKey("spriteOffset", frameDict));
                    CCSize  spriteSourceSize = CCNS.CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
                    CCRect  textureRect      = CCNS.CCRectFromString(valueForKey("textureRect", frameDict));
                    bool    textureRotated   = false;
                    if (frameDict.Keys.Contains("textureRotated"))
                    {
                        textureRotated = ccUtils.ccParseInt(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
                    }

                    // get aliases
                    var           list     = frameDict["aliases"];
                    List <object> aliases  = (frameDict["aliases"] as List <object>);
                    string        frameKey = key;
                    foreach (var item2 in aliases)
                    {
                        string oneAlias = item2.ToString();
                        if (m_pSpriteFramesAliases.Keys.Contains(oneAlias))
                        {
                            if (m_pSpriteFramesAliases[oneAlias] != null)
                            {
                                CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", oneAlias);
                            }
                        }
                        if (!m_pSpriteFramesAliases.Keys.Contains(frameKey))
                        {
                            m_pSpriteFramesAliases.Add(frameKey, oneAlias);
                        }
                    }

                    // create frame
                    spriteFrame = new CCSpriteFrame();
                    spriteFrame.initWithTexture(pobTexture,
                                                new CCRect(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                                                textureRotated,
                                                spriteOffset,
                                                spriteSourceSize);
                }

                // add sprite frame
                if (!m_pSpriteFrames.Keys.Contains(key))
                {
                    m_pSpriteFrames.Add(key, spriteFrame);
                }
            }
        }
Esempio n. 11
0
        public void addSpriteFramesWithDictionary(Dictionary <string, object> pobDictionary, CCTexture2D pobTexture)
        {
            Dictionary <string, object> item = null;

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

            if (pobDictionary.Keys.Contains <string>("frames"))
            {
                strs = (Dictionary <string, object>)pobDictionary["frames"];
            }
            int num = 0;

            if (item != null)
            {
                num = ccUtils.ccParseInt(item["format"].ToString());
            }
            foreach (string key in strs.Keys)
            {
                Dictionary <string, object> item1 = strs[key] as Dictionary <string, object>;
                CCSpriteFrame cCSpriteFrame       = new CCSpriteFrame();
                if (num == 0)
                {
                    float single  = ccUtils.ccParseFloat(item1["x"].ToString());
                    float single1 = ccUtils.ccParseFloat(item1["y"].ToString());
                    float single2 = ccUtils.ccParseFloat(item1["width"].ToString());
                    float single3 = ccUtils.ccParseFloat(item1["height"].ToString());
                    float single4 = ccUtils.ccParseFloat(item1["offsetX"].ToString());
                    float single5 = ccUtils.ccParseFloat(item1["offsetY"].ToString());
                    int   num1    = ccUtils.ccParseInt(item1["originalWidth"].ToString());
                    int   num2    = ccUtils.ccParseInt(item1["originalHeight"].ToString());
                    if (num1 == 0 || num2 == 0)
                    {
                        CCLog.Log("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
                    }
                    num1          = Math.Abs(num1);
                    num2          = Math.Abs(num2);
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, new CCRect(single, single1, single2, single3), false, new CCPoint(single4, single5), new CCSize((float)num1, (float)num2));
                }
                else if (num == 1 || num == 2)
                {
                    CCRect cCRect = CCNS.CCRectFromString(item1["frame"].ToString());
                    bool   flag   = false;
                    if (num == 2 && item1.Keys.Contains <string>("rotated"))
                    {
                        flag = (ccUtils.ccParseInt(this.valueForKey("rotated", item1)) == 0 ? false : true);
                    }
                    CCPoint cCPoint = CCNS.CCPointFromString(this.valueForKey("offset", item1));
                    CCSize  cCSize  = CCNS.CCSizeFromString(this.valueForKey("sourceSize", item1));
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, cCRect, flag, cCPoint, cCSize);
                }
                else if (num == 3)
                {
                    CCSize  cCSize1  = CCNS.CCSizeFromString(this.valueForKey("spriteSize", item1));
                    CCPoint cCPoint1 = CCNS.CCPointFromString(this.valueForKey("spriteOffset", item1));
                    CCSize  cCSize2  = CCNS.CCSizeFromString(this.valueForKey("spriteSourceSize", item1));
                    CCRect  cCRect1  = CCNS.CCRectFromString(this.valueForKey("textureRect", item1));
                    bool    flag1    = false;
                    if (item1.Keys.Contains <string>("textureRotated"))
                    {
                        flag1 = (ccUtils.ccParseInt(this.valueForKey("textureRotated", item1)) == 0 ? false : true);
                    }
                    object        obj  = item1["aliases"];
                    List <object> objs = item1["aliases"] as List <object>;
                    string        str  = key;
                    foreach (object obj1 in objs)
                    {
                        string str1 = obj1.ToString();
                        if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str1) && this.m_pSpriteFramesAliases[str1] != null)
                        {
                            CCLog.Log("cocos2d: WARNING: an alias with name {0} already exists", new object[] { str1 });
                        }
                        if (this.m_pSpriteFramesAliases.Keys.Contains <string>(str))
                        {
                            continue;
                        }
                        this.m_pSpriteFramesAliases.Add(str, str1);
                    }
                    cCSpriteFrame = new CCSpriteFrame();
                    cCSpriteFrame.initWithTexture(pobTexture, new CCRect(cCRect1.origin.x, cCRect1.origin.y, cCSize1.width, cCSize1.height), flag1, cCPoint1, cCSize2);
                }
                if (this.m_pSpriteFrames.Keys.Contains <string>(key))
                {
                    continue;
                }
                this.m_pSpriteFrames.Add(key, cCSpriteFrame);
            }
        }