public bool UpdateWithSprite(CCSprite sprite, CCRect textureRect, bool rotated, CCPoint offset,
                                     CCSize originalSize, CCRect capInsets)
        {
            var opacity = Opacity;
            var color   = Color;

            CleanupSlicedSprites();
            protectedChildren.Clear();

            UpdateBlendFunc((sprite != null) ? sprite.Texture : null);

            if (sprite != null)
            {
                if (sprite.SpriteFrame == null)
                {
                    return(false);
                }

                if (scale9Image == null)
                {
                    scale9Image = sprite;
                    scale9Image.RemoveAllChildren(true);
                }
                else
                {
                    scale9Image.SpriteFrame = sprite.SpriteFrame;
                }
            }

            if (scale9Image == null)
            {
                return(false);
            }

            var spriteFrame = scale9Image.SpriteFrame;

            if (spriteFrame == null)
            {
                return(false);
            }

            var rect = textureRect;
            var size = originalSize;

            this.capInsets = capInsets;

            // If there is no given rect
            if (rect == CCRect.Zero)
            {
                // Get the texture size as original
                CCSize textureSize = scale9Image.Texture.ContentSizeInPixels;

                rect.Origin.X    = 0;
                rect.Origin.Y    = 0;
                rect.Size.Width  = textureSize.Width;
                rect.Size.Height = textureSize.Height;
            }

            if (size == CCSize.Zero)
            {
                size = rect.Size;
            }


            // Set the given rect's size as original size
            spriteRect         = rect;
            this.offset        = offset;
            spriteFrameRotated = rotated;
            this.originalSize  = size;
            preferredSize      = size;
            capInsetsInternal  = capInsets;

            if (isScale9Enabled)
            {
                CreateSlicedSprites();
            }

            ApplyBlendFunc();

            ContentSize = size;

            if (spritesGenerated)
            {
                // Restore color and opacity
                Opacity = opacity;
                Color   = color;
            }
            spritesGenerated = true;

            return(true);
        }
        public bool UpdateWithSprite(CCSprite sprite, CCRect textureRect, bool rotated, CCPoint offset,
            CCSize originalSize, CCRect capInsets)
        {
            var opacity = Opacity;
            var color = Color;

            CleanupSlicedSprites();
            protectedChildren.Clear();

            UpdateBlendFunc((sprite != null) ? sprite.Texture : null);

            if (sprite != null)
            {
                if (sprite.SpriteFrame == null)
                    return false;

                if (scale9Image == null)
                {
                    scale9Image = sprite;
                    scale9Image.RemoveAllChildren(true);
                }
                else
                {
                    scale9Image.SpriteFrame = sprite.SpriteFrame;
                }

            }

            if (scale9Image == null)
                return false;

            var spriteFrame = scale9Image.SpriteFrame;

            if (spriteFrame == null)
            {
                return false;
            }

            var rect = textureRect;
            var size = originalSize;

            this.capInsets = capInsets;

            // If there is no given rect
            if (rect == CCRect.Zero)
            {
                // Get the texture size as original
                CCSize textureSize = scale9Image.Texture.ContentSizeInPixels;

                rect.Origin.X = 0;
                rect.Origin.Y = 0;
                rect.Size.Width = textureSize.Width;
                rect.Size.Height = textureSize.Height;
            }

            if (size == CCSize.Zero)
                size = rect.Size;


            // Set the given rect's size as original size
            spriteRect = rect;
            this.offset = offset;
            spriteFrameRotated = rotated;
            this.originalSize = size;
            preferredSize = size;
            capInsetsInternal = capInsets;

            if (isScale9Enabled)
                CreateSlicedSprites();

            ApplyBlendFunc();

            ContentSize = size;

            if (spritesGenerated)
            {
                // Restore color and opacity
                Opacity = opacity;
                Color = color;
            }
            spritesGenerated = true;

            return true;
        }