So, you may have noticed iOS 7 was released yesterday, and the nice folks over at Xamarin released an update to Xamarin.iOS less than a day later. Nice!
One of the nice features on iOS7 is Sprite Kit. This includes 2D sprites, Physics (using box2D) and Animation.
So to help you get going, heres how to get started in F#. This code is based on the Objective-C sample, so isn’t hugely interesting to look at, but may be enough to get started.
First create an Xamarin iOS F# SingleView application. Target iOS 7 in the project options.
open the MonoTouch.SpriteKit namespace. Add a png to the project under the “Resources” folder. Call it whatever you like, but make sure you name it the same in the code below.
Then replace the code in ViewDidLoad in the UICiewController with this
override x.ViewDidLoad () =
base.ViewDidLoad ()
//Create and configure the view
let skView = new SKView()
skView.Bounds <- RectangleF(0.f,0.f,
x.View.Bounds.Width * UIScreen.MainScreen.Scale,
x.View.Bounds.Height * UIScreen.MainScreen.Scale)
skView.ShowsFPS <- true
skView.ShowsNodeCount <- true
x.View <- skView
//Create and configure the screen
let scene = new SKScene(skView.Bounds.Size)
scene.BackgroundColor <- UIColor.Cyan
scene.ScaleMode <- SKSceneScaleMode.AspectFill
//Create a sprite
let spriteNode = new SKSpriteNode "Spaceship"
spriteNode.Position <- PointF(200.f,200.f)
//Set a repeating 360 degree rotation
let action = SKAction.RotateByAngle(float32 Math.PI,1.0)
let action = SKAction.RepeatActionForever action
spriteNode.RunAction action
//Add sprite to scene
scene.AddChild spriteNode
//Show scene
skView.PresentScene scene
Running you should see something like this:
I’m a big advocate of Monogame and Farseer, and for cross-platform scenarios it is definitely the way to go, but if you only want to target iOS, then Sprite Kit may be worth a look.
Next I’ll take a look at integrating some simple physics……
Pingback: F# Weekly #38, 2013 | Sergey Tihon's Blog
Pingback: SpriteKit and Physics in F# | Neil Danson's Blog
Pingback: A Platform game in SpriteKit and F# – Part 1 – Game State Management | Neil Danson's Blog
Pingback: A Platform game in SpriteKit and F# – Part 2 – Start building a level | Neil Danson's Blog