protected override void AddedToScene() { base.AddedToScene(); var origin = Layer.VisibleBoundsWorldspace.Size; float delta = origin.Height / 4; label1.Position = origin.Center; label1.PositionY = delta * 2; label2.Position = label1.Position; // We use the ScaledContentSize here instead of ContentSize var labelSize = label1.ScaledContentSize; origin.Width = origin.Width / 2 - (labelSize.Width / 2); origin.Height = origin.Height / 2 - (labelSize.Height / 2); CCPoint[] vertices1 = { new CCPoint(origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, labelSize.Height + origin.Height), new CCPoint(origin.Width, labelSize.Height + origin.Height) }; drawNode.DrawPolygon(vertices1, 4, CCColor4B.Transparent, 1, CCColor4B.White); labelSize = label2.ScaledContentSize; origin = Layer.VisibleBoundsWorldspace.Size; origin.Width = origin.Width / 2 - (labelSize.Width / 2); origin.Height = origin.Height / 2 - (labelSize.Height / 2); CCPoint[] vertices2 = { new CCPoint(origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, labelSize.Height + origin.Height), new CCPoint(origin.Width, labelSize.Height + origin.Height) }; drawNode.DrawPolygon(vertices2, 4, CCColor4B.Transparent, 1, CCColor4B.Red); }
void MakeDownArrowGraphic(CCDrawNode drawNode) { var verts = new CCPoint[] { new CCPoint(0, 22), new CCPoint(20, 0), new CCPoint(40, 22) }; drawNode.DrawPolygon(verts, 3, CCColor4B.Gray, 1, CCColor4B.White); }
bool OnTouchBegan(CCTouch touch, CCEvent touchEvent) { var layer = tileMap.LayerNamed("grass"); var location = layer.WorldToParentspace(touch.Location); var tileCoordinates = layer.ClosestTileCoordAtNodePosition(location); var gid = layer.TileGIDAndFlags(tileCoordinates); if (gid.Gid != 1) // we only want the green grass { return(false); } // Convert the tile coordinates position to world coordinates for // our outline drawing var world = layer.TilePosition(tileCoordinates); // Calculate our width and height of the tile CCSize texToContentScaling = CCTileMapLayer.DefaultTexelToContentSizeRatios; float width = layer.TileTexelSize.Width * texToContentScaling.Width; float height = layer.TileTexelSize.Height * texToContentScaling.Height; var rect = new CCRect(world.X, world.Y, width, height); drawNode.Clear(); drawNode.Color = CCColor3B.Magenta; drawNode.Opacity = 255; var center = rect.Center; var right = center; right.X += width / 2; var top = center; top.Y += height / 2; var left = right; left.X -= width; var bottom = center; bottom.Y -= height / 2; // Hightlight our iso tile drawNode.DrawPolygon(new CCPoint[] { right, top, left, bottom }, 4, CCColor4B.Transparent, 1, new CCColor4F(CCColor4B.Magenta)); return(true); }
protected virtual CCDrawNode Shape() { var shape = new CCDrawNode(); var triangle = new CCPoint[3]; triangle[0] = new CCPoint(-100, -100); triangle[1] = new CCPoint(100, -100); triangle[2] = new CCPoint(0, 100); shape.DrawPolygon(triangle, 3, new CCColor4F(0, 1, 0, 1), 0, new CCColor4F(0, 1, 0, 1)); return(shape); }
public void MakePlayGraphic(CCDrawNode drawNode) { drawNode.Clear(); const float playButtonHeight = 40; var verts = new CCPoint[] { new CCPoint(0, 0), new CCPoint(0, playButtonHeight), new CCPoint(22, playButtonHeight / 2.0f) }; drawNode.DrawPolygon(verts, 3, CCColor4B.Green, 1, CCColor4B.White); }
public GameScene(CCGameView gameView, float x, float y) : base(gameView) { var layer = new CCLayer(); this.AddLayer(layer); _context = new DatabaseContext(); var rooms = _context.Rooms.ToList(); //System.Diagnostics.Debug.WriteLine("******************************count " + rooms.Count); foreach (var r in rooms) { float ldx = r.LavaXhodnota * 10; float ldy = r.LavaYhodnota * 10; float rhx = r.PravaXhodnota * 10; float rhy = r.PravaYhodnota * 10; square = new CCDrawNode(); layer.AddChild(square); CCPoint[] verts = new CCPoint[] { new CCPoint(ldx, ldy), new CCPoint(rhx, ldy), new CCPoint(rhx, rhy), new CCPoint(ldx, rhy) }; square.DrawPolygon(verts, count: verts.Length, fillColor: CCColor4B.White, borderWidth: 1, borderColor: CCColor4B.Red, closePolygon: true); /*square.PositionX = ldx; * square.PositionY = ldy;*/ } circle = new CCDrawNode(); layer.AddChild(circle); circle.DrawSolidCircle( pos: new CCPoint(0, 0), radius: 4, color: CCColor4B.Blue); circle.PositionX = x; circle.PositionY = y; }
void Polygon() { CCPoint[] verts = new CCPoint[] { new CCPoint(0, 0), new CCPoint(0, 100), new CCPoint(50, 150), new CCPoint(100, 100), new CCPoint(100, 0) }; drawNode.DrawPolygon(verts, count: verts.Length, fillColor: CCColor4B.White, borderWidth: 5, borderColor: CCColor4B.Red, closePolygon: true); }
public override void Setup() { CCClippingNode clipper = new CCClippingNode() { Tag = kTagClipperNode }; clipper.ContentSize = new CCSize(200, 200); clipper.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(clipper); CCDrawNode stencil = new CCDrawNode(); CCPoint[] rectangle = { new CCPoint(0, 0), new CCPoint(clipper.ContentSize.Width, 0), new CCPoint(clipper.ContentSize.Width, clipper.ContentSize.Height), new CCPoint(0, clipper.ContentSize.Height), }; CCColor4F white = new CCColor4F(0, 0, 0, 1); stencil.DrawPolygon(rectangle, 4, white, 0, white); clipper.Stencil = stencil; CCSprite content = new CCSprite(TestResource.s_back2); content.Tag = kTagContentNode; content.AnchorPoint = new CCPoint(0.5f, 0.5f); clipper.AddChild(content); content.RunAction(new CCRepeatForever(new CCRotateBy(1, 45))); m_bScrolling = false; // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesBegan = onTouchesBegan; touchListener.OnTouchesMoved = onTouchesMoved; touchListener.OnTouchesEnded = onTouchesEnded; AddEventListener(touchListener); }
public DrawPrimitivesWithRenderTextureTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCRenderTexture text = new CCRenderTexture((int)s.Width, (int)s.Height); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(s.Height / 4, 0), new CCPoint(s.Width, s.Height / 5), new CCPoint(s.Width / 3 * 2, s.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); text.End(); AddChild(text, 24); }
void AddShip(CCRect bounds) { ship = new CCDrawNode(); CCPoint[] points = { new CCPoint(0, 25), new CCPoint(50, 0), new CCPoint(0, -25) }; ship.DrawPolygon(points, points.Length, CCColor4B.White, 1.0f, CCColor4B.Orange); ship.Position = new CCPoint(bounds.MinX + 100.0f, bounds.MidY); AddChild(ship); var fire = new CCParticleFire(new CCPoint(-10.0f, 0.0f)); fire.Rotation = -90.0f; fire.Scale = 0.5f; ship.AddChild(fire); }
public override void Setup() { var s = CCDirector.SharedDirector.WinSize; CCClippingNode clipper = new CCClippingNode(); clipper.Tag = kTagClipperNode; clipper.ContentSize = new CCSize(200, 200); clipper.AnchorPoint = new CCPoint(0.5f, 0.5f); clipper.Position = ContentSize.Center; clipper.RunAction(new CCRepeatForever(new CCRotateBy(1, 45))); AddChild(clipper); CCDrawNode stencil = new CCDrawNode(); CCPoint[] rectangle = { new CCPoint(0, 0), new CCPoint(clipper.ContentSize.Width, 0), new CCPoint(clipper.ContentSize.Width, clipper.ContentSize.Height), new CCPoint(0, clipper.ContentSize.Height), }; CCColor4F white = new CCColor4F(1, 1, 1, 1); stencil.DrawPolygon(rectangle, 4, white, 0, white); clipper.Stencil = stencil; CCSprite content = new CCSprite(TestResource.s_back2); content.Tag = kTagContentNode; content.AnchorPoint = new CCPoint(0.5f, 0.5f); content.Position = clipper.ContentSize.Center; clipper.AddChild(content); m_bScrolling = false; TouchEnabled = true; }
protected override void AddedToScene() { base.AddedToScene(); var origin = Layer.VisibleBoundsWorldspace.Size; label.Position = origin.Center; label.Dimensions = new CCSize(origin.Width, 0); var labelSize = label.ContentSize; origin.Width = origin.Width / 2 - (labelSize.Width / 2); origin.Height = origin.Height / 2 - (labelSize.Height / 2); CCPoint[] vertices = { new CCPoint(origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, origin.Height), new CCPoint(labelSize.Width + origin.Width, labelSize.Height + origin.Height), new CCPoint(origin.Width, labelSize.Height + origin.Height) }; drawNode.DrawPolygon(vertices, 4, CCColor4B.Transparent, 1, CCColor4B.White); }
public override void OnEnter() { base.OnEnter(); var windowSize = Layer.VisibleBoundsWorldspace.Size; CCRenderTexture text = new CCRenderTexture(windowSize, windowSize); AddChild(text, 24); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // 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)); text.End(); }
public override bool Init() { base.Init(); CCSize s = CCDirector.SharedDirector.WinSize; CCDrawNode draw = new CCDrawNode(); AddChild(draw, 10); // Draw 10 circles for (int i = 0; i < 10; i++) { draw.DrawDot(new CCPoint(s.Width / 2, s.Height / 2), 10 * (10 - i), new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1)); } // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(s.Height / 4, 0), new CCPoint(s.Width, s.Height / 5), new CCPoint(s.Width / 3 * 2, s.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); // star poly (triggers buggs) { const float o = 80; const float w = 20; const float h = 50; CCPoint[] star = new CCPoint[] { new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike // {o +w, o+w*2+h}, {o,o+w*2}, // top spike // {o -h, o+w}, {o,o}, // left spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // star poly (doesn't trigger bug... order is important un tesselation is supported. { const float o = 180; const float w = 20; const float h = 50; var star = new CCPoint[] { new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2), // top spike new CCPoint(o - h, o + w), // left spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // Draw segment draw.DrawSegment(new CCPoint(20, s.Height), new CCPoint(20, s.Height / 2), 10, new CCColor4F(0, 1, 0, 1)); draw.DrawSegment(new CCPoint(10, s.Height / 2), new CCPoint(s.Width / 2, s.Height / 2), 40, new CCColor4F(1, 0, 1, 0.5f)); return(true); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCDrawNode draw = new CCDrawNode(); AddChild(draw, 10); var s = windowSize; // Draw 10 circles for (int i = 0; i < 10; i++) { draw.DrawDot(s.Center, 10 * (10 - i), new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1)); } // Draw polygons CCV3F_C4B[] points = new CCV3F_C4B[3]; points[0].Colors = CCColor4B.Red; points[0].Colors.A = 127; points[1].Colors = CCColor4B.Green; points[1].Colors.A = 127; points[2].Colors = CCColor4B.Blue; points[2].Colors.A = 127; points[0].Vertices.X = windowSize.Height / 4; points[0].Vertices.Y = 0; points[1].Vertices.X = windowSize.Width; points[1].Vertices.Y = windowSize.Height / 5; points[2].Vertices.X = windowSize.Width / 3 * 2; points[2].Vertices.Y = windowSize.Height; draw.DrawTriangleList(points); // star poly (triggers buggs) { const float o = 80; const float w = 20; const float h = 50; CCPoint[] star = new CCPoint[] { new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // star poly (doesn't trigger bug... order is important un tesselation is supported. { const float o = 180; const float w = 20; const float h = 50; var star = new CCPoint[] { new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2), // top spike new CCPoint(o - h, o + w), // left spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // Draw segment draw.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1)); draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40, new CCColor4F(1, 0, 1, 0.5f)); }
protected void UpdateSkeletonGeometry() { skeletonGeometry.ClearInstances(); //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; 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; var item = skeletonGeometry.CreateGeometryInstance(4, 6); //item.InstanceAttributes.BlendState = blend; //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; item.GeometryPacket.Indicies = quadTriangles; var itemVertices = item.GeometryPacket.Vertices; AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * regionAttachment.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * regionAttachment.R * a, skeletonG * slot.G * regionAttachment.G * a, skeletonB * slot.B * regionAttachment.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * regionAttachment.R, skeletonG * slot.G * regionAttachment.G, skeletonB * slot.B * regionAttachment.B, a); } itemVertices[TL].Colors = color; itemVertices[BL].Colors = color; itemVertices[BR].Colors = color; itemVertices[TR].Colors = color; regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices); itemVertices[TL].Vertices.X = vertices[RegionAttachment.X1]; itemVertices[TL].Vertices.Y = vertices[RegionAttachment.Y1]; itemVertices[TL].Vertices.Z = 0; itemVertices[BL].Vertices.X = vertices[RegionAttachment.X2]; itemVertices[BL].Vertices.Y = vertices[RegionAttachment.Y2]; itemVertices[BL].Vertices.Z = 0; itemVertices[BR].Vertices.X = vertices[RegionAttachment.X3]; itemVertices[BR].Vertices.Y = vertices[RegionAttachment.Y3]; itemVertices[BR].Vertices.Z = 0; itemVertices[TR].Vertices.X = vertices[RegionAttachment.X4]; itemVertices[TR].Vertices.Y = vertices[RegionAttachment.Y4]; itemVertices[TR].Vertices.Z = 0; float[] uvs = regionAttachment.UVs; itemVertices[TL].TexCoords.U = uvs[RegionAttachment.X1]; itemVertices[TL].TexCoords.V = uvs[RegionAttachment.Y1]; itemVertices[BL].TexCoords.U = uvs[RegionAttachment.X2]; itemVertices[BL].TexCoords.V = uvs[RegionAttachment.Y2]; itemVertices[BR].TexCoords.U = uvs[RegionAttachment.X3]; itemVertices[BR].TexCoords.V = uvs[RegionAttachment.Y3]; itemVertices[TR].TexCoords.U = uvs[RegionAttachment.X4]; itemVertices[TR].TexCoords.V = 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; var item = skeletonGeometry.CreateGeometryInstance(vertexCount, triangles.Length); //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; item.GeometryPacket.Indicies = triangles; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; var itemVertices = item.GeometryPacket.Vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Colors = color; itemVertices[ii].Vertices.X = vertices[v]; itemVertices[ii].Vertices.Y = vertices[v + 1]; itemVertices[ii].Vertices.Z = 0; itemVertices[ii].TexCoords.U = uvs[v]; itemVertices[ii].TexCoords.V = 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; var item = skeletonGeometry.CreateGeometryInstance(vertexCount, triangles.Length); item.GeometryPacket.Indicies = triangles; //item.InstanceAttributes.AdditionalTransform = AffineWorldTransform; AtlasRegion region = (AtlasRegion)mesh.RendererObject; item.GeometryPacket.Texture = (CCTexture2D)region.page.rendererObject; CCColor4B color; float a = skeletonA * slot.A * mesh.A; if (PremultipliedAlpha) { color = new CCColor4B( skeletonR * slot.R * mesh.R * a, skeletonG * slot.G * mesh.G * a, skeletonB * slot.B * mesh.B * a, a); } else { color = new CCColor4B( skeletonR * slot.R * mesh.R, skeletonG * slot.G * mesh.G, skeletonB * slot.B * mesh.B, a); } float[] uvs = mesh.UVs; var itemVertices = item.GeometryPacket.Vertices; for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2) { itemVertices[ii].Colors = color; itemVertices[ii].Vertices.X = vertices[v]; itemVertices[ii].Vertices.Y = vertices[v + 1]; itemVertices[ii].Vertices.Z = 0; itemVertices[ii].TexCoords.U = uvs[v]; itemVertices[ii].TexCoords.V = uvs[v + 1]; } } } debugger.Clear(); 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; } debugger.DrawPolygon(slotVertices, verticesCount / 2, CCColor4B.Transparent, 1, DebugSlotColor); } } 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; debugger.DrawLine(new CCPoint(bone.WorldX, bone.WorldY), new CCPoint(x, y), 1, DebugJointColor); } // Bone origins. for (int i = 0; i < Skeleton.Bones.Count; i++) { Bone bone = Skeleton.Bones[i]; debugger.DrawDot(new CCPoint(bone.WorldX, bone.WorldY), 3, DebugBoneColor); } } } }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCDrawNode draw = new CCDrawNode(); AddChild(draw, 10); var s = windowSize; // Draw 10 circles for (int i = 0; i < 10; i++) { draw.DrawSolidCircle(s.Center, 10 * (10 - i), new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1)); } // 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.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); // star poly (triggers buggs) { const float o = 80; const float w = 20; const float h = 50; CCPoint[] star = new CCPoint[] { new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // star poly (doesn't trigger bug... order is important un tesselation is supported. { const float o = 180; const float w = 20; const float h = 50; var star = new CCPoint[] { new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2), // top spike new CCPoint(o - h, o + w), // left spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // Draw segment draw.DrawLine(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1), CCLineCap.Round); draw.DrawLine(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40, new CCColor4F(1, 0, 1, 0.5f), CCLineCap.Round); CCSize size = Layer.VisibleBoundsWorldspace.Size; var visibleRect = VisibleBoundsWorldspace; // draw quad bezier path draw.DrawQuadBezier(new CCPoint(0, size.Height), visibleRect.Center, (CCPoint)visibleRect.Size, 50, 3, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path draw.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, 2, CCColor4B.Green); // draw an ellipse within rectangular region draw.DrawEllipse(new CCRect(100, 300, 100, 200), 8, CCColor4B.AliceBlue); var splinePoints = new List <CCPoint>(); splinePoints.Add(new CCPoint(0, 0)); splinePoints.Add(new CCPoint(50, 70)); splinePoints.Add(new CCPoint(0, 140)); splinePoints.Add(new CCPoint(100, 210)); splinePoints.Add(new CCPoint(0, 280)); splinePoints.Add(new CCPoint(150, 350)); int numberOfSegments = 64; float tension = .05f; draw.DrawCardinalSpline(splinePoints, tension, numberOfSegments); draw.DrawSolidArc( pos: new CCPoint(350, windowSize.Height * 0.75f), radius: 100, startAngle: CCMathHelper.ToRadians(45), sweepAngle: CCMathHelper.Pi / 2, // this is in radians, clockwise color: CCColor4B.Aquamarine); }
void RenderDrawPrimTest() { CCSize size = Layer.VisibleBoundsWorldspace.Size; var visibleRect = VisibleBoundsWorldspace; CCDrawNode drawNode = new CCDrawNode(); // *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); float lineWidth = 1.0f; CCColor4B lineColor = CCColor4B.White; drawNode.DrawLine(visibleRect.LeftBottom(), visibleRect.RightTop(), lineWidth); // line: color, width, aliased lineWidth = 5.0f; lineColor = CCColor4B.Red; drawNode.DrawLine(visibleRect.LeftTop(), visibleRect.RightBottom(), lineWidth, lineColor); // 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 drawNode.DrawSolidCircle(visibleRect.Center(), 64.0f, 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) }; foreach (CCPoint point in points) { drawNode.DrawSolidCircle(point, 8.0f, new CCColor4B(0, 255, 255, 255)); } // draw a green circle with 10 segments drawNode.DrawCircle(visibleRect.Center, 100.0f, 10, CCColor4B.Green); // draw an arc drawNode.DrawSolidArc(visibleRect.Center, 10.0f, 0, 180, CCColor4B.AliceBlue); // draw an ellipse within rectangular region drawNode.DrawEllipse(new CCRect(100, 100, 100, 200), 10.0f, CCColor4B.Red); // 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) }; // draw quad bezier path drawNode.DrawQuadBezier( new CCPoint(0, size.Height), visibleRect.Center, (CCPoint)visibleRect.Size, 50, 10.0f, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path drawNode.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, 10.0f, 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) }; drawNode.DrawPolygon(vertices3, 4, new CCColor4F(1, 1, 0, 1), 1.0f, new CCColor4F(1, 1, 0, 1)); AddChild(drawNode); }
void DrawSolidPolygon(CCPoint[] points, CCColor4B color) { drawTriangles.DrawPolygon(points, points.Length, color, 0, CCColor4B.Transparent); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCDrawNode draw = new CCDrawNode(); AddChild(draw, 10); var s = windowSize; // Draw 10 circles for (int i = 0; i < 10; i++) { draw.DrawDot(s.Center, 10 * (10 - i), new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1)); } // 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.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); // star poly (triggers buggs) { const float o = 80; const float w = 20; const float h = 50; CCPoint[] star = new CCPoint[] { new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // star poly (doesn't trigger bug... order is important un tesselation is supported. { const float o = 180; const float w = 20; const float h = 50; var star = new CCPoint[] { new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2), // right spike new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2), // top spike new CCPoint(o - h, o + w), // left spike }; draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1)); } // Draw segment draw.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1)); draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40, new CCColor4F(1, 0, 1, 0.5f)); CCSize size = Layer.VisibleBoundsWorldspace.Size; var visibleRect = VisibleBoundsWorldspace; // draw quad bezier path draw.DrawQuadBezier(new CCPoint(0, size.Height), visibleRect.Center, (CCPoint)visibleRect.Size, 50, 3, new CCColor4B(255, 0, 255, 255)); // draw cubic bezier path draw.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, 2, CCColor4B.Green); // draw an ellipse within rectangular region draw.DrawEllipse(new CCRect(100, 300, 100, 200), 2, CCColor4B.AliceBlue); }
internal void UpdateDrawNode(bool useMultiplGoal = false) { if (MyDrawNode == null) { return; } MyDrawNode.Clear(); if (LootboxCount != 0) { // visualize lootbar-progress const float GROWTH_FACTOR = 1.3f; const float BORDER_WIDTH = 4f; CCColor4B white = new CCColor4B(1f, 1f, 1f, DrawNodeAlpha); CCColor4B bright = new CCColor4B(1f, 1f, 1f, DrawNodeAlpha); CCRect progressRect = new CCRect(-(ContentSize.Width * GROWTH_FACTOR) / 2, -(ContentSize.Height * GROWTH_FACTOR) / 2, ContentSize.Width * GROWTH_FACTOR, ContentSize.Height * GROWTH_FACTOR); // draw the progress bar var progressPoly = new List <CCPoint> { CCPoint.Zero, new CCPoint(0, (ContentSize.Height * GROWTH_FACTOR) / 2) }; if (LootboxProgress >= 0.125f) { progressPoly.Add(progressRect.UpperRight); } else { progressPoly.Add(new CCPoint(LootboxProgress / 0.125f * progressRect.MaxX, progressRect.MaxY)); goto done; } if (LootboxProgress >= 0.375f) { progressPoly.Add(new CCPoint(progressRect.MaxX, progressRect.MinY)); } else { progressPoly.Add(new CCPoint(progressRect.MaxX, progressRect.MaxY - progressRect.Size.Height * ((LootboxProgress - 0.125f) * 4))); goto done; } if (LootboxProgress >= 0.625f) { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MinY)); } else { progressPoly.Add(new CCPoint(progressRect.MaxX - progressRect.Size.Width * ((LootboxProgress - 0.375f) * 4), progressRect.MinY)); goto done; } if (LootboxProgress >= 0.875f) { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MaxY)); } else { progressPoly.Add(new CCPoint(progressRect.MinX, progressRect.MinY + progressRect.Size.Height * ((LootboxProgress - 0.625f) * 4))); goto done; } if (LootboxProgress > 0.875f) { progressPoly.Add(new CCPoint(progressRect.MinX + progressRect.Size.Width * (LootboxProgress - 0.875f) * 2, progressRect.MaxY)); } done: var progressPolyPoints = progressPoly.ToArray(); MyDrawNode.DrawPolygon(progressPolyPoints, progressPolyPoints.Length, bright, 0f, CCColor4B.Transparent); // draw the progress bar border MyDrawNode.DrawRect(progressRect, CCColor4B.Transparent, BORDER_WIDTH, white); } // additionally color the button depending on the multiplier progress int multiplier = 1; float progress = 0; if (useMultiplGoal) { multiplier = (int)CurrentMathChallengeNode.MultiplGoal; progress = CurrentMathChallengeNode.MathChallenge.MultiplProgress; } else { multiplier = CurrentMathChallengeNode.Multiplier; progress = CurrentMathChallengeNode.MultiplProgressVisible; } var lastColor = MathChallengeNode.MultiplierBarColor(multiplier - 1); var nextColor = MathChallengeNode.MultiplierBarColor(multiplier); var currentColor = multiplier <= 5 ? CCColor4B.Lerp(lastColor, nextColor, progress) : lastColor; var darkenedColor = CCColor4B.Lerp(currentColor, CCColor4B.Black, 0.25f); darkenedColor.A = (byte)(DrawNodeAlpha * byte.MaxValue); MyDrawNode.DrawRect(new CCRect(-(ContentSize.Width) / 2, -(ContentSize.Height) / 2, ContentSize.Width, ContentSize.Height), darkenedColor); }
protected void DrawPolygon(Dictionary <string, string> dict, CCDrawNode draw) { List <CCPoint> points = ParsePoints(dict["points"]); draw.DrawPolygon(points.ToArray(), points.Count, new CCColor4B(0, 0, 0, 0), 1.0f, new CCColor4B(255, 255, 0)); }
public HeatMapScene(CCGameView gameView, float index, int max) : base(gameView) { var layer = new CCLayer(); this.AddLayer(layer); _context = new DatabaseContext(); var rooms = _context.Rooms.ToList(); //System.Diagnostics.Debug.WriteLine("******************************count " + rooms.Count); foreach (var r in rooms) { float ldx = r.LavaXhodnota * 10; float ldy = r.LavaYhodnota * 10; float rhx = r.PravaXhodnota * 10; float rhy = r.PravaYhodnota * 10; square = new CCDrawNode(); layer.AddChild(square); CCPoint[] verts = new CCPoint[] { new CCPoint(ldx, ldy), new CCPoint(rhx, ldy), new CCPoint(rhx, rhy), new CCPoint(ldx, rhy) }; square.DrawPolygon(verts, count: verts.Length, fillColor: CCColor4B.White, borderWidth: 1, borderColor: CCColor4B.Red, closePolygon: true); /*square.PositionX = ldx; * square.PositionY = ldy;*/ } if (index > max - 10) { index = max - 10; } var sekv = _context.MovementSekv.Where(t => t.PohSekvId >= index).ToList(); int poc = 1; List <int> vyskyt = new List <int>(); foreach (var s in sekv) { if (poc > 10) { break; } //System.Diagnostics.Debug.WriteLine("POCET +++++ " + s.Cas_Zotrvania); int n = 0; Int32.TryParse(s.Cas_Zotrvania, out n); vyskyt.Add(n); poc++; } int maxVal = vyskyt.Max(); int divide = maxVal / 4; poc = 1; foreach (var s in sekv) { if (poc > 10) { break; } circle = new CCDrawNode(); layer.AddChild(circle); /*circle.DrawCircle( * new CCPoint(0, 0), * radius: 2, * color: CCColor4B.Blue); * circle.PositionX = s.Xhodnota; * circle.PositionY = s.Yhodnota;*/ int n = 0; Int32.TryParse(s.Cas_Zotrvania, out n); if (n >= 0 && n <= divide) { circle.DrawSolidCircle( pos: new CCPoint(s.Xhodnota, s.Yhodnota), radius: 2, color: CCColor4B.Green); } else if (n > divide && n <= divide * 2) { circle.DrawSolidCircle( pos: new CCPoint(s.Xhodnota, s.Yhodnota), radius: 4, color: CCColor4B.Yellow); } else if (n > divide * 2 && n <= divide * 3) { circle.DrawSolidCircle( pos: new CCPoint(s.Xhodnota, s.Yhodnota), radius: 6, color: CCColor4B.Orange); } else { circle.DrawSolidCircle( pos: new CCPoint(s.Xhodnota, s.Yhodnota), radius: 8, color: CCColor4B.Red); } var text = new CCLabel(s.Cas_Zotrvania, "Arial", 10) { Position = new CCPoint(s.Xhodnota, s.Yhodnota), Color = CCColor3B.Black, IsAntialiased = true }; layer.AddChild(text); poc++; } }