Ejemplo n.º 1
0
        public virtual bool init()
        {
            this.m_bDirty = this.m_bRecursiveDirty = false;
            this.useSelfRender();
            this.m_bOpacityModifyRGB        = true;
            this.m_nOpacity                 = 0xff;
            this.m_sColor                   = new ccColor3B(0xff, 0xff, 0xff);
            this.m_sColorUnmodified         = new ccColor3B(0xff, 0xff, 0xff);
            this.m_sBlendFunc               = new ccBlendFunc();
            this.m_sBlendFunc.src           = ccMacros.CC_BLEND_SRC;
            this.m_sBlendFunc.dst           = ccMacros.CC_BLEND_DST;
            this.Texture                    = null;
            this.m_sQuad                    = new ccV3F_C4B_T2F_Quad();
            this.m_bFlipX                   = this.m_bFlipY = false;
            this.anchorPoint                = CCPointExtension.ccp(0.5f, 0.5f);
            this.m_obOffsetPositionInPixels = new CCPoint();
            this.m_eHonorParentTransform    = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
            this.m_bHasChildren             = false;
            ccColor4B colorb = new ccColor4B(0xff, 0xff, 0xff, 0xff);

            this.m_sQuad.bl.colors = colorb;
            this.m_sQuad.br.colors = colorb;
            this.m_sQuad.tl.colors = colorb;
            this.m_sQuad.tr.colors = colorb;
            this.setTextureRectInPixels(new CCRect(), false, new CCSize());
            return(true);
        }
Ejemplo n.º 2
0
        public virtual bool init()
        {
            m_bDirty = m_bRecursiveDirty = false;

            // by default use "Self Render".
            // if the sprite is added to an batchnode, then it will automatically switch to "SpriteSheet Render"
            useSelfRender();

            m_bOpacityModifyRGB = true;
            m_nOpacity          = 255;
            m_sColor            = new ccColor3B(255, 255, 255);
            m_sColorUnmodified  = new ccColor3B(255, 255, 255);

            m_sBlendFunc     = new ccBlendFunc();
            m_sBlendFunc.src = ccMacros.CC_BLEND_SRC;
            m_sBlendFunc.dst = ccMacros.CC_BLEND_DST;


            // update texture (calls updateBlendFunc)
            Texture = null;

            // clean the Quad
            m_sQuad = new ccV3F_C4B_T2F_Quad();

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            anchorPoint = (CCPointExtension.ccp(0.5f, 0.5f));

            // zwoptex default values
            m_obOffsetPositionInPixels = new CCPoint();

            m_eHonorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
            m_bHasChildren          = false;

            // Atlas: Color
            ccColor4B tmpColor = new ccColor4B(255, 255, 255, 255);

            m_sQuad.bl.colors = tmpColor;
            m_sQuad.br.colors = tmpColor;
            m_sQuad.tl.colors = tmpColor;
            m_sQuad.tr.colors = tmpColor;

            // Atlas: Vertex

            // updated in "useSelfRender"

            // Atlas: TexCoords

            setTextureRectInPixels(new CCRect(), false, new CCSize());

            return(true);
        }
Ejemplo n.º 3
0
        public virtual bool init()
        {
            m_bDirty = m_bRecursiveDirty = false;

            // by default use "Self Render".
            // if the sprite is added to an batchnode, then it will automatically switch to "SpriteSheet Render"
            useSelfRender();

            m_bOpacityModifyRGB = true;
            m_nOpacity = 255;
            m_sColor = new ccColor3B(255, 255, 255);
            m_sColorUnmodified = new ccColor3B(255, 255, 255);

            m_sBlendFunc = new ccBlendFunc();
            m_sBlendFunc.src = ccMacros.CC_BLEND_SRC;
            m_sBlendFunc.dst = ccMacros.CC_BLEND_DST;

            // update texture (calls updateBlendFunc)
            Texture = null;

            // clean the Quad
            m_sQuad = new ccV3F_C4B_T2F_Quad();

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            AnchorPoint = (CCPointExtension.ccp(0.5f, 0.5f));

            // zwoptex default values
            m_obOffsetPositionInPixels = new CCPoint();

            m_eHonorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
            m_bHasChildren = false;

            // Atlas: Color
            ccColor4B tmpColor = new ccColor4B(255, 255, 255, 255);
            m_sQuad.bl.colors = tmpColor;
            m_sQuad.br.colors = tmpColor;
            m_sQuad.tl.colors = tmpColor;
            m_sQuad.tr.colors = tmpColor;

            // Atlas: Vertex

            // updated in "useSelfRender"

            // Atlas: TexCoords

            setTextureRectInPixels(new CCRect(), false, new CCSize());

            return true;
        }
Ejemplo n.º 4
0
        // BatchNode methods

        /// <summary>
        /// updates the quad according the the rotation, position, scale values.
        /// </summary>
        public void updateTransform()
        {
            Debug.Assert(m_bUsesBatchNode != null);

            // optimization. Quick return if not dirty
            if (!m_bDirty)
            {
                return;
            }

            CCAffineTransform matrix;

            // Optimization: if it is not visible, then do nothing
            if (!m_bIsVisible)
            {
                m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0);
                m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);
                //m_bDirty = m_bRecursiveDirty = false;
                return;
            }

            // Optimization: If parent is batchnode, or parent is nil
            // build Affine transform manually
            if (m_pParent == null || m_pParent == m_pobBatchNode)
            {
                float radians = -ccMacros.CC_DEGREES_TO_RADIANS(m_fRotation);
                float c       = (float)Math.Cos(radians);
                float s       = (float)Math.Sin(radians);

                matrix = CCAffineTransform.CCAffineTransformMake(c * m_fScaleX, s * m_fScaleX,
                                                                 -s * m_fScaleY, c * m_fScaleY,
                                                                 m_tPositionInPixels.x, m_tPositionInPixels.y);
                if (m_fSkewX > 0 || m_fSkewY > 0)
                {
                    CCAffineTransform skewMatrix = CCAffineTransform.CCAffineTransformMake(1.0f, (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewY)),
                                                                                           (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f,
                                                                                           0.0f, 0.0f);
                    matrix = CCAffineTransform.CCAffineTransformConcat(skewMatrix, matrix);
                }
                matrix = CCAffineTransform.CCAffineTransformTranslate(matrix, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
            }
            else // parent_ != batchNode_
            {
                // else do affine transformation according to the HonorParentTransform
                matrix = CCAffineTransform.CCAffineTransformMakeIdentity();
                ccHonorParentTransform prevHonor = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;

                CCNode p = this;
                while (p != null && p is CCSprite && p != m_pobBatchNode)
                {
                    // Might happen. Issue #1053
                    // how to implement, we can not use dynamic
                    // CCAssert( [p isKindOfClass:[CCSprite class]], @"CCSprite should be a CCSprite subclass. Probably you initialized an sprite with a batchnode, but you didn't add it to the batch node." );
                    transformValues_ tv = new transformValues_();
                    ((CCSprite)p).getTransformValues(tv);

                    // If any of the parents are not visible, then don't draw this node
                    if (!tv.visible)
                    {
                        m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0);
                        m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);
                        m_bDirty = m_bRecursiveDirty = false;

                        return;
                    }

                    CCAffineTransform newMatrix = CCAffineTransform.CCAffineTransformMakeIdentity();

                    // 2nd: Translate, Skew, Rotate, Scale
                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, tv.pos.x, tv.pos.y);
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformRotate(newMatrix, -ccMacros.CC_DEGREES_TO_RADIANS(tv.rotation));
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SKEW != 0)
                    {
                        CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f,
                                                                                         (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.y)),
                                                                                         (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.x)), 1.0f, 0.0f, 0.0f);
                        // apply the skew to the transform
                        newMatrix = CCAffineTransform.CCAffineTransformConcat(skew, newMatrix);
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformScale(newMatrix, tv.scale.x, tv.scale.y);
                    }

                    // 3rd: Translate anchor point
                    newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, -tv.ap.x, -tv.ap.y);

                    // 4th: Matrix multiplication
                    matrix = CCAffineTransform.CCAffineTransformConcat(matrix, newMatrix);

                    prevHonor = ((CCSprite)p).honorParentTransform;

                    p = p.parent;
                }
            }

            //
            // calculate the Quad based on the Affine Matrix
            //
            CCSize size = m_obRectInPixels.size;

            float x1 = m_obOffsetPositionInPixels.x;
            float y1 = m_obOffsetPositionInPixels.y;

            float x2 = x1 + size.width;
            float y2 = y1 + size.height;
            float x  = matrix.tx;
            float y  = matrix.ty;

            float cr  = matrix.a;
            float sr  = matrix.b;
            float cr2 = matrix.d;
            float sr2 = -matrix.c;
            float ax  = x1 * cr - y1 * sr2 + x;
            float ay  = x1 * sr + y1 * cr2 + y;

            float bx = x2 * cr - y1 * sr2 + x;
            float by = x2 * sr + y1 * cr2 + y;

            float cx = x2 * cr - y2 * sr2 + x;
            float cy = x2 * sr + y2 * cr2 + y;

            float dx = x1 * cr - y2 * sr2 + x;
            float dy = x1 * sr + y2 * cr2 + y;

            m_sQuad.bl.vertices = new ccVertex3F((float)ax, (float)ay, m_fVertexZ);
            m_sQuad.br.vertices = new ccVertex3F((float)bx, (float)by, m_fVertexZ);
            m_sQuad.tl.vertices = new ccVertex3F((float)dx, (float)dy, m_fVertexZ);
            m_sQuad.tr.vertices = new ccVertex3F((float)cx, (float)cy, m_fVertexZ);

            m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);

            m_bDirty = m_bRecursiveDirty = false;
        }
Ejemplo n.º 5
0
 public void updateTransform()
 {
     if (this.m_bDirty)
     {
         if (!base.m_bIsVisible)
         {
             this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f);
             this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
         }
         else
         {
             CCAffineTransform transform;
             if ((base.m_pParent == null) || (base.m_pParent == this.m_pobBatchNode))
             {
                 float num  = -ccMacros.CC_DEGREES_TO_RADIANS(base.m_fRotation);
                 float num2 = (float)Math.Cos((double)num);
                 float num3 = (float)Math.Sin((double)num);
                 transform = CCAffineTransform.CCAffineTransformMake(num2 * base.m_fScaleX, num3 * base.m_fScaleX, -num3 * base.m_fScaleY, num2 * base.m_fScaleY, base.m_tPositionInPixels.x, base.m_tPositionInPixels.y);
                 if ((base.m_fSkewX > 0f) || (base.m_fSkewY > 0f))
                 {
                     transform = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewY)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewX)), 1f, 0f, 0f), transform);
                 }
                 transform = CCAffineTransform.CCAffineTransformTranslate(transform, -base.m_tAnchorPointInPixels.x, -base.m_tAnchorPointInPixels.y);
             }
             else
             {
                 transform = CCAffineTransform.CCAffineTransformMakeIdentity();
                 ccHonorParentTransform honorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
                 for (CCNode node = this; ((node != null) && (node is CCSprite)) && (node != this.m_pobBatchNode); node = node.parent)
                 {
                     transformValues_ tv = new transformValues_();
                     ((CCSprite)node).getTransformValues(tv);
                     if (!tv.visible)
                     {
                         this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f);
                         this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
                         this.m_bDirty = this.m_bRecursiveDirty = false;
                         return;
                     }
                     CCAffineTransform t = CCAffineTransform.CCAffineTransformMakeIdentity();
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformTranslate(t, tv.pos.x, tv.pos.y);
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformRotate(t, -ccMacros.CC_DEGREES_TO_RADIANS(tv.rotation));
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.y)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.x)), 1f, 0f, 0f), t);
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformScale(t, tv.scale.x, tv.scale.y);
                     }
                     t                    = CCAffineTransform.CCAffineTransformTranslate(t, -tv.ap.x, -tv.ap.y);
                     transform            = CCAffineTransform.CCAffineTransformConcat(transform, t);
                     honorParentTransform = ((CCSprite)node).honorParentTransform;
                 }
             }
             CCSize size  = this.m_obRectInPixels.size;
             float  x     = this.m_obOffsetPositionInPixels.x;
             float  y     = this.m_obOffsetPositionInPixels.y;
             float  num6  = x + size.width;
             float  num7  = y + size.height;
             float  tx    = transform.tx;
             float  ty    = transform.ty;
             float  a     = transform.a;
             float  b     = transform.b;
             float  d     = transform.d;
             float  num13 = -transform.c;
             float  inx   = ((x * a) - (y * num13)) + tx;
             float  iny   = ((x * b) + (y * d)) + ty;
             float  num16 = ((num6 * a) - (y * num13)) + tx;
             float  num17 = ((num6 * b) + (y * d)) + ty;
             float  num18 = ((num6 * a) - (num7 * num13)) + tx;
             float  num19 = ((num6 * b) + (num7 * d)) + ty;
             float  num20 = ((x * a) - (num7 * num13)) + tx;
             float  num21 = ((x * b) + (num7 * d)) + ty;
             this.m_sQuad.bl.vertices = new ccVertex3F(inx, iny, base.m_fVertexZ);
             this.m_sQuad.br.vertices = new ccVertex3F(num16, num17, base.m_fVertexZ);
             this.m_sQuad.tl.vertices = new ccVertex3F(num20, num21, base.m_fVertexZ);
             this.m_sQuad.tr.vertices = new ccVertex3F(num18, num19, base.m_fVertexZ);
             this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
             this.m_bDirty = this.m_bRecursiveDirty = false;
         }
     }
 }