Example #1
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);
        }
Example #2
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 #3
0
        private bool InitWithTarget(CCNode pFollowedNode, CCRect rect)
        {
            Debug.Assert(pFollowedNode != null);

            m_pobFollowedNode = pFollowedNode;
            if (rect.Equals(CCRect.Zero))
            {
                m_bBoundarySet = false;
            }
            else
            {
                m_bBoundarySet = true;
            }

            m_bBoundaryFullyCovered = false;

            CCSize winSize = CCDirector.SharedDirector.WinSize;
            m_obFullScreenSize = new CCPoint(winSize.Width, winSize.Height);
            m_obHalfScreenSize = CCPointExtension.Multiply(m_obFullScreenSize, 0.5f);

            if (m_bBoundarySet)
            {
                m_fLeftBoundary = -((rect.Origin.X + rect.Size.Width) - m_obFullScreenSize.X);
                m_fRightBoundary = -rect.Origin.X;
                m_fTopBoundary = -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;
        }