Advertisement
ptrelford

Simple SpriteKit demo in F#

Mar 4th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.99 KB | None | 0 0
  1. // Updated version of source from https://neildanson.wordpress.com/2013/09/19/simple-spritekit-demo-in-f/
  2.  
  3. namespace Demo
  4.  
  5. open System
  6. open System.Drawing
  7.  
  8. open Foundation
  9. open UIKit
  10. open SpriteKit
  11. open CoreGraphics
  12.  
  13. [<Register ("ViewController")>]
  14. type ViewController (handle:IntPtr) =
  15.     inherit UIViewController (handle)
  16.  
  17.     override x.DidReceiveMemoryWarning () =
  18.         // Releases the view if it doesn't have a superview.
  19.         base.DidReceiveMemoryWarning ()
  20.         // Release any cached data, images, etc that aren't in use.
  21.  
  22.     override x.ViewDidLoad () =
  23.          base.ViewDidLoad ()
  24.          //Create and configure the view
  25.          let skView = new SKView()
  26.          let width = x.View.Bounds.Width * UIScreen.MainScreen.Scale
  27.          let height = x.View.Bounds.Height * UIScreen.MainScreen.Scale
  28.          skView.Bounds <- CGRect(nfloat 0.0, nfloat 0.0, width, height)
  29.          skView.ShowsFPS <- true
  30.          skView.ShowsNodeCount <- true
  31.          x.View <- skView
  32.  
  33.          //Create and configure the screen
  34.          let scene =  new SKScene(skView.Bounds.Size)
  35.          scene.BackgroundColor <- UIColor.Cyan
  36.          scene.ScaleMode <- SKSceneScaleMode.AspectFill
  37.  
  38.          //Create a sprite
  39.          let spriteNode = new SKSpriteNode "Spaceship"
  40.          spriteNode.Position <- CGPoint(200.0,200.0)
  41.  
  42.          //Set a repeating 360 degree rotation
  43.          let action = SKAction.RotateByAngle(nfloat Math.PI,1.0)
  44.          let action = SKAction.RepeatActionForever action
  45.          spriteNode.RunAction action
  46.  
  47.          //Add sprite to scene
  48.          scene.AddChild spriteNode
  49.  
  50.          //Show scene
  51.          skView.PresentScene scene
  52.  
  53.     override x.ShouldAutorotateToInterfaceOrientation (toInterfaceOrientation) =
  54.         // Return true for supported orientations
  55.         if UIDevice.CurrentDevice.UserInterfaceIdiom = UIUserInterfaceIdiom.Phone then
  56.            toInterfaceOrientation <> UIInterfaceOrientation.PortraitUpsideDown
  57.         else
  58.            true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement