public override void OnEnter() { base.OnEnter(); var windowSize = Layer.VisibleBoundsWorldspace.Size; CCRenderTexture text = new CCRenderTexture(windowSize, windowSize); AddChild(text, 24); CCDrawNode draw = new CCDrawNode(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(windowSize.Height / 4, 0), new CCPoint(windowSize.Width, windowSize.Height / 5), new CCPoint(windowSize.Width / 3 * 2, windowSize.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); draw.AnchorPoint = CCPoint.AnchorLowerLeft; text.Begin(); draw.Visit(); text.End(); }
/* * TL TR * 0----1 0,1,2,3 = index offsets for vertex indices * | /| * | / | * | / | * |/ | * 2----3 * BL BR */ void GenerateStripes(CCSize textureSizeInPixels, CCColor4B c2, int numberOfStripes) { var gradientNode = new CCDrawNode(); // Layer 1: Stripes CCV3F_C4B[] vertices = new CCV3F_C4B[numberOfStripes * 6]; var textureWidth = textureSizeInPixels.Width; var textureHeight = textureSizeInPixels.Height; int nVertices = 0; float x1 = -textureHeight; float x2; float y1 = textureHeight; float y2 = 0; float dx = textureWidth / numberOfStripes * 2; float stripeWidth = dx / 2; for (int i = 0; i < numberOfStripes; i++) { x2 = x1 + textureHeight; // Left triangle TL - 0 vertices[nVertices].Vertices = new CCVertex3F(x1, y1, 0); vertices[nVertices++].Colors = c2; // Left triangle BL - 2 vertices[nVertices].Vertices = new CCVertex3F(x1 + stripeWidth, y1, 0); vertices[nVertices++].Colors = c2; // Left triangle TR - 1 vertices[nVertices].Vertices = new CCVertex3F(x2, y2, 0); vertices[nVertices++].Colors = c2; // Right triangle BL - 2 vertices[nVertices].Vertices = vertices[nVertices - 2].Vertices; vertices[nVertices++].Colors = c2; // Right triangle BR - 3 vertices[nVertices].Vertices = vertices[nVertices - 2].Vertices; vertices[nVertices++].Colors = c2; // Right triangle TR - 1 vertices[nVertices].Vertices = new CCVertex3F(x2 + stripeWidth, y2, 0); vertices[nVertices++].Colors = c2; x1 += dx; } gradientNode.DrawTriangleList(vertices); gradientNode.Visit(); }
void SaveImage(object sender) { RemoveChildByTag(spriteTag); var renderSize = canvasNode.BoundingRect.Size; var rtm = new CCRenderTexture(renderSize, renderSize); rtm.BeginWithClear(CCColor4B.Green); canvasNode.Position -= canvasNode.BoundingRect.Origin; canvasNode.Visit(); rtm.End(); canvasNode.Position = CCPoint.Zero; rtm.Texture.IsAntialiased = true; rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft; rtm.Sprite.Opacity = 127; AddChild(rtm.Sprite, 50, spriteTag);; }
public override void OnEnter() { base.OnEnter(); CCDrawNode circle = new CCDrawNode(); circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255)); CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rtm.BeginWithClear(CCColor4B.Orange); circle.Visit(); // Draw to rendertarget rtm.End(); rtm.Position = VisibleBoundsWorldspace.Center; rtm.AnchorPoint = CCPoint.AnchorMiddle; AddChild(rtm); }
void SaveImage(object sender) { RemoveChildByTag(spriteTag); var renderSize = canvasNode.BoundingRect.Size; var renderOrigin = canvasNode.BoundingRect.Origin; // here we calculate the translation of the rendering. It should be the offset of BoundingRect Origin // this will then be passed to the Visit(ref CCAffineTransform) method. var translate = CCAffineTransform.Translate(canvasNode.AffineWorldTransform, -renderOrigin.X, -renderOrigin.Y); var rtm = new CCRenderTexture(renderSize, renderSize); rtm.BeginWithClear(CCColor4B.Green); canvasNode.Visit(ref translate); rtm.End(); rtm.Texture.IsAntialiased = true; rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft; rtm.Sprite.Opacity = 127; AddChild(rtm.Sprite, 50, spriteTag);; }
private void Touch(CCTouch touch, CCEvent e) { var square = touch.Location.GetSquare(this.piece.Board.Size); if (!square.Equals(this.lastMovePosition)) { drawNode.Clear(); this.lastMovePosition = square; if (this.possibleSquares.Any(x => x.Equals(square))) { var size = this.piece.Board.Size / 8; var color = new CCColor4B(0, 199, 90, 0x66); var point = square.GetPoint(this.piece.Board.Size); drawNode.DrawSolidCircle(point, size, color); drawNode.Visit(); } } this.Position = touch.Location; }
public override void OnEnter() { base.OnEnter(); CCDrawNode circle = new CCDrawNode(); circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255)); CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rtm.BeginWithClear(CCColor4B.Orange); circle.Visit(); // Draw to rendertarget rtm.End(); // Create a new sprite from the render target texture var sprite = new CCSprite(rtm.Texture); sprite.Position = VisibleBoundsWorldspace.Center; AddChild(sprite); }
/* * TL TR * 0----1 0,1,2,3 = index offsets for vertex indices * | /| * | / | * | / | * |/ | * 2----3 * BL BR */ void GenerateGradient(CCSize textureSizeInPixels) { var gradientNode = new CCDrawNode(); var gradientAlpha = new CCColor4B(0, 0, 0, (byte)(0.7f * 255f)); CCV3F_C4B[] vertices = new CCV3F_C4B[6]; // Left triangle TL - 0 vertices[0].Vertices = new CCVertex3F(0, textureSizeInPixels.Height, 0); vertices[0].Colors = CCColor4B.Transparent; // Left triangle BL - 2 vertices[1].Vertices = new CCVertex3F(0, 0, 0); vertices[1].Colors = gradientAlpha; // Left triangle TR - 1 vertices[2].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0); vertices[2].Colors = CCColor4B.Transparent; // Right triangle BL - 2 vertices[3].Vertices = new CCVertex3F(0, 0, 0); vertices[3].Colors = gradientAlpha; // Right triangle BR - 3 vertices[4].Vertices = new CCVertex3F(textureSizeInPixels.Width, 0, 0); vertices[4].Colors = gradientAlpha; // Right triangle TR - 1 vertices[5].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0); vertices[5].Colors = CCColor4B.Transparent; gradientNode.DrawTriangleList(vertices); gradientNode.Visit(); }