protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
                                                     CCBReader reader)
 {
     if (propertyName == PROPERTY_NORMALDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetNormalSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetSelectedSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetDisabledSpriteFrame(spriteFrame);
         }
     }
     else
     {
         base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader);
     }
 }
 public void AddSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName)
 {
     if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(pszFrameName))
     {
         throw (new ArgumentException("The frame named " + pszFrameName + " already exists."));
     }
     m_pSpriteFrames[pszFrameName] = pobFrame;
 }
示例#3
0
        public void AddSpriteFrame(CCSpriteFrame pFrame)
        {
            var animFrame = new CCAnimationFrame();
            animFrame.InitWithSpriteFrame(pFrame, 1.0f, null);
            m_pFrames.Add(animFrame);

            // update duration
            m_fTotalDelayUnits++;
        }
示例#4
0
        public override void StartWithTarget(CCNode target)
        {
            base.StartWithTarget(target);
            var pSprite = (CCSprite) (target);

            m_pOrigFrame = null;

            if (m_pAnimation.RestoreOriginalFrame)
            {
                m_pOrigFrame = pSprite.DisplayFrame;
            }

            m_nNextFrame = 0;
            m_uExecutedLoops = 0;
        }
示例#5
0
        public bool initWithAnimation(CCAnimation pAnimation, bool bRestoreOriginalFrame)
        {
            Debug.Assert(pAnimation != null);

            if (base.initWithDuration(pAnimation.getFrames().Count * pAnimation.getDelay()))
            {
                m_bRestoreOriginalFrame = bRestoreOriginalFrame;
                m_pAnimation = pAnimation;
                m_pOrigFrame = null;

                return true;
            }

            return false;
        }
        public CCAnimate CreateAnimateAction()
        {
            var frameList = new List<CCSpriteFrame>();

            for (var i = 0; i < 7; i++)
            {
                var texture = CreateCharacterTexture();

                var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height));
                frameList.Add(sprite);
            }
            var animation = new CCAnimation(frameList, 0.1f);
            var animate = new CCAnimate (animation);

            return animate;
        }
示例#7
0
        /// <summary>
        /// Returns an Sprite Frame that was previously added.
        /// If the name is not found it will return nil.
        /// You should retain the returned copy if you are going to use it.
        /// </summary>
        public CCSpriteFrame spriteFrameByName(string pszName)
        {
            CCSpriteFrame
                frame = m_pSpriteFrames[pszName];

            if (frame == null)
            {
                // try alias dictionary
                string key = (string)m_pSpriteFramesAliases[pszName];
                if (key != null)
                {
                    frame = m_pSpriteFrames[key];
                    if (frame == null)
                    {
                        CCLog.Log("cocos2d: CCSpriteFrameCahce: Frame '{0}' not found", pszName);
                    }
                }
            }
            return(frame);
        }
示例#8
0
        public override CCFiniteTimeAction reverse()
        {
            List <CCSpriteFrame> list   = this.m_pAnimation.getFrames();
            List <CCSpriteFrame> frames = new List <CCSpriteFrame>(list.Count);

            if (list.Count > 0)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    CCSpriteFrame frame = list[i];
                    if (frame == null)
                    {
                        break;
                    }
                    frames.Insert((list.Count - 1) - i, (CCSpriteFrame)frame.copy());
                }
            }
            CCAnimation pAnimation = CCAnimation.animationWithFrames(frames, this.m_pAnimation.getDelay());

            return(actionWithDuration(base.m_fDuration, pAnimation, this.m_bRestoreOriginalFrame));
        }
        public SpriteAnimationSplit()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation");

            // manually add frames to the frame cache
            CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132));
            CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132));
            CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132));
            CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132));
            CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132));
            CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132));

            //
            // Animation using Sprite BatchNode
            //
            CCSprite sprite = new CCSprite(frame0);
            sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));
            AddChild(sprite);

            var animFrames = new List<CCSpriteFrame>(6);
            animFrames.Add(frame0);
            animFrames.Add(frame1);
            animFrames.Add(frame2);
            animFrames.Add(frame3);
            animFrames.Add(frame4);
            animFrames.Add(frame5);

            CCAnimation animation = new CCAnimation(animFrames, 0.2f);
            CCAnimate animate = new CCAnimate (animation);
            CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(animate,
                               new CCFlipX(true),
                              (CCFiniteTimeAction)animate.Copy(),
                               new CCFlipX(false)
                               ));

            sprite.RunAction(new CCRepeatForever (seq));
            //animFrames->release();    // win32 : memory leak    2010-0415
        }
示例#10
0
 /// <summary>
 /// Adds an sprite frame with a given name.
 /// If the name already exists, then the contents of the old name will be replaced with the new one.
 /// </summary>
 public void addSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName)
 {
     m_pSpriteFrames.Add(pszFrameName, pobFrame);
 }
示例#11
0
        protected bool InitWithAnimation(CCAnimation pAnimation)
        {
            Debug.Assert(pAnimation != null);

            float singleDuration = pAnimation.Duration;

            if (base.InitWithDuration(singleDuration * pAnimation.Loops))
            {
                m_nNextFrame = 0;
                m_pAnimation = pAnimation;
                m_pOrigFrame = null;
                m_uExecutedLoops = 0;

                m_pSplitTimes.Capacity = pAnimation.Frames.Count;

                float accumUnitsOfTime = 0;
                float newUnitOfTimeValue = singleDuration / pAnimation.TotalDelayUnits;

                var pFrames = pAnimation.Frames;

                //TODO: CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame *);

                foreach (var pObj in pFrames)
                {
                    var frame = (CCAnimationFrame) pObj;
                    float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
                    accumUnitsOfTime += frame.DelayUnits;
                    m_pSplitTimes.Add(value);
                }
                return true;
            }
            return false;
        }
示例#12
0
 public static CCScale9Sprite CreateWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithSpriteFrame(spriteFrame, capInsets);
     return pReturn;
 }
示例#13
0
        public void SetSpriteFrame(CCSpriteFrame spriteFrame)
        {
            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
            UpdateWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, CCRect.Zero);

            // Reset insets
            m_insetLeft = 0;
            m_insetTop = 0;
            m_insetRight = 0;
            m_insetBottom = 0;
        }
示例#14
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;
        }
示例#15
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;
        }
示例#16
0
 public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
 {
     CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
     AddSpriteFrame(pFrame);
 }
示例#17
0
 public void AddSprite(CCSprite sprite)
 {
     CCSpriteFrame f = new CCSpriteFrame(sprite.Texture, new CCRect(0, 0, sprite.ContentSize.Width, sprite.ContentSize.Height));
     AddSpriteFrame(f);
 }
示例#18
0
 /**
  * Sets the background spriteFrame to use for the specified button state.
  *
  * @param spriteFrame The background spriteFrame to use for the specified state.
  * @param state The state that uses the specified image. The values are described
  * in "CCControlState".
  */
 public virtual void SetBackgroundSpriteFrameForState(CCSpriteFrame spriteFrame, CCControlState state)
 {
     CCScale9Sprite sprite = new CCScale9SpriteFrame(spriteFrame);
     SetBackgroundSpriteForState(sprite, state);
 }
示例#19
0
        public void SetDisplayFrame(CCSpriteFrame spriteFrame)
        {
            Debug.Assert(spriteFrame.OffsetInPixels.Equals(CCPoint.Zero),
                         "QuadParticle only supports SpriteFrames with no offsets");

            // update texture before updating texture rect
            if (m_pTexture != null || spriteFrame.Texture.Name != m_pTexture.Name)
            {
                Texture = spriteFrame.Texture;
            }
        }
示例#20
0
 public object Copy(ICopyable pZone)
 {
     var pCopy = new CCSpriteFrame();
     pCopy.InitWithTexture(m_pobTexture, m_obRectInPixels, m_bRotated, m_obOffsetInPixels, m_obOriginalSizeInPixels);
     return pCopy;
 }
示例#21
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);
                }
            }
        }
示例#22
0
        public void setDisplayFrameWithAnimationName(string animationName, int frameIndex)
        {
            CCSpriteFrame frame = CCAnimationCache.sharedAnimationCache().animationByName(animationName).getFrames()[frameIndex];

            this.DisplayFrame = frame;
        }
示例#23
0
        /// <summary>
        /// Initializes an sprite with an sprite frame.
        /// </summary>
        public bool initWithSpriteFrame(CCSpriteFrame pSpriteFrame)
        {
            Debug.Assert(pSpriteFrame != null);

            bool bRet = initWithTexture(pSpriteFrame.Texture, pSpriteFrame.Rect);
            DisplayFrame = pSpriteFrame;

            return bRet;
        }
示例#24
0
 internal virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame)
 {
     Debug.Assert(spriteFrame != null, "Invalid spriteFrame for sprite");
     bool pReturn = InitWithSpriteFrame(spriteFrame, CCRect.Zero);
     return pReturn;
 }
示例#25
0
        /// <summary>
        /// returns whether or not a CCSpriteFrame is being displayed
        /// </summary>
        public bool isFrameDisplayed(CCSpriteFrame pFrame)
        {
            CCRect r = pFrame.Rect;

            return(r.Equals(m_obRect) && pFrame.Texture.Name == m_pobTexture.Name);
        }
示例#26
0
        /// <summary>
        /// Initializes an sprite with an sprite frame.
        /// </summary>
        public bool initWithSpriteFrame(CCSpriteFrame pSpriteFrame)
        {
            if (pSpriteFrame == null)
            {
                throw (new ArgumentNullException("pSpriteFrame", "SpriteFrame cannot be null"));
            }

            bool bRet = initWithTexture(pSpriteFrame.Texture, pSpriteFrame.Rect);
            DisplayFrame = pSpriteFrame;

            return bRet;
        }
示例#27
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;
 }
示例#28
0
 public bool isFrameDisplayed(CCSpriteFrame pFrame)
 {
     return(CCRect.CCRectEqualToRect(pFrame.Rect, this.m_obRect) && (pFrame.Texture.Name == this.m_pobTexture.Name));
 }
示例#29
0
 /** adds a frame to a CCAnimation */
 public void addFrame(CCSpriteFrame pFrame)
 {
     // m_pobFrames.addObject(pFrame);
     m_pobFrames.Add(pFrame);
 }
示例#30
0
 public void addFrame(CCSpriteFrame pFrame)
 {
     this.m_pobFrames.Add(pFrame);
 }
示例#31
0
 public static CCScale9Sprite CreateWithSpriteFrame(CCSpriteFrame spriteFrame)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithSpriteFrame(spriteFrame);
     return pReturn;
 }
示例#32
0
 protected virtual void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
                                                    CCBReader reader)
 {
     CCLog.Log("Unexpected property type: '{0}'!", propertyName);
     Debug.Assert(false);
 }
示例#33
0
        internal virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
        {
            Debug.Assert(spriteFrame != null, "Sprite frame must be not nil");

            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
            bool pReturn = InitWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, capInsets);
            return pReturn;
        }
示例#34
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);
            }
        }
示例#35
0
 /// <summary>
 /// Creates an sprite with an sprite frame.
 /// </summary>
 public static CCSprite spriteWithSpriteFrame(CCSpriteFrame pSpriteFrame)
 {
     CCSprite pobSprite = new CCSprite();
     if (pobSprite != null && pobSprite.initWithSpriteFrame(pSpriteFrame))
     {
         return pobSprite;
     }
     return null;
 }
示例#36
0
 public void AddSpriteFrameWithFileName(string pszFileName)
 {
     CCTexture2D pTexture = CCTextureCache.SharedTextureCache.AddImage(pszFileName);
     CCRect rect = CCRect.Zero;
     rect.Size = pTexture.ContentSize;
     CCSpriteFrame pFrame = new CCSpriteFrame(pTexture, rect);
     AddSpriteFrame(pFrame);
 }
示例#37
0
        /// <summary>
        /// returns whether or not a CCSpriteFrame is being displayed
        /// </summary>
        public bool isFrameDisplayed(CCSpriteFrame pFrame)
        {
            CCRect r = pFrame.Rect;

            return (r.Equals(m_obRect) && pFrame.Texture.Name == m_pobTexture.Name);
        }
 /// <summary>
 /// Adds an sprite frame with a given name.
 /// If the name already exists, then the contents of the old name will be replaced with the new one.
 /// </summary>
 public void addSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName)
 {
     m_pSpriteFrames.Add(pszFrameName, pobFrame);
 }
	    /** Sets a new CCSpriteFrame as particle.
	    WARNING: this method is experimental. Use setTexture:withRect instead.
	    @since v0.99.4
	    */
	    public void setDisplayFrame(CCSpriteFrame spriteFrame)
        {
           	Debug.Assert( CCPoint.CCPointEqualToPoint( spriteFrame.OffsetInPixels , new CCPoint(0,0) ), "QuadParticle only supports SpriteFrames with no offsets");

	        // update texture before updating texture rect
	        if ( null == this.Texture || spriteFrame.Texture.Name != this.Texture.Name)
	        {
		        this.Texture = spriteFrame.Texture;
	        }
        }
        /// <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);
                }
            }
        }