internal override void UpdateCamera() { base.UpdateCamera(); // additionally color the background and the planes according to the position of the center of the camera relative to the zones CCPoint camMid = CameraPosition + (CCPoint)CameraSize / 2; float radius = camMid.Length; var bgColor = RadiusToColor(radius, groundNotAir: true); var planeColor = RadiusToColor(radius, groundNotAir: false); // draw the bg lines DrawNode.Clear(); const float bgsize = 600000f; const int lineCount = 200; var bgLineColor = CCColor4B.Lerp(planeColor, CCColor4B.Black, 0.75f); for (int i = -lineCount; i < lineCount; i++) { DrawNode.DrawLine(new CCPoint(i * bgsize / lineCount, -bgsize), new CCPoint(i * bgsize / lineCount, bgsize), 20f, bgLineColor); DrawNode.DrawLine(new CCPoint(-bgsize, i * bgsize / lineCount), new CCPoint(bgsize, i * bgsize / lineCount), 20f, bgLineColor); } // draw the bg color DrawNodeBG.Clear(); DrawNodeBG.DrawRect(new CCRect(-999999999f, -999999999f, 999999999f * 2, 999999999f * 2), bgColor); // now the planes // only color the enemies foreach (var aircraft in ActiveAircrafts) { aircraft.ColorByPlayLayer(planeColor); } }
protected void RenderTouchPoint() { touchPoint.Clear(); touchPoint.Color = new CCColor3B(_touchColor.R, _touchColor.G, _touchColor.B); touchPoint.Opacity = 255; touchPoint.DrawLine(new CCPoint(0, _touchPoint.Y), new CCPoint(ContentSize.Width, _touchPoint.Y), 5); touchPoint.DrawLine(new CCPoint(_touchPoint.X, 0), new CCPoint(_touchPoint.X, ContentSize.Height), 5); touchPoint.DrawRect(_touchPoint, 30); }
void OnTouchesBegan(List <CCTouch> touches, CCEvent touchEvent) { if (touches.Count > 0) { _line.DrawLine(touches[0].StartLocation, touches[0].Location, LINE_WIDTH, CCColor4B.Yellow, CCLineCap.Round); _lastLineStartPoint = new CCPoint(touches[0].Location); _ball.AddChild(_glow); _ball.ReorderChild(_glow, 1); } }
public override void OnEnter() { base.OnEnter(); var s = Layer.VisibleBoundsWorldspace.Size; var drawNode = new CCDrawNode(); drawNode.DrawLine(new CCPoint(0, s.Height / 2), new CCPoint(s.Width, s.Height / 2), new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f)); drawNode.DrawLine(new CCPoint(s.Width / 2, 0), new CCPoint(s.Width / 2, s.Height), new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f)); AddChild(drawNode, -1); }
public MainLayer() : base(CCColor4B.AliceBlue) { _canvasNode = new CCDrawNode(); _recognizerCanvasNode = new CCDrawNode(); _lineRecognizer = new LineRecognizer(); _shapeNode = new CCDrawNode(); AddChild(_shapeNode); AddChild(_canvasNode); AddChild(_recognizerCanvasNode); if (_drawDebug) { _lineRecognizer.LineFound = (line) => _recognizerCanvasNode.DrawLine(line.P1.ToCCPoint(), line.P2.ToCCPoint(), 5, CCColor4B.Blue); } // Register patterns (concept) _patternEvaluator = new PatternEvaluator(); _patternEvaluator.Add("button").When(Pattern.WideRectangle); _patternEvaluator.Add("image").When(Pattern.Cross); _patternEvaluator.Add("text").When(p => p.Repetitive(ip => ip.MovesRight().MovesLeftAndDown()).MovesRight()); _patternEvaluator.Add("entry").When(p => p.MovesDown().MovesRight().MovesUp().Bounds(BoundsDescriptor.IsWide)); _patternEvaluator.Add("lineoftext").When(p => p.MovesRight()); _patternEvaluator.Add("delete").When(p => p.MovesRightAndUp()); }
void Line() { drawNode.DrawLine( from: new CCPoint(0, 0), to: new CCPoint(150, 30), lineWidth: 5, color: CCColor4B.Orange); }
void UpdateLine() { line.Clear(); var effectiveWidth = Math.Max(0, width); line.DrawLine(CCPoint.Zero, new CCPoint(40, 0), effectiveWidth / 2, new CCColor4F(1, 1, 0, 1)); }
protected void Draw() { CCColor4B color = new CCColor4B(1.0f, 1.0f, 1.0f, 1.0f); switch (_lineType) { case lineTypes.LINE_NONE: break; case lineTypes.LINE_TEMP: drawNode.DrawLine(_tip, _pivot, color); drawNode.DrawCircle(_pivot, 10, 10, color); break; case lineTypes.LINE_DASHED: drawNode.DrawCircle(_pivot, 10, 10, color); int segments = (int)(_lineLength / (_dash + _dashSpace)); float t = 0.0f; float x_; float y_; for (int i = 0; i < segments + 1; i++) { x_ = _pivot.X + t * (_tip.X - _pivot.X); y_ = _pivot.Y + t * (_tip.Y - _pivot.Y); drawNode.DrawCircle(new CCPoint(x_, y_), 4, 6, color); t += (float)1 / segments; } break; } //draw energy bar color = new CCColor4B(0.0f, 0.0f, 0.0f, 1.0f); drawNode.DrawLine( new CCPoint(_energyLineX, _screenSize.Height * 0.1f), new CCPoint(_energyLineX, _screenSize.Height * 0.9f), color); color = new CCColor4B(1.0f, 0.5f, 0.0f, 1.0f); drawNode.DrawLine( new CCPoint(_energyLineX, _screenSize.Height * 0.1f), new CCPoint(_energyLineX, _screenSize.Height * 0.1f + _energy * _energyHeight), color); }
private void RedrawGameScene() { _wheel.Clear(); _layer.Children?.Clear(); _layer.AddChild(_wheel); float lineWidth = (float)_centre.Mass / 10; if (lineWidth < 1f) { lineWidth = 1f; } _wheel.DrawLine(new CCPoint(-20, -20), new CCPoint(20, 20), lineWidth: lineWidth, CCColor4B.White); _wheel.DrawLine(new CCPoint(-20, 20), new CCPoint(20, -20), lineWidth: lineWidth, CCColor4B.White); _wheel.PositionX = (float)_viewResolution.Width / 2; _wheel.PositionY = (float)_viewResolution.Height / 2; }
protected override void PlayAttackAnimation() { float x = this.PositionWorldspace.X - this.attackTarget.PositionWorldspace.X; float y = this.PositionWorldspace.Y - this.attackTarget.PositionWorldspace.Y; attackDrawNode = new CCDrawNode(); attackDrawNode.DrawLine(CCPoint.Zero, new CCPoint(x * -1, y * -1), CCColor4B.Red, CCLineCap.Butt); this.AddChild(attackDrawNode); attackDrawNode.RunActions(new CCFadeOut(0.5f), new CCRemoveSelf(true)); }
public void UseDrawNodes(CCDrawNode highNode, CCDrawNode lowNode) { // calculate how far back the tail needs to go float tMidTail = TailLifeTime / 2; float tEndTail = TailLifeTime; if (TimeAlive - tMidTail < 0) { tMidTail = TimeAlive; tEndTail = TimeAlive; } else if (TimeAlive - tEndTail < 0) { tEndTail = TimeAlive; } if (!IsAlive()) { float diff = TimeAlive - LifeTime; tMidTail -= diff; tEndTail -= diff; if (tMidTail < 0) { tMidTail = 0; } if (tEndTail < 0) { tEndTail = 0; } } CCPoint midPoint = new CCPoint(PositionX - Dx * tMidTail, PositionY - Dy * tMidTail); CCPoint endPoint = new CCPoint(PositionX - Dx * tEndTail, PositionY - Dy * tEndTail); if (tMidTail != 0) { lowNode.DrawLine(Position, midPoint, TailWidth, TailColor); } if (tEndTail != 0) { lowNode.DrawLine(midPoint, endPoint, TailWidth, TailEndColor); } //TailNode.DrawSolidCircle(Position, 10f, CCColor4B.Yellow); }
void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { var touch = touches[0]; // Let's make sure that the two line points are not the same or we will have errors later on // with NaN on some platforms when calculating DrawNode's BoundingRect. if (lastPoint != touch.Location) { canvasNode.DrawLine(lastPoint, touch.Location, 1, new CCColor4F(CCColor4B.White), CCLineCap.Round); } lastPoint = touch.Location; }
/********************************************************************** *********************************************************************/ public static void DrawGrayArrow() { //gray arrow float c = 0; for (int i = 0; i <= besPos; i++) { if (i == besPos) { c += memoryBlocks[i, 1] * relativeFragmentSize + (memoryBlocks[i, 0] * relativeFragmentSize) / 2; } else { c += memoryBlocks[i, 1] * relativeFragmentSize + memoryBlocks[i, 0] * relativeFragmentSize; } if (i > 0) { c += relativeFragmentSize; } //don't forget the parting lines with width 1 } //Memory Box starts at 15 +1 linewidth ->15.5 posArrow2 = 15.5f + c; cc_arrow2 = new CCDrawNode(); cc_arrow2a = new CCDrawNode(); cc_arrow2b = new CCDrawNode(); cc_arrow2.DrawLine( from: new CCPoint(posArrow2, 16), to: new CCPoint(posArrow2, 0), lineWidth: 1, color: CCColor4B.Gray); cc_arrow2a.DrawLine( from: new CCPoint(posArrow2 + 0.5f, 16), to: new CCPoint(posArrow2 - 5, 12), lineWidth: 1, color: CCColor4B.Gray); cc_arrow2b.DrawLine( from: new CCPoint(posArrow2 - 0.5f, 16), to: new CCPoint(posArrow2 + 5, 12), lineWidth: 1, color: CCColor4B.Gray); layer.AddChild(cc_arrow2); layer.AddChild(cc_arrow2a); layer.AddChild(cc_arrow2b); }
/********************************************************************** *********************************************************************/ public static void DrawRedArrow() { //red arrow float c = 0; for (int i = 0; i <= pos; i++) { if (i == pos) { c += memoryBlocks[i, 1] * relativeFragmentSize + (memoryBlocks[i, 0] * relativeFragmentSize) / 2; } else { c += memoryBlocks[i, 1] * relativeFragmentSize + memoryBlocks[i, 0] * relativeFragmentSize; } if (i > 0) { c += relativeFragmentSize; } //don't forget the parting lines with width 1 } //Memory Box starts at 15 +1 linewidth ->15.5 posArrow1 = 15.5f + c; cc_arrow1 = new CCDrawNode(); cc_arrow1a = new CCDrawNode(); cc_arrow1b = new CCDrawNode(); cc_arrow1.DrawLine( from: new CCPoint(posArrow1, 95), to: new CCPoint(posArrow1, 75), lineWidth: 1, color: color_red); cc_arrow1a.DrawLine( from: new CCPoint(posArrow1 + 0.5f, 75), to: new CCPoint(posArrow1 - 5, 80), lineWidth: 1, color: color_red); cc_arrow1b.DrawLine( from: new CCPoint(posArrow1 - 0.5f, 75), to: new CCPoint(posArrow1 + 5, 80), lineWidth: 1, color: color_red); layer.AddChild(cc_arrow1); layer.AddChild(cc_arrow1a); layer.AddChild(cc_arrow1b); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; var line = new CCDrawNode(); line.DrawLine(new CCPoint(0, windowSize.Height / 2), new CCPoint(windowSize.Width, windowSize.Height / 2), 10); AddChild(line, 0); byte alpha = 100; // 255 is full opacity var green = new CCColor4B(0, 255, 0, alpha); CCV3F_C4B[] verts = new CCV3F_C4B[] { new CCV3F_C4B(new CCPoint(0, 0), green), new CCV3F_C4B(new CCPoint(30, 60), green), new CCV3F_C4B(new CCPoint(60, 0), green) }; triangleList1.DrawTriangleList(verts); triangleList1.Position = windowSize.Center; triangleList1.PositionX -= windowSize.Width / 4; triangleList1.PositionY -= triangleList1.ContentSize.Center.Y; // Because the default BlendFunc of our DrawNode is AlphaBlend we need // to pass the colors as pre multiplied alpha. var greenPreMultiplied = green; greenPreMultiplied.G = (byte)(greenPreMultiplied.G * alpha / 255.0f); verts[0].Colors = greenPreMultiplied; verts[1].Colors = greenPreMultiplied; verts[2].Colors = greenPreMultiplied; triangleList2.DrawTriangleList(verts); triangleList2.Position = windowSize.Center; triangleList2.PositionX += windowSize.Width / 4; triangleList2.PositionY -= triangleList2.BoundingRect.Size.Height / 2; }
/********************************************************************** *********************************************************************/ public static void DrawFill() { int request = OldAllocationStrategies.memoryRequest; float start = 0; for (int i = 0; i <= pos; i++) { if (i == pos) { start += memoryBlocks[i, 1] * relativeFragmentSize; memoryBlocks[i, 0] -= request; memoryBlocks[i, 1] += request; } else { start += memoryBlocks[i, 1] * relativeFragmentSize + memoryBlocks[i, 0] * relativeFragmentSize; } if (i > 0) { start += relativeFragmentSize; } //don't forget the parting lines with width 1 } //Memory Box starts at 15 +1 linewidth -> we have to start at 16 float partingLineWidth = relativeFragmentSize / 2; float posXstart = 16f + start + +partingLineWidth; //var fill = new CCRect(posXstart, 22, posXend, 48);//CCRect(x,y,legth,width) cc_fill = new CCDrawNode(); for (int i = 0; i < request; i++) { cc_fill.DrawLine( from: new CCPoint(posXstart, 22), to: new CCPoint(posXstart, 70), lineWidth: partingLineWidth, color: color_blue); posXstart += relativeFragmentSize; } layer.AddChild(cc_fill); }
/********************************************************************** *********************************************************************/ static void DrawMemory() { //the problem with drawing lines is, that they don't start at a point and have a witdth in only one direction. //The width actually spreads in both directions. wich makes it kinda difficult //draw the outlines of the memorybox //since the border width is 1, in order to achieve exactly 300 entities space, we have to add 2 entities var box = new CCRect(15, 21, 302, 50);//CCRect(x,y,legth,width) cc_box = new CCDrawNode(); cc_box.DrawRect( box, fillColor: CCColor4B.White, borderWidth: 1, borderColor: color_red); //add box to layer layer.AddChild(cc_box); //draw fragmentation of memorybox //it's only necessary to draw the gaps/parting lines int fragmentSize; float sizeInBox; float partingLineWidth = relativeFragmentSize / 2; float startX = 16; //kinda fixed value, since I set the starting point of the whole memorybox to 15// also add the border with and start after that for (int i = 0; i < numberOfFragments - 1; i++) { fragmentSize = fragmentList.ElementAt(i); sizeInBox = fragmentSize * relativeFragmentSize; startX += sizeInBox + partingLineWidth; //draw the line CCDrawNode cc_partingLine = new CCDrawNode(); cc_partingLine.DrawLine( from: new CCPoint(startX, 22), to: new CCPoint(startX, 70), lineWidth: partingLineWidth, color: CCColor4B.Gray); layer.AddChild(cc_partingLine); startX += partingLineWidth; } }
public override void Draw(CCDrawNode node) { node.DrawLine(P1, P2, LINE_THICKNESS, CCColor4B.Red, CCLineCap.Round); node.DrawLine(P2, P3, LINE_THICKNESS, CCColor4B.Red, CCLineCap.Round); node.DrawLine(P3, P1, LINE_THICKNESS, CCColor4B.Red, CCLineCap.Round); }
private void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { if (touches.Count <= 0) { return; } if (_hitBubble == null) { return; } CCTouch touch = touches[0]; _line.DrawLine(_lastPoint, touch.Location, 3, _hitBubble.ColorF); _lastPoint = touch.Location; bool hitOtherColor = _visibleBubbles.Any(x => x.ContainsPoint(touch.Location) && x.BubbleColor != _hitBubble.BubbleColor); if (hitOtherColor) { foreach (Bubble bubble in _frozenBubbles) { bubble.ForcePop(this); _visibleBubbles.Remove(bubble); } _line.Clear(); _frozenBubbles.Clear(); _hitBubble = null; _multiplierLabel.Text = string.Empty; return; } IEnumerable <Bubble> bubbles = _visibleBubbles.Where( x => x.ContainsPoint(touch.Location) && x.BubbleColor == _hitBubble.BubbleColor && !x.IsFrozen).ToList(); if (bubbles == null || !bubbles.Any()) { return; } foreach (Bubble bubble in bubbles) { _frozenBubbles.Add(bubble); bubble.Freeze(_frozenBubbles.Count); } if (_frozenBubbles.Count > 1) { _multiplierLabel.SystemFontSize = 48 + _frozenBubbles.Count * 2; _multiplierLabel.Text = $"{_frozenBubbles.Count - 1}x"; } if (_frozenBubbles.Count >= 6) { CalculateScore(); CCAudioEngine.SharedEngine.PlayEffect("sounds/highscore"); } }
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 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.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); }
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); }
protected override void AddedToScene() { base.AddedToScene(); // DEBUG: test out the PopUp //PopUp.ShowPopUp(this, "This is a test."); var bounds = VisibleBoundsWorldspace; // move the part carousel away as the hangar does not start there PartCarousel.PositionY += PartCarousel.ContentSize.Height * 1.5f; HangarOptionHangar = new HangarOptionHangar(); HangarOptionWorkshop = new HangarOptionWorkshop(); HangarOptionScrapyard = new HangarOptionScrapyard(); HangarOptionCarousel = new Carousel(new CCSize(bounds.Size.Width, HangarOptionHangar.BoundingBoxTransformedToWorld.Size.Height)); HangarOptionCarousel.NodeAnchor = CCPoint.AnchorMiddleTop; AddChild(HangarOptionCarousel); HangarOptionCarousel.AnchorPoint = CCPoint.AnchorUpperLeft; HangarOptionCarousel.Position = new CCPoint(0, bounds.MaxY); HangarOptionCarousel.AddToCollection(HangarOptionHangar); HangarOptionCarousel.AddToCollection(HangarOptionWorkshop); HangarOptionCarousel.AddToCollection(HangarOptionScrapyard); TakeoffCollectionNode = new ScrollableCollectionNode(new CCSize(bounds.Size.Width, bounds.Size.Height / 7)); float borderToCollection = 15f; TakeoffNode.Position = CCPoint.Zero; TakeoffNode.AnchorPoint = CCPoint.AnchorLowerLeft; TakeoffNode.AddChild(TakeoffCollectionNode); TakeoffCollectionNode.PositionY = borderToCollection; TakeoffCollectionNode.Columns = HangarLayer.UnlockedPlaneSlots; // start off with only one plane slot unlocked TakeoffCollectionNode.Rows = 1; TakeoffCollectionNode.BoxSize = new CCSize(TakeoffCollectionNode.ContentSize.Height, TakeoffCollectionNode.ContentSize.Height); AddChild(TakeoffNode, zOrder: 1); TakeoffNode.ContentSize = new CCSize(TakeoffCollectionNode.ContentSize.Width, TakeoffCollectionNode.ContentSize.Height + 2 * borderToCollection); var drawNode = new CCDrawNode(); TakeoffNode.AddChild(drawNode, zOrder: -1); drawNode.DrawRect(TakeoffNode.BoundingBoxTransformedToWorld, CCColor4B.Black); drawNode.DrawLine(new CCPoint(0, TakeoffNode.BoundingBoxTransformedToWorld.UpperRight.Y), TakeoffNode.BoundingBoxTransformedToWorld.UpperRight, 8f, CCColor4B.White); drawNode.DrawLine(CCPoint.Zero, new CCPoint(TakeoffNode.BoundingBoxTransformedToWorld.MaxX, 0), 8f, CCColor4B.White); TakeoffNode.ContentSize = new CCSize(TakeoffNode.ContentSize.Width, TakeoffNode.ContentSize.Height + 2 * 4f); TakeoffNode.PositionY += 8f; TakeoffNode.AddChild(TakeoffCollectionLabel); TakeoffCollectionLabel.VerticalAlignment = CCVerticalTextAlignment.Center; TakeoffCollectionLabel.HorizontalAlignment = CCTextAlignment.Center; TakeoffCollectionLabel.Color = CCColor3B.White; TakeoffCollectionLabel.Scale = 2.5f; if (PopUp.TriggeredPlayLayer) { TakeoffCollectionLabel.Visible = false; } TakeoffCollectionLabel.AnchorPoint = CCPoint.AnchorMiddle; TakeoffCollectionLabel.Position = (CCPoint)TakeoffNode.ContentSize / 2; GOButton = new GOButton(); AddChild(GOButton); // place the go button a bit higher than the rest (in ZOrder) GOButton.Visible = false; GOButton.Position = GOButtonOutPosition; // let the hangar listen to the TakeoffCollectionNode TakeoffCollectionNode.CollectionRemovalEvent += HangarLayer.ReceiveAircraftFromCollection; // let the hangar listen to the Carousel for a change of the middle node HangarOptionCarousel.MiddleChangedEvent += HangarLayer.MiddleNodeChanged; // listen to the part carousel for a change of the middle node PartCarousel.MiddleChangedEvent += (sender, args) => { if (HangarLayer.State == HangarLayer.HangarState.MODIFY_AIRCRAFT) { HangarLayer.DrawInModifyAircraftState(); } }; // also listen to each part carousel node's collectionNode foreach (var node in PartCarousel.CollectionNode.Children) { PartCarouselNode pNode = (PartCarouselNode)node; pNode.PartCollectionNode.CollectionRemovalEvent += HangarLayer.ReceivePartFromCollection; } }
public override void Draw(CCDrawNode node) { node.DrawLine(L1.P1.ToCCPoint(), L1.P2.ToCCPoint(), LINE_THICKNESS, CCColor4B.Red, CCLineCap.Round); node.DrawLine(L2.P1.ToCCPoint(), L2.P2.ToCCPoint(), LINE_THICKNESS, CCColor4B.Red, CCLineCap.Round); }
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); } } } }
private void DrawTargetLine() { targetLine.Clear(); targetLine.DrawLine(this.Position, this.attackTarget.Position, CCColor4B.Green, CCLineCap.Square); }
void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { touches = FindUniqueTouches(touches); _clearTTL = _clearTTLResetValue; if (touches.Count == 1) { var touch = touches[0]; if (_trackedShape != null) { _trackedShape.Position += touch.Delta; } else { var location = touch.LocationOnScreen; _canvasNode.DrawLine(_lastKnownPoint, touch.Location, 5, CCColor4B.Red, CCLineCap.Round); if (_drawDebug) { _canvasNode.DrawSolidCircle(_lastKnownPoint, 5, CCColor4B.Green); } _lineRecognizer.RegisterPoint(_lastKnownPoint.X, _lastKnownPoint.Y); _lastKnownPoint = touch.Location; } } else if (touches.Count > 1 && _trackedShape != null) { var touch = touches[0]; _trackedShape.Position += touch.Delta; var t1 = touches[0]; var t2 = touches[1]; CCPoint p1; CCPoint p2; if (t1.Location.X < t2.Location.X) { p1.X = t1.Delta.X; p2.X = t2.Delta.X; } else { p1.X = t2.Delta.X; p2.X = t1.Delta.X; } if (t1.Location.Y < t2.Location.Y) { p1.Y = t1.Delta.Y; p2.Y = t2.Delta.Y; } else { p1.Y = t2.Delta.Y; p2.Y = t1.Delta.Y; } _trackedShape.SetNewPoints(_trackedShape.P1 + p1, _trackedShape.P2 + p2); } else { _lineRecognizer.Clear(); EvaluateResizeOrMoveStart(touches); } }