private void AddAxes() { CGPath pathToDraw; var center = new CGPoint(0, 0); var xAxis = new SKShapeNode(); pathToDraw = new CGPath(); pathToDraw.MoveToPoint(center); pathToDraw.AddLineToPoint(new CGPoint(1000, 0)); xAxis.Path = pathToDraw; xAxis.StrokeColor = UIColor.LightGray; xAxis.LineWidth = 2; AddChild(xAxis); var yAxis = new SKShapeNode(); pathToDraw = new CGPath(); pathToDraw.MoveToPoint(center); pathToDraw.AddLineToPoint(new CGPoint(0, 1000)); yAxis.Path = pathToDraw; yAxis.StrokeColor = UIColor.LightGray; yAxis.LineWidth = 2; AddChild(yAxis); var zAxis = new SKShapeNode(); pathToDraw = new CGPath(); pathToDraw.MoveToPoint(center); pathToDraw.AddLineToPoint(new CGPoint(center.X - 1000, center.Y - 1000)); zAxis.Path = pathToDraw; zAxis.StrokeColor = UIColor.LightGray; zAxis.LineWidth = 2; AddChild(zAxis); }
public ShipSprite(CGPoint initialPosition) : base(NSBundle.MainBundle.PathForResource("spaceship", "png")) { CGPath boundingPath = new CGPath(); boundingPath.MoveToPoint(-12f, -38f); boundingPath.AddLineToPoint(12f, -38f); boundingPath.AddLineToPoint(9f, 18f); boundingPath.AddLineToPoint(2f, 38f); boundingPath.AddLineToPoint(-2f, 38f); boundingPath.AddLineToPoint(-9f, 18f); boundingPath.AddLineToPoint(-12f, -38f); #if false // Debug overlay SKShapeNode shipOverlayShape = new SKShapeNode() { Path = boundingPath, StrokeColor = UIColor.Clear, FillColor = UIColor.FromRGBA(0f, 1f, 0f, 0.5f) }; ship.AddChild(shipOverlayShape); #endif var body = SKPhysicsBody.CreateBodyFromPath(boundingPath); body.CategoryBitMask = Category.Ship; body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge; body.ContactTestBitMask = body.CollisionBitMask; body.LinearDamping = 0; body.AngularDamping = 0.5f; PhysicsBody = body; Position = initialPosition; }
void CreateGameBoard(nfloat width, nfloat height) { var cellWidth = 14; var numRows = 40; var numCols = 20; var x = (width / -2f) + (cellWidth / 2f); var y = (height / 2f) - (cellWidth / 2f); //loop through rows and columns, create cells for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { var cellNode = SKShapeNode.FromRect(new CGSize(width: cellWidth, height: cellWidth)); cellNode.StrokeColor = UIColor.Black; cellNode.ZPosition = 2; cellNode.Position = new CGPoint( x: Frame.GetMidX() + x, y: Frame.GetMidY() + 40 + y); //add to array of cells -- then add to game board gameArray.Add(new CellObj(cellNode, i, j)); gameBG.AddChild(cellNode); //iterate x x += cellWidth; } //reset x, iterate y x = (width / -2f) + (cellWidth / 2f); y -= cellWidth; } }
public LineBar(GameController controller, CGPoint position, NSColor color) { this.controller = controller; this.position = position; this.color = color; MaxLineWidth = 300; MaxlineHeigth = 10; Line = SKShapeNode.FromRect(new CGSize(MaxLineWidth, MaxlineHeigth)); Line.FillColor = color; Line.Position = position; Line.ZPosition = 1; Border = SKShapeNode.FromRect(new CGSize(MaxLineWidth, MaxlineHeigth)); Border.StrokeColor = NSColor.Black; Border.Position = position; Border.ZPosition = 1; Label = new SKLabelNode { FontColor = NSColor.White, FontName = "Arial", FontSize = 20, Text = "txt", ZPosition = 1 }; Label.Position = new CGPoint( Line.Position.X, Line.Position.Y + Label.FontSize / 2); controller.Scene.AddNodes(Line, Border, Label); }
public static SKShapeNode MakeSquiggle() { // new Path var shape = SKShapeNode.FromCircle(12.5f); return(shape); }
public static SKShapeNode MakeDiamond() { var square = SKShapeNode.FromRect(Settings.Sizes.DiamondSize); square.ZRotation = 44.99999999f; return(square); }
private void DrawFlag() { var s1 = new SKShapeNode(); var p1 = new CGPath(); p1.MoveToPoint(size / 3.0f, size / 2.0f); p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f); p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f * 2); s1.Path = p1.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s1.StrokeColor = NSColor.Red; s1.FillColor = NSColor.Red; AddChild(s1); var s2 = new SKShapeNode(); var p2 = new CGPath(); p2.MoveToPoint(size / 3.0f * 2, size - size / 3.0f); p2.AddLineToPoint(size / 3.0f * 2, size / 4.0f); p2.AddLineToPoint(size / 2.0f, size / 4.0f); p2.AddLineToPoint(size - size / 5.0f, size / 4.0f); s2.Path = p2.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s2.StrokeColor = NSColor.Black; s2.FillColor = NSColor.FromCalibratedRgba(0.0f, 0.0f, 0.0f, 0.0f); s2.LineWidth = size / 20; AddChild(s2); }
private void Win() { state = State.Win; ShowMines(-1); var background = new SKShapeNode(); var p = new CGPath(); p.MoveToPoint(0, 0); p.AddLineToPoint(40 * 19, 0); p.AddLineToPoint(40 * 19, 40 * 13); p.AddLineToPoint(0, 40 * 13); p.AddLineToPoint(0, 0); background.Path = p; background.FillColor = NSColor.FromCalibratedRgba(1.0f, 1.0f, 1.0f, 0.7f); AddChild(background); var label = new SKLabelNode("Arial"); label.Text = "Win"; label.FontColor = NSColor.FromCalibratedRgb(0.0f, 0.502f, 0.0f); label.FontSize = 40; label.Position = new CGPoint(40 * 19 / 2, 40 * 13 / 2); label.VerticalAlignmentMode = SKLabelVerticalAlignmentMode.Center; label.HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center; AddChild(label); }
public void RenderExplodedMine() { RemoveAllChildren(); var s = new SKShapeNode(); var path = new CGPath(); path.MoveToPoint(0, 0); path.AddLineToPoint(size, 0); path.AddLineToPoint(size, size); path.AddLineToPoint(0, size); path.AddLineToPoint(0, 0); s.Path = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f); s.FillColor = NSColor.FromCalibratedRgb(0.8f, 0.8f, 0.8f); AddChild(s); var s1 = new SKShapeNode(); var p1 = new CGPath(); p1.AddArc(x * size + size / 2, y * size + size / 2, size / 4, 0, 2 * (float)Math.PI, true); s1.Path = p1; s1.StrokeColor = NSColor.FromCalibratedRgb(0.2f, 0.2f, 0.2f); s1.FillColor = NSColor.FromCalibratedRgb(0.8f, 0.0f, 0.0f); AddChild(s1); }
public ShipSprite(PointF initialPosition) : base(NSBundle.MainBundle.PathForResource ("spaceship", "png")) { CGPath boundingPath = new CGPath (); boundingPath.MoveToPoint (-12f, -38f); boundingPath.AddLineToPoint (12f, -38f); boundingPath.AddLineToPoint (9f, 18f); boundingPath.AddLineToPoint (2f, 38f); boundingPath.AddLineToPoint (-2f, 38f); boundingPath.AddLineToPoint (-9f, 18f); boundingPath.AddLineToPoint (-12f, -38f); #if false // Debug overlay SKShapeNode shipOverlayShape = new SKShapeNode () { Path = boundingPath, StrokeColor = UIColor.Clear, FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f) }; ship.AddChild (shipOverlayShape); #endif var body = SKPhysicsBody.BodyWithPolygonFromPath (boundingPath); body.CategoryBitMask = Category.Ship; body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge; body.ContactTestBitMask = body.CollisionBitMask; body.LinearDamping = 0; body.AngularDamping = 0.5f; PhysicsBody = body; Position = initialPosition; }
public Slider(int width, int height, string text) : base() { // create a label var fontName = "Optima-ExtraBlack"; this.label = SKLabelNode.FromFont(fontName); this.label.Text = text; this.label.FontSize = 18; this.label.FontColor = SKColor.White; this.label.Position = new CGPoint(0f, -8f); // create background & slider this.background = new SKSpriteNode(SKColor.White, new CGSize(width, 2f)); this.slider = SKShapeNode.FromCircle(height); this.slider.FillColor = SKColor.White; this.background.AnchorPoint = new CGPoint(0f, 0.5f); this.slider.Position = new CGPoint(this.label.Frame.Size.Width / 2f + 15f, 0f); this.background.Position = new CGPoint(this.label.Frame.Size.Width / 2f + 15f, 0f); // add to the root node this.AddChild(this.label); this.AddChild(this.background); this.AddChild(this.slider); // track mouse event base.UserInteractionEnabled = true; this.Value = 0f; }
void InitializeGameView() { currentScore = new SKLabelNode("ArialRoundedMTBold"); currentScore.ZPosition = 1; currentScore.Position = new CGPoint( x: Frame.GetMidX(), y: Frame.GetMidY() + (Frame.Size.Height / -2f) + 60); currentScore.FontSize = 20; currentScore.Hidden = true; currentScore.Text = "Score: 0"; currentScore.FontColor = UIColor.White; AddChild(currentScore); var width = Frame.Size.Width - 94; var height = Frame.Size.Height - 106; var rect = new CGRect( x: Frame.GetMidX() - width / 2f, y: Frame.GetMidY() - height / 2f + 40, width: width, height: height); gameBG = SKShapeNode.FromRect(rect: rect, cornerRadius: 0.02f); gameBG.FillColor = UIColor.DarkGray; gameBG.ZPosition = 2; gameBG.Hidden = true; AddChild(gameBG); CreateGameBoard(width: width, height: height); }
internal void loadWeaponRangeShapeNode(GameWorld gameWorld) { SKShapeNode shapeNode = new SKShapeNode(weaponRange); shapeNode.position = position; shapeNode.alpha = 0.0f; gameWorld.addChild(shapeNode); weaponRangeShapeNode = shapeNode; }
private SKShapeNode CreateLightAtPosition(CGPoint position) { var circle = SKShapeNode.FromCircle(CountDownLightRadius); circle.Position = position; circle.StrokeColor = UIColor.DarkGray; circle.LineWidth = 3; circle.FillColor = UIColor.Red; return(circle); }
private void DrawMine() { var s1 = new SKShapeNode(); var p1 = new CGPath(); p1.AddArc(size / 2, size / 2, size / 4, 0, 2 * (float)Math.PI, true); s1.Path = p1.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s1.StrokeColor = NSColor.FromCalibratedRgb(0.2f, 0.2f, 0.2f); s1.FillColor = NSColor.FromCalibratedRgb(0.4f, 0.4f, 0.4f); AddChild(s1); }
void AddAnchorDotToSprite (SKSpriteNode sprite) { CGPath myPath = new CGPath (); myPath.AddArc (0, 0, 10, 0, (float) Math.PI * 2, true); myPath.CloseSubpath (); SKShapeNode dot = new SKShapeNode () { Path = myPath, FillColor = UIColor.Green, LineWidth = 0.0f }; sprite.AddChild (dot); }
public void FromSplinePointsTest() { TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false); TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 10, throwIfOtherPlatform: false); var pts = new[] { new CGPoint(0, 0), new CGPoint(320, 568) }; var result = SKShapeNode.FromSplinePoints(pts); Assert.IsNotNull(result, "result should not be null"); }
void InitializeMenu() { //Create game title gameLogo = new SKLabelNode("ArialRoundedMTBold"); gameLogo.ZPosition = 1; gameLogo.Position = new CGPoint( x: Frame.GetMidX(), y: Frame.GetMidY() + (Frame.Size.Height / 2f) - 200); gameLogo.FontSize = 60; gameLogo.Text = "SNAKE"; gameLogo.FontColor = UIColor.Red; AddChild(gameLogo); //Create best score label bestScore = new SKLabelNode("ArialRoundedMTBold"); bestScore.ZPosition = 1; bestScore.Position = new CGPoint( x: Frame.GetMidX(), y: gameLogo.Position.Y - 50); bestScore.FontSize = 20; bestScore.Text = $"Best Score: {game.SavedBestScore}"; bestScore.FontColor = UIColor.White; AddChild(bestScore); //Create play button playButton = new SKShapeNode(); playButton.Name = "play_button"; playButton.ZPosition = 1; playButton.Position = new CGPoint( x: 0, y: (Frame.Size.Height / -2f) + 200); playButton.FillColor = UIColor.Cyan; var topCorner = new CGPoint( x: Frame.GetMidX() - 50, y: Frame.GetMidY() + 50); var bottomCorner = new CGPoint( x: Frame.GetMidX() - 50, y: Frame.GetMidY() - 50); var middle = new CGPoint( x: Frame.GetMidX() + 50, y: Frame.GetMidY()); var path = new CGPath(); path.AddLineToPoint(topCorner.X, topCorner.Y); path.AddLines(new[] { topCorner, bottomCorner, middle }); playButton.Path = path; AddChild(playButton); }
private void DrawTile() { var s = new SKShapeNode(); var path = new CGPath(); path.MoveToPoint(0, 0); path.AddLineToPoint(size, 0); path.AddLineToPoint(size, size); path.AddLineToPoint(0, size); path.AddLineToPoint(0, 0); s.Path = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f); s.FillColor = NSColor.FromCalibratedRgb(0.8f, 0.8f, 0.8f); AddChild(s); }
private void DrawCross() { var s3 = new SKShapeNode(); var p3 = new CGPath(); p3.MoveToPoint(size / 5.0f, size / 5.0f); p3.AddLineToPoint(size - size / 5.0f, size - size / 5.0f); p3.MoveToPoint(size / 5.0f, size - size / 5.0f); p3.AddLineToPoint(size - size / 5.0f, size / 5.0f); s3.Path = p3.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s3.StrokeColor = NSColor.Black; s3.FillColor = NSColor.FromCalibratedRgba(0.0f, 0.0f, 0.0f, 0.0f); s3.LineWidth = size / 20; AddChild(s3); }
public void FromSplinePointsTest() { if (!TestRuntime.CheckSystemAndSDKVersion(8, 0)) { Assert.Ignore("requires iOS8+"); } var pts = new[] { new PointF(0, 0), new PointF(320, 568) }; var result = SKShapeNode.FromSplinePoints(pts); Assert.IsNotNull(result, "result should not be null"); }
public void FromSplinePointsOffsetTest() { TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false); TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 10, throwIfOtherPlatform: false); var pts = new [] { new CGPoint(0, 0), new CGPoint(320, 568) }; var result = SKShapeNode.FromSplinePoints(pts, 1, 1); Assert.IsNotNull(result, "result should not be null"); Assert.Throws <InvalidOperationException> (() => SKShapeNode.FromSplinePoints(pts, 1, 2)); }
void AddAnchorDotToSprite(SKSpriteNode sprite) { CGPath myPath = new CGPath(); myPath.AddArc(0, 0, 10, 0, (float)Math.PI * 2, true); myPath.CloseSubpath(); SKShapeNode dot = new SKShapeNode() { Path = myPath, FillColor = UIColor.Green, LineWidth = 0.0f }; sprite.AddChild(dot); }
GKObstacle AddObstacle(CGPoint point) { var circleShape = SKShapeNode.FromCircle(DefaultAgentRadius); circleShape.LineWidth = 2.5f; circleShape.FillColor = SKColor.Gray; circleShape.StrokeColor = SKColor.Red; circleShape.ZPosition = 1; circleShape.Position = point; AddChild(circleShape); var obstacle = new GKCircleObstacle(DefaultAgentRadius); obstacle.Position = new Vector2((float)point.X, (float)point.Y); return(obstacle); }
public void RenderDiscovered(int nbMinesAround) { state = State.Discovered; RemoveAllChildren(); var s = new SKShapeNode(); var path = new CGPath(); path.MoveToPoint(0, 0); path.AddLineToPoint(size, 0); path.AddLineToPoint(size, size); path.AddLineToPoint(0, size); path.AddLineToPoint(0, 0); s.Path = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size)); s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f); s.FillColor = NSColor.FromCalibratedRgb(1.0f, 1.0f, 1.0f); AddChild(s); if (nbMinesAround == 0) { return; } NSColor[] colors = { NSColor.FromCalibratedRgb(0.0f, 0.0f, 1.0f), // Blue NSColor.FromCalibratedRgb(0.0f, 0.502f, 0.0f), // Green NSColor.FromCalibratedRgb(1.0f, 0.0f, 0.0f), // Red NSColor.FromCalibratedRgb(0.0f, 0.0f, 0.502f), // Navy NSColor.FromCalibratedRgb(0.502f, 0.0f, 0.0f), // Maroon NSColor.FromCalibratedRgb(0.0f, 1.0f, 1.0f), // Aqua NSColor.FromCalibratedRgb(0.502f, 0.0f, 0.502f), // Purple NSColor.FromCalibratedRgb(0.0f, 0.0f, 0.0f), // Black }; var label = new SKLabelNode("Arial") { Text = nbMinesAround.ToString(), Position = new CGPoint(x * 40 + 20, y * 40 + 20), FontColor = colors[nbMinesAround - 1], HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center, VerticalAlignmentMode = SKLabelVerticalAlignmentMode.Center, FontSize = 38, }; AddChild(label); }
public void UpdateBarData(double data) { Label.Text = StrTemplate + $" { data } / 100"; double widthHpAspect = MaxLineWidth / 100; double HPBarWidth = data * widthHpAspect; controller.Scene.RemoveChildren(new SKNode[] { Line }); double HPBarHeight = MaxlineHeigth; Line = SKShapeNode.FromRect(new CGSize(HPBarWidth, HPBarHeight)); Line.Position = new CGPoint(position.X - (MaxLineWidth - HPBarWidth) / 2, position.Y); Line.FillColor = color; controller.Scene.AddChild(Line); }
public void FromSplinePointsOffsetTest() { if (!TestRuntime.CheckSystemAndSDKVersion(8, 0)) { Assert.Ignore("requires iOS8+"); } var pts = new [] { new PointF(0, 0), new PointF(320, 568) }; var result = SKShapeNode.FromSplinePoints(pts, 1, 1); Assert.IsNotNull(result, "result should not be null"); Assert.Throws <InvalidOperationException> (() => SKShapeNode.FromSplinePoints(pts, 1, 2)); }
public override void DidMoveToView(SKView view) { base.DidMoveToView(view); var follower = new AgentNode(this, DefaultAgentRadius, new CGPoint(Frame.GetMidX(), Frame.GetMidY())) { Color = SKColor.Cyan }; var center = new Vector2((float)Frame.GetMidX(), (float)Frame.GetMidY()); var points = new [] { new Vector2(center.X, center.Y + 50), new Vector2(center.X + 50, center.Y + 150), new Vector2(center.X + 100, center.Y + 150), new Vector2(center.X + 200, center.Y + 200), new Vector2(center.X + 350, center.Y + 150), new Vector2(center.X + 300, center.Y), new Vector2(center.X, center.Y - 200), new Vector2(center.X - 200, center.Y - 100), new Vector2(center.X - 200, center.Y), new Vector2(center.X - 100, center.Y + 50), }; var path = GKPath.FromPoints(points, DefaultAgentRadius, true); follower.Agent.Behavior = GKBehavior.FromGoal(GKGoal.GetGoalToFollowPath(path, 1.5, true), 1); AgentSystem.AddComponent(follower.Agent); var cgPoints = new CGPoint[11]; for (var i = 0; i < 10; i++) { cgPoints [i] = new CGPoint(points [i].X, points [i].Y); } cgPoints [10] = cgPoints [0]; var pathShape = SKShapeNode.FromPoints(ref cgPoints [0], 11); pathShape.LineWidth = 2; pathShape.StrokeColor = SKColor.Magenta; AddChild(pathShape); }
public void InitAgent(SKScene scene, float radius, CGPoint position) { Position = position; ZPosition = 10f; scene.AddChild(this); Agent = new GKAgent2D { Radius = radius, Position = new Vector2((float)position.X, (float)position.Y), Delegate = this, MaxSpeed = 100f, MaxAcceleration = 50f }; var circleShape = SKShapeNode.FromCircle(radius); circleShape.LineWidth = 2.5f; circleShape.FillColor = SKColor.Gray; circleShape.ZPosition = 1f; AddChild(circleShape); const float triangleBackSideAngle = (float)((135f / 360f) * (2 * Math.PI)); var points = new [] { new CGPoint(radius, 0f), // Tip new CGPoint(radius * Math.Cos(triangleBackSideAngle), radius * Math.Sin(triangleBackSideAngle)), // Back bottom new CGPoint(radius * Math.Cos(triangleBackSideAngle), -radius * Math.Sin(triangleBackSideAngle)), // Back top new CGPoint(radius, 0f) // Back top }; TriangleShape = SKShapeNode.FromPoints(ref points [0], (nuint)points.Length); TriangleShape.LineWidth = 2.5f; TriangleShape.ZPosition = 1f; AddChild(TriangleShape); Particles = SKNode.FromFile <SKEmitterNode> ("Trail.sks"); DefaultParticleRate = (float)Particles.ParticleBirthRate; Particles.Position = new CGPoint(-radius + 5, 0); Particles.TargetNode = scene; Particles.ZPosition = 0f; AddChild(Particles); }
private void BuildPad() { var backgroundRect = new CGRect(0f, 0f, this.Size.Width, this.Size.Height); this.background = new SKShapeNode(); this.background.Path = CGPath.EllipseFromRect(backgroundRect); this.background.StrokeColor = UIColor.Black; this.background.LineWidth = 3f; this.AddChild(this.background); var stickRect = CGRect.Empty; stickRect.Size = this.StickSize; this.stick = new SKShapeNode(); this.stick.Path = CGPath.EllipseFromRect(stickRect); this.stick.LineWidth = 2f; this.stick.FillColor = UIColor.White; this.stick.StrokeColor = UIColor.Black; this.AddChild(this.stick); this.UpdateStickPosition(); }
public ShipSprite(CGPoint initialPosition) : base(NSBundle.MainBundle.PathForResource("spaceship", "png")) { health = startingShipHealth; using (CGPath boundingPath = new CGPath()) { boundingPath.MoveToPoint(-12f, -38f); boundingPath.AddLineToPoint(12f, -38f); boundingPath.AddLineToPoint(9f, 18f); boundingPath.AddLineToPoint(2f, 38f); boundingPath.AddLineToPoint(-2f, 38f); boundingPath.AddLineToPoint(-9f, 18f); boundingPath.AddLineToPoint(-12f, -38f); #if false // Debug overlay SKShapeNode shipOverlayShape = new SKShapeNode() { Path = boundingPath, StrokeColor = UIColor.Clear, FillColor = UIColor.FromRGBA(0f, 1f, 0f, 0.5f) }; ship.AddChild(shipOverlayShape); #endif var body = SKPhysicsBody.CreateBodyFromPath(boundingPath); body.CategoryBitMask = Category.Ship; body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge; body.ContactTestBitMask = body.CollisionBitMask; // The ship doesn't slow down when it moves forward, but it does slow its angular rotation. In practice, // this feels better for a game. body.LinearDamping = 0; body.AngularDamping = 0.5f; PhysicsBody = body; } Position = initialPosition; }
public ShipSprite (CGPoint initialPosition) : base (NSBundle.MainBundle.PathForResource ("spaceship", "png")) { health = startingShipHealth; using (CGPath boundingPath = new CGPath ()) { boundingPath.MoveToPoint (-12f, -38f); boundingPath.AddLineToPoint (12f, -38f); boundingPath.AddLineToPoint (9f, 18f); boundingPath.AddLineToPoint (2f, 38f); boundingPath.AddLineToPoint (-2f, 38f); boundingPath.AddLineToPoint (-9f, 18f); boundingPath.AddLineToPoint (-12f, -38f); #if false // Debug overlay SKShapeNode shipOverlayShape = new SKShapeNode () { Path = boundingPath, StrokeColor = UIColor.Clear, FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f) }; ship.AddChild (shipOverlayShape); #endif var body = SKPhysicsBody.CreateBodyFromPath (boundingPath); body.CategoryBitMask = Category.Ship; body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge; body.ContactTestBitMask = body.CollisionBitMask; // The ship doesn't slow down when it moves forward, but it does slow its angular rotation. In practice, // this feels better for a game. body.LinearDamping = 0; body.AngularDamping = 0.5f; PhysicsBody = body; } Position = initialPosition; }
private void BuildPad(string text) { var backgroundRect = new CGRect(0f, 0f, this.Size.Width, this.Size.Height); this.background = new SKShapeNode { Path = CGPath.EllipseFromRect(backgroundRect), StrokeColor = UIColor.Black, LineWidth = 3f }; this.AddChild(this.background); this.inner = new SKShapeNode { LineWidth = 1f, FillColor = UIColor.White, StrokeColor = UIColor.Gray, Path = CGPath.EllipseFromRect(new CGRect(0f, 0f, this.Size.Width, this.Size.Height)), }; this.AddChild(this.inner); this.label = new SKLabelNode { Text = text, FontSize = 24f, FontColor = UIColor.Black, FontName = UIFont.BoldSystemFontOfSize(24f).Name, VerticalAlignmentMode = SKLabelVerticalAlignmentMode.Center, HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center, Position = new CGPoint(this.Size.Width / 2f, this.Size.Height / 2f + 1f), }; this.AddChild(this.label); }
public void InitAgent(SKScene scene, float radius, CGPoint position) { Position = position; ZPosition = 10f; scene.AddChild (this); Agent = new GKAgent2D { Radius = radius, Position = new Vector2 ((float)position.X, (float)position.Y), Delegate = this, MaxSpeed = 100f, MaxAcceleration = 50f }; var circleShape = SKShapeNode.FromCircle (radius); circleShape.LineWidth = 2.5f; circleShape.FillColor = SKColor.Gray; circleShape.ZPosition = 1f; AddChild (circleShape); const float triangleBackSideAngle = (float)((135f / 360f) * (2 * Math.PI)); var points = new [] { new CGPoint (radius, 0f), // Tip new CGPoint (radius * Math.Cos (triangleBackSideAngle), radius * Math.Sin (triangleBackSideAngle)), // Back bottom new CGPoint (radius * Math.Cos (triangleBackSideAngle), -radius * Math.Sin (triangleBackSideAngle)), // Back top new CGPoint (radius, 0f) // Back top }; TriangleShape = SKShapeNode.FromPoints (ref points [0], (nuint)points.Length); TriangleShape.LineWidth = 2.5f; TriangleShape.ZPosition = 1f; AddChild (TriangleShape); Particles = SKNode.FromFile<SKEmitterNode> ("Trail.sks"); DefaultParticleRate = (float)Particles.ParticleBirthRate; Particles.Position = new CGPoint (-radius + 5, 0); Particles.TargetNode = scene; Particles.ZPosition = 0f; AddChild (Particles); }
/// <summary> /// Helper method that creates the grid shown in the background of the scene. /// </summary> /// <returns>The background node.</returns> /// <param name="size">Size of the scene.</param> /// <param name="height">Height of the scene.</param> static SKNode CreateBackgroundNode(SizeF size) { // Use a SKShapeNode. This can display any arbitrary CG content. var shapeNode = new SKShapeNode (); var path = new CGPath(); shapeNode.StrokeColor = UIColor.FromRGB (112, 80, 160); float cellSize = 32f; // Draw vertical lines. float x = 0f; do { path.MoveToPoint (x, 0); path.AddLineToPoint (x, size.Height); x += cellSize; } while(x < size.Width); // Draw horizontal lines. float y = 0f; do { path.MoveToPoint (0, y); path.AddLineToPoint (size.Width, y); y += cellSize; } while(y < size.Height); shapeNode.Path = path; return shapeNode; }