public override void Draw() { CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawLine(new CCPoint(0, _touchPoint.Y), new CCPoint(ContentSize.Width, _touchPoint.Y), new CCColor4B(_touchColor.R, _touchColor.G, _touchColor.B, 255)); CCDrawingPrimitives.DrawLine(new CCPoint(_touchPoint.X, 0), new CCPoint(_touchPoint.X, ContentSize.Height), new CCColor4B(_touchColor.R, _touchColor.G, _touchColor.B, 255)); CCDrawingPrimitives.DrawPoint(_touchPoint, 30, new CCColor4B(_touchColor.R, _touchColor.G, _touchColor.B, 255)); CCDrawingPrimitives.End(); }
protected override void Draw() { CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawColor = new CCColor4B(_touchColor.R, _touchColor.G, _touchColor.B, 255); CCDrawingPrimitives.LineWidth = 10; CCDrawingPrimitives.DrawLine(new CCPoint(0, _touchPoint.Y), new CCPoint(ContentSize.Width, _touchPoint.Y)); CCDrawingPrimitives.DrawLine(new CCPoint(_touchPoint.X, 0), new CCPoint(_touchPoint.X, ContentSize.Height)); CCDrawingPrimitives.LineWidth = 1; CCDrawingPrimitives.PointSize = 30; CCDrawingPrimitives.DrawPoint(_touchPoint); CCDrawingPrimitives.End(); }
public override void Draw() { base.Draw(); CCApplication app = CCApplication.SharedApplication; CCSize s = CCDirector.SharedDirector.WinSize; CCDrawingPrimitives.Begin(); // draw a simple line CCDrawingPrimitives.DrawLine(new CCPoint(0, 0), new CCPoint(s.Width, s.Height), new CCColor4B(255, 255, 255, 255)); // line: color, width, aliased CCDrawingPrimitives.DrawLine(new CCPoint(0, s.Height), new CCPoint(s.Width, 0), new CCColor4B(255, 0, 0, 255)); // draw big point in the center CCDrawingPrimitives.DrawPoint(new CCPoint(s.Width / 2, s.Height / 2), 64, new CCColor4B(0, 0, 255, 128)); // draw 4 small points CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) }; CCDrawingPrimitives.DrawPoints(points, 4, 4, new CCColor4B(0, 255, 255, 255)); // draw a green circle with 10 segments CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 100, 0, 10, false, new CCColor4B(0, 255, 0, 255)); // draw a green circle with 50 segments with line to center CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 50, CCMacros.CCDegreesToRadians(90), 50, true, new CCColor4B(0, 255, 255, 255)); // draw an arc within rectangular region CCDrawingPrimitives.DrawArc(new CCRect(200, 200, 100, 200), 0, 180, new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue)); // draw an ellipse within rectangular region CCDrawingPrimitives.DrawEllipse(new CCRect(500, 200, 100, 200), new CCColor4B(255, 0, 0, 255)); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100, new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue)); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260, new CCColor4B(Microsoft.Xna.Framework.Color.Aquamarine)); // open yellow poly CCPoint[] vertices = { new CCPoint(0, 0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100), new CCPoint(50, 100) }; CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255)); // filled poly CCPoint[] filledVertices = { new CCPoint(0, 120), new CCPoint(50, 120), new CCPoint(50, 170), new CCPoint(25, 200), new CCPoint(0, 170) }; CCDrawingPrimitives.DrawSolidPoly(filledVertices, 5, new CCColor4B(128, 128, 255, 255)); // closed purble poly CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) }; CCDrawingPrimitives.DrawPoly(vertices2, 3, true, new CCColor4B(255, 0, 255, 255)); // draw quad bezier path CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, s.Height), new CCPoint(s.Width / 2, s.Height / 2), new CCPoint(s.Width, s.Height), 50, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path CCDrawingPrimitives.DrawCubicBezier(new CCPoint(s.Width / 2, s.Height / 2), new CCPoint(s.Width / 2 + 30, s.Height / 2 + 50), new CCPoint(s.Width / 2 + 60, s.Height / 2 - 50), new CCPoint(s.Width, s.Height / 2), 100, new CCColor4B(255, 0, 255, 255)); //draw a solid polygon CCPoint[] vertices3 = { new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190), new CCPoint(90, 160) }; CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4B(255, 255, 0, 255)); CCDrawingPrimitives.End(); }
protected override void Draw() { base.Draw(); CCSize size = Layer.VisibleBoundsWorldspace.Size; var visibleRect = VisibleBoundsWorldspace; CCDrawingPrimitives.Begin(); // *NOTE* Using the Director.ContentScaleFactor for now until we work something out with the initialization // CCDrawPriitives should be able to do this converstion themselves. // draw a simple line // The default state is: // Line Width: 1 // color: 255,255,255,255 (white, non-transparent) // Anti-Aliased // glEnable(GL_LINE_SMOOTH); CCDrawingPrimitives.LineWidth = 1; CCDrawingPrimitives.DrawLine(visibleRect.LeftBottom(), visibleRect.RightTop()); // line: color, width, aliased CCDrawingPrimitives.LineWidth = 5; CCDrawingPrimitives.DrawColor = CCColor4B.Red; CCDrawingPrimitives.DrawLine(visibleRect.LeftTop(), visibleRect.RightBottom()); // TIP: // If you are going to use always thde same color or width, you don't // need to call it before every draw // // draw big point in the center CCDrawingPrimitives.PointSize = 64; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 0, 255, 128); CCDrawingPrimitives.DrawPoint(visibleRect.Center()); // draw 4 small points CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) }; CCDrawingPrimitives.PointSize = 8; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255); CCDrawingPrimitives.DrawPoints(points); // draw a green circle with 10 segments CCDrawingPrimitives.LineWidth = 16; CCDrawingPrimitives.DrawColor = CCColor4B.Green; CCDrawingPrimitives.DrawCircle(visibleRect.Center, 100, 0, 10, false); // draw a green circle with 50 segments with line to center CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255); CCDrawingPrimitives.DrawCircle(visibleRect.Center, 50, CCMacros.CCDegreesToRadians(45), 50, true); // draw a pink solid circle with 50 segments CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255); CCDrawingPrimitives.DrawSolidCircle(visibleRect.Center + new CCPoint(140, 0), 40, CCMacros.CCDegreesToRadians(90), 50); // draw an arc within rectangular region CCDrawingPrimitives.LineWidth = 5; CCDrawingPrimitives.DrawArc(new CCRect(200, 100, 100, 200), 0, 180, CCColor4B.AliceBlue); // draw an ellipse within rectangular region CCDrawingPrimitives.DrawEllipse(new CCRect(100, 100, 100, 200), CCColor4B.Red); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100, CCColor4B.AliceBlue); // draw an arc within rectangular region CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260, CCColor4B.Aquamarine); // open yellow poly CCPoint[] vertices = { new CCPoint(0, 0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100), new CCPoint(50, 100) }; CCDrawingPrimitives.LineWidth = 10; CCDrawingPrimitives.DrawColor = CCColor4B.Yellow; CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255)); // filled poly CCDrawingPrimitives.LineWidth = 1; CCPoint[] filledVertices = { new CCPoint(0, 120), new CCPoint(50, 120), new CCPoint(50, 170), new CCPoint(25, 200), new CCPoint(0, 170) }; CCDrawingPrimitives.DrawSolidPoly(filledVertices, new CCColor4F(0.5f, 0.5f, 1, 1)); // closed purple poly CCDrawingPrimitives.LineWidth = 2; CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255); CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) }; CCDrawingPrimitives.DrawPoly(vertices2, true); // draw quad bezier path CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, size.Height), visibleRect.Center, (CCPoint)visibleRect.Size, 50, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path CCDrawingPrimitives.DrawCubicBezier(visibleRect.Center, new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50), new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50), new CCPoint(size.Width, size.Height / 2), 100); //draw a solid polygon CCPoint[] vertices3 = { new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190), new CCPoint(90, 160) }; CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4F(1, 1, 0, 1)); CCDrawingPrimitives.End(); }
protected override void Draw() { defaultBlendState = PremultipliedAlpha ? BlendState.AlphaBlend : BlendState.NonPremultiplied; float[] vertices = this.vertices; List <Slot> drawOrder = Skeleton.DrawOrder; float x = Skeleton.X, y = Skeleton.Y; CCColor3B color3b = Color; float skeletonR = color3b.R / 255f; float skeletonG = color3b.G / 255f; float skeletonB = color3b.B / 255f; float skeletonA = Opacity / 255f; batcher.BlendState = defaultBlendState; batcher.Begin(); for (int i = 0, n = drawOrder.Count; i < n; i++) { Slot slot = drawOrder[i]; Attachment attachment = slot.Attachment; if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; BlendState blend = slot.Data.AdditiveBlending ? BlendState.Additive : defaultBlendState; //batcher.BlendState = blend; if (CCDrawManager.GraphicsDevice.BlendState != blend) { batcher.End(); batcher.BlendState = blend; batcher.Begin(); } MeshItem item = batcher.NextItem(4, 6); item.triangles = quadTriangles; VertexPositionColorTexture[] itemVertices = item.vertices; AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject; item.texture = (Texture2D)region.page.rendererObject; Color color; float a = skeletonA * slot.A * regionAttachment.A; if (PremultipliedAlpha) { color = new Color( skeletonR * slot.R * regionAttachment.R * a, skeletonG * slot.G * regionAttachment.G * a, skeletonB * slot.B * regionAttachment.B * a, a); } else { color = new Color( skeletonR * slot.R * regionAttachment.R, skeletonG * slot.G * regionAttachment.G, skeletonB * slot.B * regionAttachment.B, a); } itemVertices[TL].Color = color; itemVertices[BL].Color = color; itemVertices[BR].Color = color; itemVertices[TR].Color = color; regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices); itemVertices[TL].Position.X = vertices[RegionAttachment.X1]; itemVertices[TL].Position.Y = vertices[RegionAttachment.Y1]; itemVertices[TL].Position.Z = 0; itemVertices[BL].Position.X = vertices[RegionAttachment.X2]; itemVertices[BL].Position.Y = vertices[RegionAttachment.Y2]; itemVertices[BL].Position.Z = 0; itemVertices[BR].Position.X = vertices[RegionAttachment.X3]; itemVertices[BR].Position.Y = vertices[RegionAttachment.Y3]; itemVertices[BR].Position.Z = 0; itemVertices[TR].Position.X = vertices[RegionAttachment.X4]; itemVertices[TR].Position.Y = vertices[RegionAttachment.Y4]; itemVertices[TR].Position.Z = 0; float[] uvs = regionAttachment.UVs; itemVertices[TL].TextureCoordinate.X = uvs[RegionAttachment.X1]; itemVertices[TL].TextureCoordinate.Y = uvs[RegionAttachment.Y1]; itemVertices[BL].TextureCoordinate.X = uvs[RegionAttachment.X2]; itemVertices[BL].TextureCoordinate.Y = uvs[RegionAttachment.Y2]; itemVertices[BR].TextureCoordinate.X = uvs[RegionAttachment.X3]; itemVertices[BR].TextureCoordinate.Y = uvs[RegionAttachment.Y3]; itemVertices[TR].TextureCoordinate.X = uvs[RegionAttachment.X4]; itemVertices[TR].TextureCoordinate.Y = uvs[RegionAttachment.Y4]; } else if (attachment is MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; int vertexCount = mesh.Vertices.Length; if (vertices.Length < vertexCount) { vertices = new float[vertexCount]; } mesh.ComputeWorldVertices(x, y, slot, vertices); int[] triangles = mesh.Triangles; MeshItem item = batcher.NextItem(vertexCount, triangles.Length); item.triangles = triangles; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.texture = (Texture2D)region.page.rendererObject; Color color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new Color( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new Color( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; VertexPositionColorTexture[] itemVertices = item.vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Color = color; itemVertices[ii].Position.X = vertices[v]; itemVertices[ii].Position.Y = vertices[v + 1]; itemVertices[ii].Position.Z = 0; itemVertices[ii].TextureCoordinate.X = uvs[v]; itemVertices[ii].TextureCoordinate.Y = uvs[v + 1]; } } else if (attachment is SkinnedMeshAttachment) { SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment; int vertexCount = mesh.UVs.Length; if (vertices.Length < vertexCount) { vertices = new float[vertexCount]; } mesh.ComputeWorldVertices(x, y, slot, vertices); int[] triangles = mesh.Triangles; MeshItem item = batcher.NextItem(vertexCount, triangles.Length); item.triangles = triangles; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.texture = (Texture2D)region.page.rendererObject; Color color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new Color( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new Color( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; VertexPositionColorTexture[] itemVertices = item.vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Color = color; itemVertices[ii].Position.X = vertices[v]; itemVertices[ii].Position.Y = vertices[v + 1]; itemVertices[ii].Position.Z = 0; itemVertices[ii].TextureCoordinate.X = uvs[v]; itemVertices[ii].TextureCoordinate.Y = uvs[v + 1]; } } } batcher.End(); if (DebugBones || DebugSlots) { if (DebugSlots) { for (int i = 0; i < Skeleton.Slots.Count; ++i) { var slot = Skeleton.Slots[i]; if (slot.Attachment == null) { continue; } var verticesCount = 0; var worldVertices = new float[1000]; // Max number of vertices per mesh. if (slot.Attachment is RegionAttachment) { var attachment = (RegionAttachment)slot.Attachment; attachment.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot.bone, worldVertices); verticesCount = 8; } else if (slot.Attachment is MeshAttachment) { var mesh = (MeshAttachment)slot.Attachment; mesh.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot, worldVertices); verticesCount = mesh.Vertices.Length; } else if (slot.Attachment is SkinnedMeshAttachment) { var mesh = (SkinnedMeshAttachment)slot.Attachment; mesh.ComputeWorldVertices(Skeleton.X, Skeleton.Y, slot, worldVertices); verticesCount = mesh.UVs.Length; } else { continue; } CCPoint[] slotVertices = new CCPoint[verticesCount / 2]; for (int ii = 0, si = 0; ii < verticesCount; ii += 2, si++) { slotVertices[si].X = worldVertices[ii] * ScaleX; slotVertices[si].Y = worldVertices[ii + 1] * ScaleY; } CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoly(slotVertices, verticesCount / 2, true, DebugSlotColor); CCDrawingPrimitives.End(); } } if (DebugBones) { // Bone lengths. for (int i = 0; i < Skeleton.Bones.Count; i++) { Bone bone = Skeleton.Bones[i]; x = bone.Data.Length * bone.M00 + bone.WorldX; y = bone.Data.Length * bone.M10 + bone.WorldY; CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawLine(new CCPoint(bone.WorldX, bone.WorldY), new CCPoint(x, y), DebugJointColor); CCDrawingPrimitives.End(); } // Bone origins. for (int i = 0; i < Skeleton.Bones.Count; i++) { Bone bone = Skeleton.Bones[i]; CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoint(new CCPoint(bone.WorldX, bone.WorldY), 4, DebugBoneColor); CCDrawingPrimitives.End(); } } } }