Page 1 of 1

Playing with SpriteKit (OS X 10.9 Mavericks, x64)

Posted: Tue Nov 12, 2013 11:15 am
by wilbert
OS X 10.9 Mavericks provides a nice new framework called SpriteKit.
It looks like x64 is required to use the SpriteKit framework.

Code: Select all

Enumeration
  #SKBlendModeAlpha
  #SKBlendModeAdd
  #SKBlendModeSubtract
  #SKBlendModeMultiply
  #SKBlendModeMultiplyX2
  #SKBlendModeScreen
  #SKBlendModeReplace
EndEnumeration

; *** Import some things ***

ImportC "/System/Library/Frameworks/SpriteKit.framework/SpriteKit"
  CGPathCreateMutable()
  CGPathMoveToPoint(path, *m.CGAFFineTransform, x.CGFloat, y.CGFloat)
  CGPathAddLineToPoint(path, *m.CGAFFineTransform, x.CGFloat, y.CGFloat)
  CGPathAddCurveToPoint(path, *m.CGAFFineTransform, cp1x.CGFloat, cp1y.CGFloat, cp2x.CGFloat, cp2y.CGFloat, x.CGFloat, y.CGFloat)
  CGPathAddQuadCurveToPoint(path, *m.CGAFFineTransform, cpx.CGFloat, cpy.CGFloat, x.CGFloat, y.CGFloat)
  CGPathRelease(path)
EndImport


; *** Create View and Scene ***

Frame.NSRect\size\width = 640
Frame\size\height = 400

View = CocoaMessage(0, CocoaMessage(0, 0, "SKView alloc"), "initWithFrame:@", @Frame)
Scene = CocoaMessage(0, CocoaMessage(0, 0, "SKScene alloc"), "initWithSize:@", @Frame\size)

OpenWindow(0, 0, 0, Frame\size\width, Frame\size\height, "SpriteKit test (OS X 10.9)", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
CocoaMessage(0, CocoaMessage(0, WindowID(0), "contentView"), "addSubview:", View)
HideWindow(0, #False)


; *** Create sprite node ***

CreateImage(0, 64, 64, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)  
Ellipse(32, 32, 15, 30, RGBA(255, 128, 0, 255))  
StopDrawing()

Texture = CocoaMessage(0, 0, "SKTexture textureWithImage:", ImageID(0))
SpriteNode1 = CocoaMessage(0, CocoaMessage(0, 0, "SKSpriteNode spriteNodeWithTexture:", Texture), "retain")
SpriteNode2 = CocoaMessage(0, CocoaMessage(0, 0, "SKSpriteNode spriteNodeWithTexture:", Texture), "retain")

; *** Run a repeated action for the sprite ***

Path = CGPathCreateMutable()
CGPathMoveToPoint(Path, #Null, 320, 200)
CGPathAddCurveToPoint(Path, #Null, 0, 0, 640, 0, 520, 100)
CGPathAddCurveToPoint(Path, #Null, 640, 0, 0, 0, 120, 100)
CGPathAddCurveToPoint(Path, #Null, 0, 0, 640, 0, 320, 200)
CGPathAddCurveToPoint(Path, #Null, 640, 0, 0, 0, 320, 200)

Duration.d = 10
Action1 = CocoaMessage(0, 0, "SKAction followPath:", Path, "asOffset:", #NO, "orientToPath:", #YES, "duration:@", @Duration)
RepeatedAction1 = CocoaMessage(0, 0, "SKAction repeatActionForever:", Action1)
CocoaMessage(0, SpriteNode1, "runAction:", RepeatedAction1)
CocoaMessage(0, SpriteNode1, "setBlendMode:", #SKBlendModeAdd)

Duration = 9
Action2 = CocoaMessage(0, 0, "SKAction followPath:", Path, "asOffset:", #NO, "orientToPath:", #YES, "duration:@", @Duration)
RepeatedAction2 = CocoaMessage(0, 0, "SKAction repeatActionForever:", Action2)
CocoaMessage(0, SpriteNode2, "runAction:", RepeatedAction2)
CocoaMessage(0, SpriteNode2, "setBlendMode:", #SKBlendModeAdd)

CGPathRelease(Path)

; *** Add the sprite to the scene and present the scene ***

CocoaMessage(0, Scene, "addChild:", SpriteNode1)
CocoaMessage(0, Scene, "addChild:", SpriteNode2)
CocoaMessage(0, View, "presentScene:", Scene)


; *** Main loop ***

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Playing with SpriteKit (OS X 10.9 Mavericks, x64)

Posted: Tue Nov 12, 2013 6:54 pm
by J. Baker
Thanks wilbert! It looks like I'll have to install OS X Mavericks to try this out. ;)

Re: Playing with SpriteKit (OS X 10.9 Mavericks, x64)

Posted: Wed Nov 13, 2013 1:54 pm
by J. Baker
This is pretty cool! I just wish Apple would have made it 32bit as well. ;)

Re: Playing with SpriteKit (OS X 10.9 Mavericks, x64)

Posted: Wed Nov 13, 2013 2:03 pm
by wilbert
J. Baker wrote:This is pretty cool! I just wish Apple would have made it 32bit as well. ;)
SpriteKit requires OS X 10.9 and all computers running OS X 10.9 support 64 bit so I guess there's no real reason.
When working with PureBasic you'll just have to use the x64 version.
And yes, it it cool :D

Re: Playing with SpriteKit (OS X 10.9 Mavericks, x64)

Posted: Wed Nov 13, 2013 2:26 pm
by J. Baker
wilbert wrote:
J. Baker wrote:This is pretty cool! I just wish Apple would have made it 32bit as well. ;)
SpriteKit requires OS X 10.9 and all computers running OS X 10.9 support 64 bit so I guess there's no real reason.
When working with PureBasic you'll just have to use the x64 version.
And yes, it it cool :D
Yeah, I guess that's the way all operating systems are headed. Looking forward to testing this out more and seeing what all it offers. :D