/// <summary> /// initializes the transition with a duration and with an RGB color /// </summary> public virtual bool InitWithDuration(float duration, CCScene scene, CCColor3B color) { if (base.InitWithDuration(duration, scene)) { m_tColor = new CCColor4B {R = color.R, G = color.G, B = color.B, A = 0}; } return true; }
public CCV2F_C4B_T2F() { Vertices = new CCVertex2F(); Colors = new CCColor4B(); TexCoords = new CCTex2F(); }
/// <summary> /// creates a CCLayer with color, width and height in Points /// </summary> public CCLayerColor(CCColor4B color, float width, float height) : this() { InitWithColorWidthHeight(color, width, height); }
/// <summary> /// initializes a CCLayer with color. Width and height are the window size. /// </summary> public virtual bool InitWithColor(CCColor4B color) { CCSize s = CCDirector.SharedDirector.WinSize; InitWithColorWidthHeight(color, s.Width, s.Height); return true; }
/// <summary> /// Initializes the CCLayer with a gradient between start and end in the direction of v. /// </summary> public virtual bool InitWithColor(CCColor4B start, CCColor4B end, CCPoint v) { m_endColor = new CCColor3B(); m_endColor.R = end.R; m_endColor.G = end.G; m_endColor.B = end.B; m_cEndOpacity = end.A; m_cStartOpacity = start.A; m_AlongVector = v; m_bCompressedInterpolation = true; return base.InitWithColor(new CCColor4B(start.R, start.G, start.B, 255)); }
/// <summary> /// Creates a full-screen CCLayer with a gradient between start and end in the direction of v. /// </summary> public static CCLayerGradient Create(CCColor4B start, CCColor4B end, CCPoint v) { var pLayer = new CCLayerGradient(); if (pLayer.InitWithColor(start, end, v)) { return pLayer; } return null; }
/// <summary> /// creates a CCLayer with color. Width and height are the window size. /// </summary> public static CCLayerColor Create(CCColor4B color) { var pLayer = new CCLayerColor(); pLayer.InitWithColor(color); return pLayer; }
public static void DrawSolidPoly(CCPoint[] vertices, int count, CCColor4B color, bool outline) { if (count == 2) { DrawPoly(vertices, count, false, color); return; } var colorFill = new Color(color.R, color.G, color.B, color.A); colorFill = colorFill * (outline ? 0.5f : 1.0f); for (int i = 1; i < count - 1; i++) { m_Batch.AddVertex(new Vector2(vertices[0].X, vertices[0].Y), colorFill, PrimitiveType.TriangleList); m_Batch.AddVertex(new Vector2(vertices[i].X, vertices[i].Y), colorFill, PrimitiveType.TriangleList); m_Batch.AddVertex(new Vector2(vertices[i + 1].X, vertices[i + 1].Y), colorFill, PrimitiveType.TriangleList); } if (outline) { DrawPoly(vertices, count, true, color); } }
public static void DrawPoint(CCPoint p, float size, CCColor4B color) { var verts = new CCPoint[4]; float hs = size / 2.0f; verts[0] = p + new CCPoint(-hs, -hs); verts[1] = p + new CCPoint(hs, -hs); verts[2] = p + new CCPoint(hs, hs); verts[3] = p + new CCPoint(-hs, hs); DrawPoly(verts, 4, false, true, color); }
public static void DrawLine(CCPoint origin, CCPoint destination, CCColor4B color) { float factor = CCDirector.SharedDirector.ContentScaleFactor; var c = new Color(color.R, color.G, color.B, color.A); m_Batch.AddVertex(new Vector2(origin.X * factor, origin.Y * factor), c, PrimitiveType.LineList); m_Batch.AddVertex(new Vector2(destination.X * factor, destination.Y * factor), c, PrimitiveType.LineList); }
public static void DrawEllipse(CCRect rect, CCColor4B color) { DrawEllipticalArc(rect, 0, 360, false, color); }
public static void DrawEllips(int x, int y, int width, int height, CCColor4B color) { DrawEllipticalArc(x,y,width,height,0,360,false, color); }
public static void DrawCircle(CCPoint center, float radius, float angle, int segments, bool drawLineToCenter, CCColor4B color) { float increment = MathHelper.Pi * 2.0f / segments; double theta = 0.0; CCPoint v1; CCPoint v2 = CCPoint.Zero; for (int i = 0; i < segments; i++) { v1 = center + new CCPoint((float) Math.Cos(theta), (float) Math.Sin(theta)) * radius; v2 = center + new CCPoint((float) Math.Cos(theta + increment), (float) Math.Sin(theta + increment)) * radius; DrawLine(v1, v2, color); theta += increment; } if (drawLineToCenter) { DrawLine(center, v2, color); } }
/// <summary> /// /// </summary> /// <param name="center"></param> /// <param name="radius"></param> /// <param name="angle">The amount of the circle to draw, in radiians</param> /// <param name="segments"></param> /// <param name="drawLineToCenter"></param> /// <param name="color"></param> public static void DrawCircle(b2Vec2 center, float radius, float angle, int segments, bool drawLineToCenter, b2Color color) { float increment = MathHelper.Pi * 2.0f / segments; double theta = 0.0; CCPoint v1 = CCPoint.Zero; CCPoint v2 = CCPoint.Zero; CCColor4B ccolor = new CCColor4B(color.r, color.b, color.g, 255); for (int i = 0; i < segments; i++) { v1.X = center.x + (float)Math.Cos(theta) * radius; v1.Y = center.y + (float)Math.Sin(theta) * radius; v2.X = center.x + (float)Math.Cos(theta + increment) * radius; v2.Y = center.y + (float)Math.Sin(theta + increment) * radius; DrawLine(v1, v2, ccolor); theta += increment; } if (drawLineToCenter) { v1.X = center.x; v1.Y = center.y; DrawLine(v1, v2, ccolor); } }
public static void DrawSolidPoly(CCPoint[] vertices, int count, CCColor4B color) { DrawSolidPoly(vertices, count, color, false); }
public static void DrawPoints(CCPoint[] points, float size, CCColor4B color) { DrawPoints(points, points.Length, size, color); }
public static void DrawArc(int x, int y, int width, int height, int startAngle, int sweepAngle, CCColor4B color) { DrawEllipticalArc(x,y,width,height,startAngle,sweepAngle,false, color); }
public static void DrawPoints(CCPoint[] points, int numberOfPoints, float size, CCColor4B color) { for (int i = 0; i < numberOfPoints; i++) { DrawPoint(points[i], size, color); } }
/// <summary> /// creates a CCLayer with color, width and height in Points /// </summary> public static CCLayerColor Create(CCColor4B color, float width, float height) { var pLayer = new CCLayerColor(); pLayer.InitWithColorWidthHeight(color, width, height); return pLayer; }
public static void DrawPoints(b2Vec2[] points, int numberOfPoints, float size, b2Color color) { CCColor4B ccolor = new CCColor4B(color.r, color.g, color.b, 255); CCPoint pt = CCPoint.Zero; for (int i = 0; i < numberOfPoints; i++) { pt.X = points[i].x; pt.Y = points[i].y; DrawPoint(pt, size, ccolor); } }
public override void Draw() { var map = (CCTMXTiledMap) GetChildByTag(kTagTileMap); CCTMXObjectGroup group = map.ObjectGroupNamed("Object Group 1"); List<Dictionary<string, string>> objects = group.Objects; foreach (var dict in objects) { int x = int.Parse(dict["x"]); int y = int.Parse(dict["y"]); int width = dict.ContainsKey("width") ? int.Parse(dict["width"]) : 0; int height = dict.ContainsKey("height") ? int.Parse(dict["height"]) : 0; //glLineWidth(3); var color = new CCColor4B(255, 255, 0, 255); CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawLine(new CCPoint(x, y), new CCPoint(x + width, y), color); CCDrawingPrimitives.DrawLine(new CCPoint(x + width, y), new CCPoint(x + width, y + height), color); CCDrawingPrimitives.DrawLine(new CCPoint(x + width, y + height), new CCPoint(x, y + height), color); CCDrawingPrimitives.DrawLine(new CCPoint(x, y + height), new CCPoint(x, y), color); CCDrawingPrimitives.End(); //glLineWidth(1); } }
/// <summary> /// draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points. /// The polygon can be closed or open /// </summary> public static void DrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, CCColor4B color) { DrawPoly(vertices, numOfVertices, closePolygon, false, color); }
/// <summary> /// Initializes the CCLayer with a gradient between start and end. /// </summary> public virtual bool InitWithColor(CCColor4B start, CCColor4B end) { return InitWithColor(start, end, new CCPoint(0, -1)); }
/// <summary> /// draws a polygon given a pointer to CCPoint coordiantes and the number of vertices measured in points. /// The polygon can be closed or open and optionally filled with current GL color /// </summary> public static void DrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, CCColor4B color) { var c = new Color(color.R, color.G, color.B, color.A); if (fill) { for (int i = 1; i < numOfVertices - 1; i++) { m_Batch.AddVertex(new Vector2(vertices[0].X, vertices[0].Y), c, PrimitiveType.TriangleList); m_Batch.AddVertex(new Vector2(vertices[i].X, vertices[i].Y), c, PrimitiveType.TriangleList); m_Batch.AddVertex(new Vector2(vertices[i + 1].X, vertices[i + 1].Y), c, PrimitiveType.TriangleList); } } else { for (int i = 0; i < numOfVertices - 1; i++) { m_Batch.AddVertex(new Vector2(vertices[i].X, vertices[i].Y), c, PrimitiveType.LineList); m_Batch.AddVertex(new Vector2(vertices[i + 1].X, vertices[i + 1].Y), c, PrimitiveType.LineList); } if (closePolygon) { m_Batch.AddVertex(new Vector2(vertices[numOfVertices - 1].X, vertices[numOfVertices - 1].Y), c, PrimitiveType.LineList); m_Batch.AddVertex(new Vector2(vertices[0].X, vertices[0].Y), c, PrimitiveType.LineList); } } }
protected override void UpdateColor() { float h = CCPointExtension.Length(m_AlongVector); if (h == 0) return; double c = Math.Sqrt(2.0); var u = new CCPoint(m_AlongVector.X / h, m_AlongVector.Y / h); // Compressed Interpolation mode if (m_bCompressedInterpolation) { float h2 = 1 / (Math.Abs(u.X) + Math.Abs(u.Y)); u = CCPointExtension.Multiply(u, h2 * (float) c); } float opacityf = m_cOpacity / 255.0f; var S = new CCColor4B { R = m_tColor.R, G = m_tColor.G, B = m_tColor.B, A = (byte) (m_cStartOpacity * opacityf) }; var E = new CCColor4B { R = m_endColor.R, G = m_endColor.G, B = m_endColor.B, A = (byte) (m_cEndOpacity * opacityf) }; // (-1, -1) m_pVertices[0].Color = new Color( (byte) (E.R + (S.R - E.R) * ((c + u.X + u.Y) / (2.0f * c))), (byte) (E.G + (S.G - E.G) * ((c + u.X + u.Y) / (2.0f * c))), (byte) (E.B + (S.B - E.B) * ((c + u.X + u.Y) / (2.0f * c))), (byte) (E.A + (S.A - E.A) * ((c + u.X + u.Y) / (2.0f * c))) ); // (1, -1) m_pVertices[1].Color = new Color( (byte) (E.R + (S.R - E.R) * ((c - u.X + u.Y) / (2.0f * c))), (byte) (E.G + (S.G - E.G) * ((c - u.X + u.Y) / (2.0f * c))), (byte) (E.B + (S.B - E.B) * ((c - u.X + u.Y) / (2.0f * c))), (byte) (E.A + (S.A - E.A) * ((c - u.X + u.Y) / (2.0f * c))) ); // (-1, 1) m_pVertices[2].Color = new Color( (byte) (E.R + (S.R - E.R) * ((c + u.X - u.Y) / (2.0f * c))), (byte) (E.G + (S.G - E.G) * ((c + u.X - u.Y) / (2.0f * c))), (byte) (E.B + (S.B - E.B) * ((c + u.X - u.Y) / (2.0f * c))), (byte) (E.A + (S.A - E.A) * ((c + u.X - u.Y) / (2.0f * c))) ); // (1, 1) m_pVertices[3].Color = new Color( (byte) (E.R + (S.R - E.R) * ((c - u.X - u.Y) / (2.0f * c))), (byte) (E.G + (S.G - E.G) * ((c - u.X - u.Y) / (2.0f * c))), (byte) (E.B + (S.B - E.B) * ((c - u.X - u.Y) / (2.0f * c))), (byte) (E.A + (S.A - E.A) * ((c - u.X - u.Y) / (2.0f * c))) ); m_bChanged = true; }
public static void DrawArc(CCRect rect, int startAngle, int sweepAngle, CCColor4B color) { DrawEllipticalArc(rect, startAngle, sweepAngle, false, color); }
/// <summary> /// initializes a CCLayer with color, width and height in Points /// </summary> public virtual bool InitWithColorWidthHeight(CCColor4B color, float width, float height) { // default blend function m_tBlendFunc.Source = CCMacros.CCDefaultSourceBlending; m_tBlendFunc.Destination = CCMacros.CCDefaultDestinationBlending; m_tColor.R = color.R; m_tColor.G = color.G; m_tColor.B = color.B; m_cOpacity = color.A; UpdateColor(); ContentSize = new CCSize(width, height); return true; }
public static void DrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, CCColor4B color) { var vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.SharedDirector.ContentScaleFactor; float t = 0.0f; for (int i = 0; i < segments; i++) { float x = (float) Math.Pow(1 - t, 2) * origin.X + 2.0f * (1 - t) * t * control.X + t * t * destination.X; float y = (float) Math.Pow(1 - t, 2) * origin.Y + 2.0f * (1 - t) * t * control.Y + t * t * destination.Y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.R, color.G, color.B, color.A); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor { Position = new Vector3(destination.X * factor, destination.Y * factor, 0), Color = new Color(color.R, color.G, color.B, color.A), }; BasicEffect basicEffect = DrawManager.PrimitiveEffect; basicEffect.Projection = DrawManager.ProjectionMatrix; basicEffect.View = DrawManager.ViewMatrix; basicEffect.World = DrawManager.WorldMatrix; foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Apply(); basicEffect.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, vertices, 0, segments); } }
/// <summary> /// creates a CCLayer with color. Width and height are the window size. /// </summary> public CCLayerColor(CCColor4B color) : this() { InitWithColor(color); }
/** Returns a ccColor4F from a ccColor4B. @since v0.99.1 */ public static CCColor4F CreateColor(CCColor4B c) { CCColor4F c4 = new CCColor4F(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f, c.A / 255.0f); return c4; }