예제 #1
0
        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;
        }
예제 #2
0
        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;
        }