Example #1
0
 public CCSprite(string fileName, CCRect rect)
 {
     if (!InitWithFile(fileName, rect))
     {
         CCLog.Log("CCSprite (string fileName, CCRect rect): Problems initializing class");
     }
 }
Example #2
0
        public Selection(Word p_StudyInfo, bool p_IsAnswer,Int32 p_Width,Int32 p_Height)
        {
            base.init();
            this.StudyInfo = p_StudyInfo;

            CCTexture2D texture = new CCTexture2D();
            texture.initWithTexture(PictureManager.GetTexture2D(p_StudyInfo));

            if (p_Width < texture.ContentSizeInPixels.width)
            {
                this.scaleX = p_Width / texture.ContentSizeInPixels.width;
            }
            if (p_Height < texture.ContentSizeInPixels.height)
            {
                this.scaleY = p_Height / texture.ContentSizeInPixels.height;
            }
            this.contentSize.width = p_Width;
            this.contentSize.height = p_Height;

            CCRect rect = new CCRect();
            rect.size = new CCSize(texture.ContentSizeInPixels.width, texture.ContentSizeInPixels.height);
            this.initWithTexture(texture, rect);

            this.IsAnswer = p_IsAnswer;
            LoadResultPeople();
        }
Example #3
0
        public CCSprite(CCTexture2D texture, CCRect rect)
        {
            if (!InitWithTexture(texture, rect))
            {
                CCLog.Log("CCSprite (CCTexture2D texture, CCRect rect): Problems initializing class");

            }
        }
 public static CCRect getRect(CCNode node)
 {
     CCRect rc = new CCRect();
     rc.Origin = node.Position;
     rc.Size = node.ContentSize;
     rc.Origin.X -= rc.Size.Width / 2;
     rc.Origin.Y -= rc.Size.Height / 2;
     return rc;
 }
 public static CCRect getRect(CCNode pNode)
 {
     CCRect rc = new CCRect();
     rc.origin = pNode.position;
     rc.size = pNode.contentSize;
     rc.origin.x -= rc.size.width / 2;
     rc.origin.y -= rc.size.height / 2;
     return rc;
 }
Example #6
0
 /** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
 Added to facilitate the migration from v0.8 to v0.9.
 */
 public void addFrameWithFileName(string pszFileName)
 {
     CCTexture2D pTexture = CCTextureCache.sharedTextureCache().addImage(pszFileName);
     //CCRect rect = CCRectZero;
     CCRect rect = new CCRect(0, 0, 0, 0);
     rect.size = pTexture.getContentSize();
     CCSpriteFrame pFrame = CCSpriteFrame.frameWithTexture(pTexture, rect);
     //// m_pobFrames.addObject(pFrame);
     m_pobFrames.Add(pFrame);
 }
 public CCRect rectForGID(int gid)
 {
     CCRect rect = new CCRect();
     rect.size = m_tTileSize;
     gid = gid - m_uFirstGid;
     int max_x = (int)((m_tImageSize.width - m_uMargin * 2 + m_uSpacing) / (m_tTileSize.width + m_uSpacing));
     //	int max_y = (imageSize.height - margin*2 + spacing) / (tileSize.height + spacing);
     rect.origin.x = (gid % max_x) * (m_tTileSize.width + m_uSpacing) + m_uMargin;
     rect.origin.y = (gid / max_x) * (m_tTileSize.height + m_uSpacing) + m_uMargin;
     return rect;
 }
Example #8
0
        public static CCRect CCRectUnion(CCRect src1, CCRect src2)
        {
            CCRect result;

            float x1 = Math.Min(src1.MinX, src2.MinX);
            float y1 = Math.Min(src1.MinY, src2.MinY);
            float x2 = Math.Max(src1.MaxX, src2.MaxX);
            float y2 = Math.Max(src1.MaxY, src2.MaxY);

            result.Origin = new CCPoint(x1,x2);
            result.Size = new CCSize(x2-x1, y2-y1);
            return result;
        }
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top = CCRect.CCRectGetMinY(rect);
            float left = CCRect.CCRectGetMinX(rect);
            float right = CCRect.CCRectGetMaxX(rect);
            float bottom = CCRect.CCRectGetMaxY(rect);

            CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.x, topRight.x), Math.Min(bottomLeft.x, bottomRight.x));
            float maxX = Math.Max(Math.Max(topLeft.x, topRight.x), Math.Max(bottomLeft.x, bottomRight.x));
            float minY = Math.Min(Math.Min(topLeft.y, topRight.y), Math.Min(bottomLeft.y, bottomRight.y));
            float maxY = Math.Max(Math.Max(topLeft.y, topRight.y), Math.Max(bottomLeft.y, bottomRight.y));

            return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
        }
Example #10
0
        public bool initWithTarget(CCNode followedNode, CCRect rect)
        {
            Debug.Assert(followedNode != null);

            m_pobFollowedNode = followedNode;
            m_bBoundarySet = true;
            m_bBoundaryFullyCovered = false;

            CCSize winSize = CCDirector.sharedDirector().getWinSize();
            m_obFullScreenSize = new CCPoint(winSize.width, winSize.height);
            m_obHalfScreenSize = CCPointExtension.ccpMult(m_obFullScreenSize, 0.5f);

            m_fLeftBoundary = -((rect.origin.x + rect.size.width) - m_obFullScreenSize.x);
            m_fRightBoundary = -rect.origin.x;
            m_fLeftBoundary = -rect.origin.y;
            m_fBottomBoundary = -((rect.origin.y + rect.size.height) - m_obFullScreenSize.y);

            if (m_fRightBoundary < m_fLeftBoundary)
            {
                // screen width is larger than world's boundary width
                //set both in the middle of the world
                m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2;
            }
            if (m_fTopBoundary < m_fBottomBoundary)
            {
                // screen width is larger than world's boundary width
                //set both in the middle of the world
                m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2;
            }

            if ((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary))
            {
                m_bBoundaryFullyCovered = true;
            }

            return true;
        }
Example #11
0
 public CCScale9Sprite ResizableSpriteWithCapInsets(CCRect capInsets)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithBatchNode(scale9Image, m_spriteRect, capInsets);
     return pReturn;
 }
Example #12
0
 public bool InitWithFile(CCRect capInsets, string file)
 {
     bool pReturn = InitWithFile(file, CCRect.Zero, capInsets);
     return pReturn;
 }
Example #13
0
 public static CCScale9Sprite CreateWithSpriteFrameName(string spriteFrameName, CCRect capInsets)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithSpriteFrameName(spriteFrameName, capInsets);
     return pReturn;
 }
        /** Sets a new texture with a rect. The rect is in Points.
	    @since v0.99.4
	    */
	    public void setTextureWithRect(CCTexture2D texture, CCRect rect)
        {
            // Only update the texture if is different from the current one
	        if( null == this.Texture || texture.Name != this.Texture.Name )
	        {
		        base.Texture = texture;
	        }

	        initTexCoordsWithRect(rect);
        }
Example #15
0
        internal virtual bool InitWithSpriteFrameName(string spriteFrameName, CCRect capInsets)
        {
            Debug.Assert(spriteFrameName != null, "Invalid spriteFrameName for sprite");

            CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(spriteFrameName);
            bool pReturn = InitWithSpriteFrame(frame, capInsets);
            return pReturn;
        }
Example #16
0
 internal virtual bool InitWithFile(CCRect capInsets, string file)
 {
     bool pReturn = InitWithFile(file, CCRect.Zero, capInsets);
     return pReturn;
 }
Example #17
0
        internal virtual bool InitWithFile(string file, CCRect rect, CCRect capInsets)
        {
            Debug.Assert(!string.IsNullOrEmpty(file), "Invalid file for sprite");

            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(file, 9);
            bool pReturn = InitWithBatchNode(batchnode, rect, capInsets);
            return pReturn;
        }
Example #18
0
        public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            byte opacity = m_cOpacity;
            CCColor3B color = m_tColor;

            // Release old sprites
            RemoveAllChildrenWithCleanup(true);

            if (scale9Image != batchnode)
            {
                scale9Image = batchnode;
            }

            scale9Image.RemoveAllChildrenWithCleanup(true);

            m_capInsets = capInsets;

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

                rect = new CCRect(0, 0, textureSize.Width, textureSize.Height);
            }

            // Set the given rect's size as original size
            m_spriteRect = rect;
            m_originalSize = rect.Size;
            m_preferredSize = m_originalSize;
            m_capInsetsInternal = capInsets;

            // Get the image edges
            float l = rect.Origin.X;
            float t = rect.Origin.Y;
            float h = rect.Size.Height;
            float w = rect.Size.Width;

            // If there is no specified center region
            if (m_capInsetsInternal.Equals(CCRect.Zero))
            {
                // Apply the 3x3 grid format
                if (rotated)
                {
                    m_capInsetsInternal = new CCRect(l + h / 3, t + w / 3, w / 3, h / 3);
                }
                else
                {
                    m_capInsetsInternal = new CCRect(l + w / 3, t + h / 3, w / 3, h / 3);
                }
            }

            //
            // Set up the image
            //
            if (rotated)
            {
                // Sprite frame is rotated

                // Centre
                centre = new CCSprite();
                centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, true);
                scale9Image.AddChild(centre, 0, (int) Positions.pCentre);

                // Bottom
                bottom = new CCSprite();
                bottom.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                       m_capInsetsInternal.Origin.Y,
                                                                       m_capInsetsInternal.Size.Width,
                                                                       m_capInsetsInternal.Origin.X - l),
                                       rotated
                    );
                scale9Image.AddChild(bottom, 1, (int) Positions.pBottom);

                // Top
                top = new CCSprite();
                top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                    m_capInsetsInternal.Origin.Y,
                                                                    m_capInsetsInternal.Size.Width,
                                                                    h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                    rotated
                    );
                scale9Image.AddChild(top, 1, (int) Positions.pTop);

                // Right
                right = new CCSprite();
                right.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                      m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                      w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                      m_capInsetsInternal.Size.Height),
                                      rotated
                    );
                scale9Image.AddChild(right, 1, (int) Positions.pRight);

                // Left
                left = new CCSprite();
                left.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                     t,
                                                                     m_capInsetsInternal.Origin.Y - t,
                                                                     m_capInsetsInternal.Size.Height),
                                     rotated
                    );
                scale9Image.AddChild(left, 1, (int) Positions.pLeft);

                // Top right
                topRight = new CCSprite();
                topRight.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                         m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                         w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                         h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                         rotated
                    );
                scale9Image.AddChild(topRight, 2, (int) Positions.pTopRight);

                // Top left
                topLeft = new CCSprite();
                topLeft.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                        t,
                                                                        m_capInsetsInternal.Origin.Y - t,
                                                                        h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                        rotated
                    );
                scale9Image.AddChild(topLeft, 2, (int) Positions.pTopLeft);

                // Bottom right
                bottomRight = new CCSprite();
                bottomRight.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                            m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                            w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                            m_capInsetsInternal.Origin.X - l),
                                            rotated
                    );
                scale9Image.AddChild(bottomRight, 2, (int) Positions.pBottomRight);

                // Bottom left
                bottomLeft = new CCSprite();
                bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                           t,
                                                                           m_capInsetsInternal.Origin.Y - t,
                                                                           m_capInsetsInternal.Origin.X - l),
                                           rotated
                    );
                scale9Image.AddChild(bottomLeft, 2, (int) Positions.pBottomLeft);
            }
            else
            {
                // Sprite frame is not rotated
                // Centre
                centre = new CCSprite();
                centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, rotated);
                scale9Image.AddChild(centre, 0, (int) Positions.pCentre);

                // Top
                top = new CCSprite();
                top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                    t,
                                                                    m_capInsetsInternal.Size.Width,
                                                                    m_capInsetsInternal.Origin.Y - t),
                                    rotated
                    );
                scale9Image.AddChild(top, 1, (int) Positions.pTop);

                // Bottom
                bottom = new CCSprite();
                bottom.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                       m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                                                       m_capInsetsInternal.Size.Width,
                                                                       h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                       rotated);
                scale9Image.AddChild(bottom, 1, (int) Positions.pBottom);

                // Left
                left = new CCSprite();
                left.InitWithTexture(scale9Image.Texture, new CCRect(
                                                              l,
                                                              m_capInsetsInternal.Origin.Y,
                                                              m_capInsetsInternal.Origin.X - l,
                                                              m_capInsetsInternal.Size.Height),
                                     rotated);
                scale9Image.AddChild(left, 1, (int) Positions.pLeft);

                // Right
                right = new CCSprite();
                right.InitWithTexture(scale9Image.Texture, new CCRect(
                                                               m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                                               m_capInsetsInternal.Origin.Y,
                                                               w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                                               m_capInsetsInternal.Size.Height),
                                      rotated);
                scale9Image.AddChild(right, 1, (int) Positions.pRight);

                // Top left
                topLeft = new CCSprite();
                topLeft.InitWithTexture(scale9Image.Texture, new CCRect(
                                                                 l,
                                                                 t,
                                                                 m_capInsetsInternal.Origin.X - l,
                                                                 m_capInsetsInternal.Origin.Y - t),
                                        rotated);

                scale9Image.AddChild(topLeft, 2, (int) Positions.pTopLeft);

                // Top right
                topRight = new CCSprite();
                topRight.InitWithTexture(scale9Image.Texture, new CCRect(
                                                                  m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                                                  t,
                                                                  w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                                                  m_capInsetsInternal.Origin.Y - t),
                                         rotated);

                scale9Image.AddChild(topRight, 2, (int) Positions.pTopRight);

                // Bottom left
                bottomLeft = new CCSprite();
                bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect(
                                                                    l,
                                                                    m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                                                    m_capInsetsInternal.Origin.X - l,
                                                                    h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                           rotated);
                scale9Image.AddChild(bottomLeft, 2, (int) Positions.pBottomLeft);

                // Bottom right
                bottomRight = new CCSprite();
                bottomRight.InitWithTexture(scale9Image.Texture, new CCRect(
                                                                     m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                                                     m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                                                     w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                                                     h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                            rotated);
                scale9Image.AddChild(bottomRight, 2, (int) Positions.pBottomRight);
            }

            ContentSize = rect.Size;
            AddChild(scale9Image);

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

            return true;
        }
Example #19
0
 public bool InitWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, CCRect capInsets)
 {
     return InitWithBatchNode(batchnode, rect, false, capInsets);
 }
Example #20
0
        public void createFontChars()
        {
            int    item            = 0;
            int    mUCommonHeight  = 0;
            int    num             = -1;
            int    num1            = 0;
            CCSize cCSize          = new CCSize(0f, 0f);
            int    num2            = 0;
            int    mUCommonHeight1 = 0;
            int    num3            = 1;
            int    length          = this.m_sString.Length;

            if (length == 0)
            {
                return;
            }
            for (int i = 0; i < length - 1; i++)
            {
                if (this.m_sString[i] == 10)
                {
                    num3++;
                }
            }
            mUCommonHeight1 = this.m_pConfiguration.m_uCommonHeight * num3;
            mUCommonHeight  = -(this.m_pConfiguration.m_uCommonHeight - this.m_pConfiguration.m_uCommonHeight * num3);
            for (int j = 0; j < length; j++)
            {
                int mSString = this.m_sString[j];
                if ((long)mSString >= (long)2048)
                {
                    object[] objArray = new object[] { "LabelBMFont: character ", this.m_sString[j], " outside of max font characters, which is ", (uint)2048 };
                    throw new ArgumentException(string.Concat(objArray));
                }
                if (mSString != 10)
                {
                    num1 = this.kerningAmountForFirst(num, mSString);
                    if (!this.m_pConfiguration.m_pBitmapFontArray.ContainsKey(mSString))
                    {
                        throw new ArgumentException(string.Concat("Character ", mSString, " in LabelBMFont is not in the font definition."));
                    }
                    ccBMFontDef _ccBMFontDef = this.m_pConfiguration.m_pBitmapFontArray[mSString];
                    CCRect      cCRect       = _ccBMFontDef.rect;
                    CCSprite    childByTag   = (CCSprite)base.getChildByTag(j);
                    if (childByTag != null)
                    {
                        childByTag.setTextureRectInPixels(cCRect, false, cCRect.size);
                        childByTag.visible = true;
                        childByTag.Opacity = 255;
                    }
                    else
                    {
                        childByTag = new CCSprite();
                        childByTag.initWithBatchNodeRectInPixels(this, cCRect);
                        this.addChild(childByTag, 0, j);
                    }
                    float single = (float)(this.m_pConfiguration.m_uCommonHeight - _ccBMFontDef.yOffset);
                    childByTag.positionInPixels = new CCPoint((float)(item + _ccBMFontDef.xOffset) + _ccBMFontDef.rect.size.width / 2f + (float)num1, (float)mUCommonHeight + single - cCRect.size.height / 2f);
                    item = item + this.m_pConfiguration.m_pBitmapFontArray[mSString].xAdvance + num1;
                    num  = mSString;
                    childByTag.IsOpacityModifyRGB = this.m_bIsOpacityModifyRGB;
                    childByTag.Color = this.m_tColor;
                    if (this.m_cOpacity != 255)
                    {
                        childByTag.Opacity = this.m_cOpacity;
                    }
                    if (num2 < item)
                    {
                        num2 = item;
                    }
                }
                else
                {
                    item           = 0;
                    mUCommonHeight = mUCommonHeight - this.m_pConfiguration.m_uCommonHeight;
                }
            }
            cCSize.width             = (float)num2;
            cCSize.height            = (float)mUCommonHeight1;
            base.contentSizeInPixels = cCSize;
        }
Example #21
0
        public bool InitWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            if (batchnode != null)
            {
                UpdateWithBatchNode(batchnode, rect, rotated, capInsets);
                AnchorPoint = new CCPoint(0.5f, 0.5f);
            }
            m_positionsAreDirty = true;

            return true;
        }
Example #22
0
        /// <summary>
        /// Initializes an sprite with a texture.
        /// The rect used will be the size of the texture.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithTexture(CCTexture2D texture)
        {
            Debug.Assert(texture != null);

            CCRect rect = new CCRect();
            rect.size = texture.getContentSize();

            return initWithTexture(texture, rect);
        }
Example #23
0
 public CCScale9Sprite(CCRect capInsets)
 {
     InitWithBatchNode(scale9Image, m_spriteRect, capInsets);
 }
Example #24
0
        /// <summary>
        /// Initializes an sprite with a texture and a rect.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithTexture(CCTexture2D texture, CCRect rect)
        {
            Debug.Assert(texture != null);
            init();
            Texture = texture;
            setTextureRect(rect);

            return true;
        }
Example #25
0
 internal virtual bool InitWithFile(string file, CCRect rect)
 {
     Debug.Assert(!string.IsNullOrEmpty(file), "Invalid file for sprite");
     bool pReturn = InitWithFile(file, rect, CCRect.Zero);
     return pReturn;
 }
Example #26
0
 /// <summary>
 /// returns a "local" axis aligned bounding box of the node in pixels.
 /// The returned box is relative only to its parent.
 /// The returned box is in Points.
 /// @since v0.99.5
 /// </summary>
 public CCRect boundingBoxInPixels()
 {
     CCRect rect = new CCRect(0, 0, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height);
     return CCAffineTransform.CCRectApplyAffineTransform(rect, nodeToParentTransform());
 }
Example #27
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;
        }
Example #28
0
 public static CCScale9Sprite Create(string file, CCRect rect)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithFile(file, rect);
     return pReturn;
 }
Example #29
0
 protected void UpdateCapInset()
 {
     CCRect insets;
     if (m_insetLeft == 0 && m_insetTop == 0 && m_insetRight == 0 && m_insetBottom == 0)
     {
         insets = CCRect.Zero;
     }
     else
     {
         if (m_bSpriteFrameRotated)
         {
             insets = new CCRect(m_spriteRect.Origin.X + m_insetBottom,
                                 m_spriteRect.Origin.Y + m_insetLeft,
                                 m_spriteRect.Size.Width - m_insetRight - m_insetLeft,
                                 m_spriteRect.Size.Height - m_insetTop - m_insetBottom);
         }
         else
         {
             insets = new CCRect(m_spriteRect.Origin.X + m_insetLeft,
                                 m_spriteRect.Origin.Y + m_insetTop,
                                 m_spriteRect.Size.Width - m_insetLeft - m_insetRight,
                                 m_spriteRect.Size.Height - m_insetTop - m_insetBottom);
         }
     }
     CapInsets = insets;
 }
Example #30
0
 public static CCScale9Sprite Create(CCRect capInsets, string file)
 {
     var pReturn = new CCScale9Sprite();
     pReturn.InitWithFile(file, capInsets);
     return pReturn;
 }
        /** initilizes the texture with a rectangle measured Points */
	    public void initTexCoordsWithRect(CCRect pointRect)
        {
            // convert to pixels coords

            CCRect rect = new CCRect(
                pointRect.origin.x * CCDirector.sharedDirector().ContentScaleFactor,
                pointRect.origin.y * CCDirector.sharedDirector().ContentScaleFactor,
                pointRect.size.width * CCDirector.sharedDirector().ContentScaleFactor,
                pointRect.size.height * CCDirector.sharedDirector().ContentScaleFactor);

            float wide = pointRect.size.width;
            float high = pointRect.size.height;

            if (this.Texture != null)
            {
                wide = this.Texture.PixelsWide;
                high = this.Texture.PixelsHigh;
            }

        //#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
        //    GLfloat left = (rect.origin.x*2+1) / (wide*2);
        //    GLfloat bottom = (rect.origin.y*2+1) / (high*2);
        //    GLfloat right = left + (rect.size.width*2-2) / (wide*2);
        //    GLfloat top = bottom + (rect.size.height*2-2) / (high*2);
        //#else
            float left = rect.origin.x / wide;
            float bottom = rect.origin.y / high;
            float right = left + rect.size.width / wide;
            float top = bottom + rect.size.height / high;
        // #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

	        // Important. Texture in cocos2d are inverted, so the Y component should be inverted
	        ccMacros.CC_SWAP<float>(ref top, ref bottom);

	        for(uint i=0; i<this.TotalParticles; i++) 
	        {
                m_pQuads[i] = new ccV2F_C4B_T2F_Quad();
		        // bottom-left vertex:
		        m_pQuads[i].bl.texCoords.u = left;
		        m_pQuads[i].bl.texCoords.v = bottom;
		        // bottom-right vertex:
		        m_pQuads[i].br.texCoords.u = right;
		        m_pQuads[i].br.texCoords.v = bottom;
		        // top-left vertex:
		        m_pQuads[i].tl.texCoords.u = left;
		        m_pQuads[i].tl.texCoords.v = top;
		        // top-right vertex:
		        m_pQuads[i].tr.texCoords.u = right;
		        m_pQuads[i].tr.texCoords.v = top;
	        }
        }
        /// <summary>
        /// updates the font chars based on the string to render
        /// </summary>
        public void createFontChars()
        {
            int nextFontPositionX = 0;
            int nextFontPositionY = 0;
            int prev          = -1;
            int kerningAmount = 0;

            CCSize tmpSize = new CCSize(0, 0);

            int longestLine = 0;
            int totalHeight = 0;

            int quantityOfLines = 1;

            int stringLen = m_sString.Length;

            if (0 == stringLen)
            {
                return;
            }

            for (int i = 0; i < stringLen - 1; ++i)
            {
                ushort c = m_sString[i];
                if (c == '\n')
                {
                    quantityOfLines++;
                }
            }

            totalHeight       = m_pConfiguration.m_uCommonHeight * quantityOfLines;
            nextFontPositionY = -(m_pConfiguration.m_uCommonHeight - m_pConfiguration.m_uCommonHeight * quantityOfLines);

            for (int i = 0; i < stringLen; i++)
            {
                int c = m_sString[i];
                if (c >= kCCBMFontMaxChars)
                {
                    throw (new ArgumentException("LabelBMFont: character " + m_sString[i] + " outside of max font characters, which is " + kCCBMFontMaxChars));
                }
                if (c == '\n')
                {
                    nextFontPositionX  = 0;
                    nextFontPositionY -= (int)m_pConfiguration.m_uCommonHeight;
                    continue;
                }

                kerningAmount = this.kerningAmountForFirst(prev, c);

                if (!m_pConfiguration.m_pBitmapFontArray.ContainsKey(c))
                {
                    throw(new ArgumentException("Character " + c + " in LabelBMFont is not in the font definition."));
                }
                ccBMFontDef fontDef = m_pConfiguration.m_pBitmapFontArray[c];

                CCRect rect = fontDef.rect;

                CCSprite fontChar = (CCSprite)(this.getChildByTag(i));
                if (fontChar == null)
                {
                    fontChar = new CCSprite();
                    fontChar.initWithBatchNodeRectInPixels(this, rect);
                    this.addChild(fontChar, 0, i);
                }
                else
                {
                    // reusing fonts
                    //fontChar = new CCSprite();
                    fontChar.setTextureRectInPixels(rect, false, rect.size);

                    // restore to default in case they were modified
                    fontChar.visible = true;
                    fontChar.Opacity = 255;
                }

                float yOffset = (float)(m_pConfiguration.m_uCommonHeight - fontDef.yOffset);
                fontChar.positionInPixels = (new CCPoint(nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount,
                                                         (float)nextFontPositionY + yOffset - rect.size.height / 2.0f));

                //		NSLog(@"position.y: %f", fontChar.position.y);

                // update kerning
                nextFontPositionX += m_pConfiguration.m_pBitmapFontArray[c].xAdvance + kerningAmount;
                prev = c;

                // Apply label properties
                fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB;
                // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
                fontChar.Color = m_tColor;

                // only apply opaccity if it is different than 255 )
                // to prevent modifying the color too (issue #610)
                if (m_cOpacity != 255)
                {
                    fontChar.Opacity = m_cOpacity;
                }

                if (longestLine < nextFontPositionX)
                {
                    longestLine = nextFontPositionX;
                }
            }

            tmpSize.width  = (float)longestLine;
            tmpSize.height = (float)totalHeight;

            this.contentSizeInPixels = tmpSize;
        }