예제 #1
0
        protected virtual bool InitWithTexture(CCTexture2D pobTexture, CCRect rect)
        {
            CCRect rectInPixels = CCMacros.CCRectanglePointsToPixels(rect);

            return(InitWithTexture(pobTexture, rectInPixels, false, new CCPoint(0, 0), rectInPixels.Size));
        }
예제 #2
0
        private void SetTextureCoords(CCRect rect)
        {
            rect = CCMacros.CCRectanglePointsToPixels(rect);

            CCTexture2D tex = m_pobBatchNode != null ? m_pobTextureAtlas.Texture : m_pobTexture;

            if (tex == null)
            {
                return;
            }

            float atlasWidth  = tex.PixelsWide;
            float atlasHeight = tex.PixelsHigh;

            float left, right, top, bottom;

            if (m_bRectRotated)
            {
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                left   = (2 * rect.origin.x + 1) / (2 * atlasWidth);
                right  = left + (rect.size.height * 2 - 2) / (2 * atlasWidth);
                top    = (2 * rect.origin.y + 1) / (2 * atlasHeight);
                bottom = top + (rect.size.width * 2 - 2) / (2 * atlasHeight);
#else
                left   = rect.Origin.X / atlasWidth;
                right  = (rect.Origin.X + rect.Size.Height) / atlasWidth;
                top    = rect.Origin.Y / atlasHeight;
                bottom = (rect.Origin.Y + rect.Size.Width) / atlasHeight;
#endif
                // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

                if (m_bFlipX)
                {
                    CCMacros.CCSwap(ref top, ref bottom);
                }

                if (m_bFlipY)
                {
                    CCMacros.CCSwap(ref left, ref right);
                }

                m_sQuad.BottomLeft.TexCoords.U  = left;
                m_sQuad.BottomLeft.TexCoords.V  = top;
                m_sQuad.BottomRight.TexCoords.U = left;
                m_sQuad.BottomRight.TexCoords.V = bottom;
                m_sQuad.TopLeft.TexCoords.U     = right;
                m_sQuad.TopLeft.TexCoords.V     = top;
                m_sQuad.TopRight.TexCoords.U    = right;
                m_sQuad.TopRight.TexCoords.V    = bottom;
            }
            else
            {
#if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL
                left   = (2 * rect.origin.x + 1) / (2 * atlasWidth);
                right  = left + (rect.size.width * 2 - 2) / (2 * atlasWidth);
                top    = (2 * rect.origin.y + 1) / (2 * atlasHeight);
                bottom = top + (rect.size.height * 2 - 2) / (2 * atlasHeight);
#else
                left   = rect.Origin.X / atlasWidth;
                right  = (rect.Origin.X + rect.Size.Width) / atlasWidth;
                top    = rect.Origin.Y / atlasHeight;
                bottom = (rect.Origin.Y + rect.Size.Height) / atlasHeight;
#endif
                // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL

                if (m_bFlipX)
                {
                    CCMacros.CCSwap(ref left, ref right);
                }

                if (m_bFlipY)
                {
                    CCMacros.CCSwap(ref top, ref bottom);
                }

                m_sQuad.BottomLeft.TexCoords.U  = left;
                m_sQuad.BottomLeft.TexCoords.V  = bottom;
                m_sQuad.BottomRight.TexCoords.U = right;
                m_sQuad.BottomRight.TexCoords.V = bottom;
                m_sQuad.TopLeft.TexCoords.U     = left;
                m_sQuad.TopLeft.TexCoords.V     = top;
                m_sQuad.TopRight.TexCoords.U    = right;
                m_sQuad.TopRight.TexCoords.V    = top;
            }
        }