private void UpdateColor() { var color4 = new CCColor4B(_displayedColor.R, _displayedColor.G, _displayedColor.B, _displayedOpacity); if (m_bOpacityModifyRGB) { color4.R = (byte)(color4.R * _displayedOpacity / 255.0f); color4.G = (byte)(color4.G * _displayedOpacity / 255.0f); color4.B = (byte)(color4.B * _displayedOpacity / 255.0f); } m_sQuad.BottomLeft.Colors = color4; m_sQuad.BottomRight.Colors = color4; m_sQuad.TopLeft.Colors = color4; m_sQuad.TopRight.Colors = color4; // renders using Sprite Manager if (m_pobBatchNode != null) { if (m_uAtlasIndex != CCMacros.CCSpriteIndexNotInitialized) { m_pobTextureAtlas.UpdateQuad(ref m_sQuad, m_uAtlasIndex); } else { // no need to set it recursively // update dirty_, don't update recursiveDirty_ m_bDirty = true; } } // self render // do nothing }
public Atlas1() { m_textureAtlas = CCTextureAtlas.Create(TestResource.s_AtlasTest, 3); //m_textureAtlas.retain(); CCSize s = CCDirector.SharedDirector.WinSize; // // Notice: u,v tex coordinates are inverted // CCV3F_C4B_T2F_Quad[] quads = { new CCV3F_C4B_T2F_Quad() { BottomLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(0,0,0), Colors = new CCColor4B(0,0,255,255),TexCoords = new CCTex2F(0.0f,1.0f)}, // bottom left BottomRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width,0,0), Colors = new CCColor4B(0,0,255,0),TexCoords = new CCTex2F(1.0f,1.0f)}, // bottom right TopLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(0,s.Height,0), Colors = new CCColor4B(0,0,255,0),TexCoords = new CCTex2F(0.0f,0.0f)}, // bottom right TopRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width,s.Height,0), Colors = new CCColor4B(0,0,255,255),TexCoords = new CCTex2F(1.0f,0.0f)}, // bottom right }, new CCV3F_C4B_T2F_Quad() { BottomLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(40,40,0), Colors = new CCColor4B(255,255,255,255),TexCoords = new CCTex2F(0.0f,0.2f)}, // bottom left BottomRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(120,80,0), Colors = new CCColor4B(255,0,0,255),TexCoords = new CCTex2F(0.5f,0.2f)}, // bottom right TopLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(40,160,0), Colors = new CCColor4B(255,255,255,255),TexCoords = new CCTex2F(0.0f,0.0f)}, // bottom right TopRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(160,160,0), Colors = new CCColor4B(0,255,0,255),TexCoords = new CCTex2F(0.5f,0.0f)}, // bottom right }, new CCV3F_C4B_T2F_Quad() { BottomLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width/2,40,0), Colors = new CCColor4B(255,0,0,255),TexCoords = new CCTex2F(0.0f,1.0f)}, // bottom left BottomRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width,40,0), Colors = new CCColor4B(0,255,0,255),TexCoords = new CCTex2F(1.0f,1.0f)}, // bottom right TopLeft = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width/2-50,200,0), Colors = new CCColor4B(0,0,255,255),TexCoords = new CCTex2F(0.0f,0.0f)}, // bottom right TopRight = new CCV3F_C4B_T2F() { Vertices = new CCVertex3F(s.Width,100,0), Colors = new CCColor4B(255,255,0,255),TexCoords = new CCTex2F(1.0f,0.0f)}, // bottom right }, }; for( int i=0;i<3;i++) { m_textureAtlas.UpdateQuad(ref quads[i], i); } }
public void UpdateTransform() { Debug.Assert(m_pobBatchNode != null, "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode"); // recaculate matrix only if it is dirty if (Dirty) { // If it is not visible, or one of its ancestors is not visible, then do nothing: if (!m_bIsVisible || (m_pParent != null && m_pParent != m_pobBatchNode && ((CCSprite)m_pParent).m_bShouldBeHidden)) { m_sQuad.BottomRight.Vertices = m_sQuad.TopLeft.Vertices = m_sQuad.TopRight.Vertices = m_sQuad.BottomLeft.Vertices = new CCVertex3F(0, 0, 0); m_bShouldBeHidden = true; } else { m_bShouldBeHidden = false; if (m_pParent == null || m_pParent == m_pobBatchNode) { m_transformToBatch = NodeToParentTransform(); } else { Debug.Assert((m_pParent as CCSprite) != null, "Logic error in CCSprite. Parent must be a CCSprite"); m_transformToBatch = CCAffineTransform.CCAffineTransformConcat(NodeToParentTransform(), ((CCSprite)m_pParent). m_transformToBatch); } // // calculate the Quad based on the Affine Matrix // CCSize size = m_obRect.Size; float x1 = m_obOffsetPosition.X; float y1 = m_obOffsetPosition.Y; float x2 = x1 + size.Width; float y2 = y1 + size.Height; float x = m_transformToBatch.tx; float y = m_transformToBatch.ty; float cr = m_transformToBatch.a; float sr = m_transformToBatch.b; float cr2 = m_transformToBatch.d; float sr2 = -m_transformToBatch.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.BottomLeft.Vertices = new CCVertex3F(ax, ay, m_fVertexZ); m_sQuad.BottomRight.Vertices = new CCVertex3F(bx, by, m_fVertexZ); m_sQuad.TopLeft.Vertices = new CCVertex3F(dx, dy, m_fVertexZ); m_sQuad.TopRight.Vertices = new CCVertex3F(cx, cy, m_fVertexZ); } m_pobTextureAtlas.UpdateQuad(ref m_sQuad, m_uAtlasIndex); m_bRecursiveDirty = false; m_bDirty = false; } // recursively iterate over children if (m_bHasChildren) { CCNode[] elements = m_pChildren.Elements; if (m_pobBatchNode != null) { for (int i = 0, count = m_pChildren.count; i < count; i++) { ((CCSprite)elements[i]).UpdateTransform(); } } else { for (int i = 0, count = m_pChildren.count; i < count; i++) { var sprite = elements[i] as CCSprite; if (sprite != null) { sprite.UpdateTransform(); } } } } }