Copyright | [2014] Manuel M T Chakravarty |
---|---|
License | BSD3 |
Maintainer | Manuel M T Chakravarty <chak@justtesting.org> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
Graphics.SpriteKit
Contents
- Basic geometry and similar
- Marshalling functions (internal)
- Color representation
- Colour representation
- Colours in the sRGBA colour space
- Standard colours
- Marshalling support (internal)
- Bit images and textures
- Vector paths
- Core Graphics path representation
- Marshalling functions (internal)
- Nodes and scenes
- Actions animating nodes
- Physics simulation
- User events
- Event information
- Marshalling functions (internal)
- Internal
Description
Cocoa SpriteKit for Haskell
Concepts:
- SpriteKit node trees are represented as conventional algebraic datatypes in Haskell.
- For rendering, Haskell node trees are converted to native
SKNode
trees. For animated scenes, where all animation is driven by Haskell, the conversion of updated scenes works by updating the previousSKNode
tree. - For interactive scenes and scenes using SceneKit's actions or physics, the Haskell scene code gets called with a Haskell
tree representing the current
SKNode
tree, which, after Haskell side processing, is converted to anSKNode
tree again by updating the version that was passed to the Haskell code.
- type TimeInterval = Double
- type GFloat = Double
- data Point = Point {}
- data Size = Size {
- sizeWidth :: !GFloat
- sizeHeight :: !GFloat
- data Rect = Rect {
- rectOrigin :: !Point
- rectSize :: !Size
- data Vector = Vector {}
- pointZero :: Point
- sizeZero :: Size
- rectZero :: Rect
- vectorZero :: Vector
- pointToCGPoint :: Point -> IO CGPoint
- cgPointToPoint :: CGPoint -> IO Point
- sizeToCGSize :: Size -> IO CGSize
- cgSizeToSize :: CGSize -> IO Size
- rectToCGRect :: Rect -> IO CGRect
- cgRectToRect :: CGRect -> IO Rect
- vectorToCGVector :: Vector -> IO CGVector
- cgVectorToVector :: CGVector -> IO Vector
- geometry_initialise :: IO ()
- newtype Color = Color SKColor
- colorWithRGBA :: Float -> Float -> Float -> Float -> Color
- rgbaOfColor :: Color -> Maybe (Float, Float, Float, Float)
- blackColor :: Color
- blueColor :: Color
- clearColor :: Color
- cyanColor :: Color
- darkGrayColor :: Color
- grayColor :: Color
- greenColor :: Color
- lightGrayColor :: Color
- magentaColor :: Color
- orangeColor :: Color
- purpleColor :: Color
- redColor :: Color
- whiteColor :: Color
- yellowColor :: Color
- newtype SKColor = SKColor (ForeignPtr SKColor)
- colorToSKColor :: Color -> SKColor
- colorToForeignPtr :: Color -> IO (ForeignPtr SKColor)
- color_initialise :: IO ()
- data Image
- class IsImage img where
- newtype NSUIImage = NSUIImage (ForeignPtr NSUIImage)
- imageToNSUIImage :: IsImage img => img -> IO NSUIImage
- imageToForeignPtr :: IsImage img => img -> IO (ForeignPtr NSUIImage)
- image_initialise :: IO ()
- newtype Texture = Texture SKTexture
- textureWithImageNamed :: FilePath -> Texture
- textureWithImage :: Image -> Texture
- textureWithRectInTexture :: Rect -> Texture -> Texture
- textureSize :: Texture -> Size
- textureRect :: Texture -> Rect
- newtype SKTexture = SKTexture (ForeignPtr SKTexture)
- textureToSKTexture :: Texture -> SKTexture
- textureToForeignPtr :: Texture -> IO (ForeignPtr SKTexture)
- texture_initialise :: IO ()
- type Path = [PathElement]
- data PathElement
- newtype CGPath = CGPath (ForeignPtr CGPath)
- pathToCGPath :: Path -> IO CGPath
- cgPathToPath :: CGPath -> IO Path
- path_initialise :: IO ()
- data Node u
- = Node {
- nodeName :: Maybe String
- nodePosition :: Point
- nodeZPosition :: GFloat
- nodeXScale :: GFloat
- nodeYScale :: GFloat
- nodeZRotation :: GFloat
- nodeChildren :: [Node u]
- nodeActionDirectives :: [Directive (Node u)]
- nodeSpeed :: GFloat
- nodePaused :: Bool
- nodePhysicsBody :: Maybe PhysicsBody
- nodeUserData :: u
- nodeForeign :: Maybe SKNode
- | Label {
- nodeName :: Maybe String
- nodePosition :: Point
- nodeZPosition :: GFloat
- nodeXScale :: GFloat
- nodeYScale :: GFloat
- nodeZRotation :: GFloat
- nodeChildren :: [Node u]
- nodeActionDirectives :: [Directive (Node u)]
- nodeSpeed :: GFloat
- nodePaused :: Bool
- nodePhysicsBody :: Maybe PhysicsBody
- nodeUserData :: u
- nodeForeign :: Maybe SKNode
- labelText :: String
- labelFontColor :: Color
- labelFontName :: Maybe String
- labelFontSize :: GFloat
- | Shape {
- nodeName :: Maybe String
- nodePosition :: Point
- nodeZPosition :: GFloat
- nodeXScale :: GFloat
- nodeYScale :: GFloat
- nodeZRotation :: GFloat
- nodeChildren :: [Node u]
- nodeActionDirectives :: [Directive (Node u)]
- nodeSpeed :: GFloat
- nodePaused :: Bool
- nodePhysicsBody :: Maybe PhysicsBody
- nodeUserData :: u
- nodeForeign :: Maybe SKNode
- shapePath :: Path
- shapeFillColor :: Color
- shapeLineWidth :: GFloat
- shapeGlowWidth :: GFloat
- shapeAntialiased :: Bool
- shapeStrokeColor :: Color
- | Sprite {
- nodeName :: Maybe String
- nodePosition :: Point
- nodeZPosition :: GFloat
- nodeXScale :: GFloat
- nodeYScale :: GFloat
- nodeZRotation :: GFloat
- nodeChildren :: [Node u]
- nodeActionDirectives :: [Directive (Node u)]
- nodeSpeed :: GFloat
- nodePaused :: Bool
- nodePhysicsBody :: Maybe PhysicsBody
- nodeUserData :: u
- nodeForeign :: Maybe SKNode
- spriteSize :: Size
- spriteAnchorPoint :: Point
- spriteTexture :: Maybe Texture
- spriteColorBlendFactor :: GFloat
- spriteColor :: Color
- = Node {
- data SDirective node children
- = RunAction (SAction node children) (Maybe String)
- | RemoveActionForKey String
- | RemoveAllActions
- type Directive node = SDirective node node
- type TimedUpdate node = node -> GFloat -> node
- node :: [Node userData] -> Node userData
- frame :: Node userData -> IO Rect
- calculateAccumulatedFrame :: Node userData -> IO Rect
- labelNodeWithFontNamed :: String -> Node userData
- labelNodeWithText :: String -> Node userData
- shapeNodeWithPath :: Path -> Node userData
- spriteNodeWithColorSize :: Color -> Size -> Node userData
- spriteNodeWithImageNamed :: FilePath -> Node userData
- spriteNodeWithTexture :: Texture -> Node userData
- spriteNodeWithTextureSize :: Texture -> Size -> Node userData
- spriteNodeWithTextureColorSize :: Texture -> Color -> Size -> Node userData
- spriteWithColorSize :: Color -> Size -> Node userData
- spriteWithImageNamed :: FilePath -> Node userData
- spriteWithTexture :: Texture -> Node userData
- spriteWithTextureSize :: Texture -> Size -> Node userData
- spriteWithTextureColorSize :: Texture -> Color -> Size -> Node userData
- newtype SKNode = SKNode (ForeignPtr SKNode)
- skNodeToNode :: SKNode -> IO (Node userData)
- nodeToSKNode :: Node userData -> IO SKNode
- mergeSKNode :: Node userData -> Node userData -> IO SKNode
- addChildren :: Bool -> SKNode -> [Node userData] -> IO ()
- addActionDirectives :: SKNode -> [SDirective node children] -> IO ()
- unsafeInterleaveNSArrayTolistOfNode :: NSArray SKNode -> IO [Node userData]
- updateChildren :: SKNode -> [Node userData] -> [Node userData] -> IO ()
- nodeToForeignPtr :: Node userData -> IO (ForeignPtr SKNode)
- node_initialise :: IO ()
- data Scene sceneData nodeData = Scene {
- sceneName :: Maybe String
- sceneChildren :: [Node nodeData]
- sceneActionDirectives :: [SDirective (Scene sceneData nodeData) (Node nodeData)]
- sceneSpeed :: GFloat
- sceneData :: sceneData
- scenePaused :: Bool
- sceneAnchorPoint :: Point
- sceneSize :: Size
- sceneScaleMode :: SceneScaleMode
- sceneBackgroundColor :: Color
- sceneUpdate :: Maybe (SceneUpdate sceneData nodeData)
- scenePhysicsWorld :: PhysicsWorld sceneData nodeData
- sceneHandleEvent :: Maybe (EventHandler sceneData)
- type EventHandler userData = Event -> userData -> Maybe userData
- sceneWithSize :: Size -> Scene sceneData nodeData
- sceneToSKNode :: Scene sceneData nodeData -> IO SKNode
- sceneToForeignPtr :: Scene sceneData nodeData -> IO (ForeignPtr SKNode)
- scene_initialise :: IO ()
- runAction :: SAction node children -> SDirective node children
- runActionWithKey :: SAction node children -> String -> SDirective node children
- removeActionForKey :: String -> SDirective node children
- removeAllActions :: SDirective node children
- data SActionSpecification node children
- = MoveBy !Vector
- | MoveTo !Point
- | MoveToX !GFloat
- | MoveToY !GFloat
- | FollowPath Path !Bool !Bool
- | FollowPathSpeed Path !Bool !Bool !GFloat
- | RotateByAngle !GFloat
- | RotateToAngle !GFloat
- | RotateToAngleShortestUnitArc !GFloat !Bool
- | SpeedBy !GFloat
- | SpeedTo !GFloat
- | ScaleBy !GFloat !GFloat
- | ScaleTo !GFloat !GFloat
- | ScaleXTo !GFloat
- | ScaleYTo !GFloat
- | Unhide
- | Hide
- | FadeIn
- | FadeOut
- | FadeAlphaBy !GFloat
- | FadeAlphaTo !GFloat
- | ResizeByWidthHeight !GFloat !GFloat
- | ResizeToHeight !GFloat
- | ResizeToWidth !GFloat
- | ResizeToWidthHeight !GFloat !GFloat
- | SetTexture Texture !Bool
- | AnimateWithTextures [Texture] !TimeInterval !Bool !Bool
- | SetNormalTexture Texture !Bool
- | AnimateWithNormalTextures [Texture] !TimeInterval !Bool !Bool
- | ColorizeWithColor Color !GFloat
- | ColorizeWithColorBlendFactor !GFloat
- | ApplyForceImpulse ForceImpulse
- | ChangeMassTo GFloat
- | ChangeMassBy GFloat
- | PlaySoundFileNamed String !Bool
- | RemoveFromParent
- | RunActionOnChildWithName (Action children) String
- | Group [SAction node children]
- | Sequence [SAction node children]
- | RepeatActionCount (SAction node children) !Int
- | RepeatActionForever (SAction node children)
- | WaitForDuration !TimeInterval
- | CustomAction (TimedUpdate node)
- type ActionSpecification node = SActionSpecification node node
- data SAction node children = Action {}
- type Action node = SAction node node
- data ActionTimingMode
- type ActionTimingFunction = Float -> Float
- action :: SActionSpecification node children -> SAction node children
- moveBy :: Vector -> SAction node children
- moveTo :: Point -> SAction node children
- moveToX :: GFloat -> SAction node children
- moveToY :: GFloat -> SAction node children
- followPath :: Path -> SAction node children
- followPathSpeed :: Path -> GFloat -> SAction node children
- followPathAsOffsetOrientToPath :: Path -> Bool -> Bool -> SAction node children
- followPathAsOffsetOrientToPathSpeed :: Path -> Bool -> Bool -> GFloat -> SAction node children
- rotateByAngle :: GFloat -> SAction node children
- rotateToAngle :: GFloat -> SAction node children
- rotateToAngleShortestUnitArc :: GFloat -> Bool -> SAction node children
- speedBy :: GFloat -> SAction node children
- speedTo :: GFloat -> SAction node children
- scaleBy :: GFloat -> SAction node children
- scaleTo :: GFloat -> SAction node children
- scaleXByY :: GFloat -> GFloat -> SAction node children
- scaleXToX :: GFloat -> GFloat -> SAction node children
- scaleXTo :: GFloat -> SAction node children
- scaleYTo :: GFloat -> SAction node children
- hide :: SAction node children
- unhide :: SAction node children
- fadeIn :: SAction node children
- fadeOut :: SAction node children
- fadeAlphaBy :: GFloat -> SAction node children
- fadeAlphaTo :: GFloat -> SAction node children
- resizeByWidthHeight :: GFloat -> GFloat -> SAction node children
- resizeToHeight :: GFloat -> SAction node children
- resizeToWidth :: GFloat -> SAction node children
- resizeToWidthHeight :: GFloat -> GFloat -> SAction node children
- setTexture :: Texture -> SAction node children
- setTextureResize :: Texture -> Bool -> SAction node children
- setNormalTexture :: Texture -> SAction node children
- setNormalTextureResize :: Texture -> Bool -> SAction node children
- animateWithTexturesTimePerFrame :: [Texture] -> TimeInterval -> SAction node children
- animateWithTextures :: [Texture] -> TimeInterval -> SAction node children
- animateWithTexturesTimePerFrameResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
- animateWithTexturesResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
- animateWithNormalTexturesTimePerFrame :: [Texture] -> TimeInterval -> SAction node children
- animateWithNormalTextures :: [Texture] -> TimeInterval -> SAction node children
- animateWithNormalTexturesTimePerFrameResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
- animateWithNormalTexturesResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
- colorizeWithColorColorBlendFactor :: Color -> GFloat -> SAction node children
- colorizeWithColor :: Color -> GFloat -> SAction node children
- colorizeWithColorBlendFactor :: GFloat -> SAction node children
- applyForce :: Vector -> SAction node children
- applyTorque :: GFloat -> SAction node children
- applyForceAtPoint :: Vector -> Point -> SAction node children
- applyImpulse :: Vector -> SAction node children
- applyAngularImpulse :: GFloat -> SAction node children
- applyImpulseAtPoint :: Vector -> Point -> SAction node children
- changeMassTo :: GFloat -> SAction node children
- changeMassBy :: GFloat -> SAction node children
- playSoundFileNamedWaitForCompletion :: String -> Bool -> SAction node children
- playSoundFileNamed :: String -> Bool -> SAction node children
- removeFromParent :: SAction node children
- runActionOnChildWithName :: Action children -> String -> SAction node children
- group :: [SAction node children] -> SAction node children
- groupActions :: [SAction node children] -> SAction node children
- sequence :: [SAction node children] -> SAction node children
- sequenceActions :: [SAction node children] -> SAction node children
- repeatActionCount :: SAction node children -> Int -> SAction node children
- repeatActionForever :: SAction node children -> SAction node children
- waitForDuration :: SAction node children
- waitForDurationWithRange :: TimeInterval -> SAction node children
- customAction :: TimedUpdate node -> SAction node children
- newtype SKAction = SKAction (ForeignPtr SKAction)
- actionToSKAction :: SAction node children -> IO SKAction
- data TimedUpdateBox node = TimedUpdateBox (TimedUpdate node)
- action_initialise :: IO ()
- data PhysicsWorld sceneData nodeData = PhysicsWorld {
- worldGravity :: Vector
- worldSpeed :: GFloat
- worldContactDidBegin :: Maybe (PhysicsContactHandler sceneData nodeData)
- worldContactDidEnd :: Maybe (PhysicsContactHandler sceneData nodeData)
- data PhysicsContact nodeData = PhysicsContact {
- contactBodyA :: Node nodeData
- contactBodyB :: Node nodeData
- contactPoint :: Point
- contactCollisionImpulse :: GFloat
- contactNormal :: Vector
- type PhysicsContactHandler sceneData nodeData = sceneData -> PhysicsContact nodeData -> (Maybe sceneData, Maybe (Node nodeData), Maybe (Node nodeData))
- physicsWorld :: PhysicsWorld sceneData nodeData
- newtype SKPhysicsWorld = SKPhysicsWorld (ForeignPtr SKPhysicsWorld)
- newtype SKPhysicsContact = SKPhysicsContact (ForeignPtr SKPhysicsContact)
- skPhysicsContactToPhysicsContact :: SKPhysicsContact -> PhysicsContact nodeData
- physicsWorld_initialise :: IO ()
- data PhysicsBody = PhysicsBody {
- bodyAffectedByGravity :: Bool
- bodyAllowsRotation :: Bool
- bodyIsDynamic :: Bool
- bodyMassOrDensity :: MassOrDensity
- bodyFriction :: GFloat
- bodyRestitution :: GFloat
- bodyLinearDamping :: GFloat
- bodyAngularDamping :: GFloat
- bodyForeign :: IO SKPhysicsBody
- bodyCategoryBitMask :: Word32
- bodyCollisionBitMask :: Word32
- bodyContactTestBitMask :: Word32
- bodyUsesPreciseCollisionDetection :: Bool
- bodyForcesAndImpulses :: [ForceImpulse]
- bodyVelocity :: Vector
- bodyAngularVelocity :: GFloat
- bodyIsResting :: Bool
- bodyIsPinned :: Bool
- data MassOrDensity
- data ForceImpulse
- bodyWithCircleOfRadius :: GFloat -> Maybe Point -> PhysicsBody
- bodyWithRectangleOfSize :: Size -> Maybe Point -> PhysicsBody
- bodyOfBodies :: [PhysicsBody] -> PhysicsBody
- bodyWithPolygonFromPath :: Path -> PhysicsBody
- bodyWithTextureSize :: Texture -> Maybe GFloat -> Size -> PhysicsBody
- bodyWithEdgeLoopFromRect :: Rect -> PhysicsBody
- bodyWithEdgeFromPointToPoint :: Point -> Point -> PhysicsBody
- bodyWithEdgeLoopFromPath :: Path -> PhysicsBody
- bodyWithEdgeChainFromPath :: Path -> PhysicsBody
- bodyDensity :: PhysicsBody -> GFloat
- bodyArea :: PhysicsBody -> GFloat
- newtype SKPhysicsBody = SKPhysicsBody (ForeignPtr SKPhysicsBody)
- physicsBodyToSKPhysicsBody :: PhysicsBody -> IO SKPhysicsBody
- skPhysicsBodyToPhysicsBody :: SKPhysicsBody -> PhysicsBody
- physicsBody_initialise :: IO ()
- data Event
- = KeyEvent { }
- | MouseEvent { }
- | EnterExitEvent { }
- | OtherEvent { }
- data KeyEvent
- = KeyDown
- | KeyUp
- | FlagsChanged
- data MouseEvent
- data EnterExitEvent = CursorUpdate
- data OtherEvent = Periodic
- keyEvent :: Point -> Double -> CLong -> String -> String -> Bool -> Word16 -> Event
- mouseEvent :: Point -> Double -> CLong -> Int -> Int -> Int -> Float -> Event
- event_initialise :: IO ()
- spritekit_initialise :: IO ()
Basic geometry and similar
Basic temporal definition
type TimeInterval = Double
Basic geometry definitions
type GFloat
Arguments
= Double | FIXME: need to be set in dependence on the definition of |
data Point
Point in a two-dimensional coordinate system.
data Size
Size of a two-dimensional geometry entity.
Constructors
Size | |
Fields
|
data Rect
Location and size of a rectangle.
Constructors
Rect | |
Fields
|
data Vector
Two-dimensional vector.
vectorZero :: Vector
Marshalling functions (internal)
pointToCGPoint :: Point -> IO CGPoint
cgPointToPoint :: CGPoint -> IO Point
sizeToCGSize :: Size -> IO CGSize
cgSizeToSize :: CGSize -> IO Size
rectToCGRect :: Rect -> IO CGRect
cgRectToRect :: CGRect -> IO Rect
vectorToCGVector :: Vector -> IO CGVector
cgVectorToVector :: CGVector -> IO Vector
geometry_initialise :: IO ()
Color representation
Colour representation
Colours in the sRGBA colour space
colorWithRGBA :: Float -> Float -> Float -> Float -> Color
Create color with the specified red, green, blue, and alpha channel values in the sRGB color space.
rgbaOfColor :: Color -> Maybe (Float, Float, Float, Float)
Extract the red, green, blue, and alpha channel values of a colour in the sRGB colour space.
Returns Nothing
if the color is in a different color space.
Standard colours
blackColor :: Color
clearColor :: Color
greenColor :: Color
orangeColor :: Color
purpleColor :: Color
whiteColor :: Color
yellowColor :: Color
Marshalling support (internal)
newtype SKColor
Constructors
SKColor (ForeignPtr SKColor) |
colorToSKColor :: Color -> SKColor
colorToForeignPtr :: Color -> IO (ForeignPtr SKColor)
color_initialise :: IO ()
Bit images and textures
Images
class IsImage img where
Instances
Marshalling functions (internal)
newtype NSUIImage
Constructors
NSUIImage (ForeignPtr NSUIImage) |
imageToNSUIImage :: IsImage img => img -> IO NSUIImage
imageToForeignPtr :: IsImage img => img -> IO (ForeignPtr NSUIImage)
image_initialise :: IO ()
SpriteKit texture representation
Texture creation
textureWithImageNamed :: FilePath -> Texture
Create a texture from an image in the app bundle (either a file or an image in a texture atlas) or external file.
A placeholder image is used if the specified image cannot be loaded.
In case of a relative name, the look up behaviour varies between a compiled application bundle and running in the interpreter. In case of a compiled application bundle, the standard SpriteKit bundle behaviour applies. In case of executing in the interpreter, we first look for assets relative to the current working directory.
textureWithImage :: Image -> Texture
Create a texture from the given image.
textureWithRectInTexture :: Rect -> Texture -> Texture
Create a texture from a subset of an existing texture.
The original and new texture share the same texture data. In further call to the same function, the rectangle is again specified in terms of the *original* texture.
Texture properties
textureSize :: Texture -> Size
The size of the texture.
textureRect :: Texture -> Rect
The rectangle (in the unit coordinate space) that defines the portion of the texture used to render its image.
The default is (0,0) — (1,1), but it may be different for textures created with textureWithRectInTexture
.
Marshalling support
newtype SKTexture
Constructors
SKTexture (ForeignPtr SKTexture) |
textureToForeignPtr :: Texture -> IO (ForeignPtr SKTexture)
texture_initialise :: IO ()
Vector paths
Core Graphics path representation
type Path = [PathElement]
Description of a graphics path.
data PathElement
Elementary components of a graphics path.
The constructors AddLineToPoint
, AddQuadCurveToPoint
, AddCurveToPoint
may not start a graphics path.
Constructors
MoveToPoint !Point | Starts a new subpath at the given point. |
AddLineToPoint !Point | Adds a line from the current to the given point. |
AddQuadCurveToPoint !Point !Point | Adds a quadratic curve with control and destination point. |
AddCurveToPoint !Point !Point !Point | Adds a cubic curve with two control and one destination point. |
CloseSubpath | Closes and completes the current subpath. FIXME: we might to add field names (esp useful for the quadratic and cubic curves) |
Marshalling functions (internal)
newtype CGPath
Constructors
CGPath (ForeignPtr CGPath) |
pathToCGPath :: Path -> IO CGPath
cgPathToPath :: CGPath -> IO Path
path_initialise :: IO ()
Nodes and scenes
SpriteKit node representation
data Node u
Tree structure of SpriteKit nodes that are used to assemble scenes, parameterised by the type of user data u
.
Constructors
Node | |
Fields
| |
Label | |
Fields
| |
Shape | |
Fields
| |
Sprite | |
Fields
|
data SDirective node children
Specification of changes that should be made to a node's actions (might be a proper node or a scene).
Constructors
RunAction (SAction node children) (Maybe String) | Initiate a new action, possibly named. |
RemoveActionForKey String | Remove a named action. |
RemoveAllActions | Remove all current actions. |
type Directive node = SDirective node node
Directive for a proper node (not including scenes).
type TimedUpdate node = node -> GFloat -> node
Function that computes an updated tree, given the time that elapsed since the start of the current animation.
The result will be ignored if the new node is not derived from the old node — i.e, it must be the same kind of node
and it must preserve the nodeForeign
field.
Generic SpriteKit node functionality
node :: [Node userData] -> Node userData
Create a node that combines multiple child nodes, but doesn't have a visual representation of its own.
frame :: Node userData -> IO Rect
Determine a rectangle in the parent’s coordinate system that contains the node’s content, ignoring the node’s children.
LIMITATION: The current implementation of this function can be quite costly due to superflous marshalling overhead.
calculateAccumulatedFrame :: Node userData -> IO Rect
Calculate a rectangle in the parent’s coordinate system that contains the content of the node and all of its descendants.
Label nodes
labelNodeWithFontNamed :: String -> Node userData
Creates a label node without any text, but using the specified font.
labelNodeWithText :: String -> Node userData
Creates a label node with the given text (set in 32pt Helvetica Neue Ultralight).
Shape nodes
shapeNodeWithPath :: Path -> Node userData
Creates a shape node from a graphics path relative to the nodes origin.
Sprite nodes
spriteNodeWithColorSize :: Color -> Size -> Node userData
Create a coloured sprite of a given size.
spriteNodeWithImageNamed :: FilePath -> Node userData
Create a texture sprite from an image in the app bundle (either a file or an image in a texture atlas).
A placeholder image is used if the image cannot be loaded.
spriteNodeWithTexture :: Texture -> Node userData
Create a textured sprite from an in-memory texture.
spriteNodeWithTextureSize :: Texture -> Size -> Node userData
Create a textured sprite from an in-memory texture, but also set an explicit size (instead of using the texture's size).
spriteNodeWithTextureColorSize :: Texture -> Color -> Size -> Node userData
Create a textured sprite from an in-memory texture, but also set an explicit size (instead of using the texture's size).
NB: To colourise the texture, you also need to set the colorBlendFactor
field of the sprite.
Short forms
spriteWithColorSize :: Color -> Size -> Node userData
Create a coloured sprite of a given size.
spriteWithImageNamed :: FilePath -> Node userData
Create a texture sprite from an image in the app bundle (either a file or an image in a texture atlas).
A placeholder image is used if the image cannot be loaded.
spriteWithTexture :: Texture -> Node userData
Create a textured sprite from an in-memory texture.
spriteWithTextureSize :: Texture -> Size -> Node userData
Create a textured sprite from an in-memory texture, but also set an explicit size (instead of using the texture's size).
spriteWithTextureColorSize :: Texture -> Color -> Size -> Node userData
Create a textured sprite from an in-memory texture, but also set an explicit size (instead of using the texture's size).
NB: To colourise the texture, you also need to set the colorBlendFactor
field of the sprite.
Internal marshalling support
newtype SKNode
Constructors
SKNode (ForeignPtr SKNode) |
skNodeToNode :: SKNode -> IO (Node userData)
nodeToSKNode :: Node userData -> IO SKNode
mergeSKNode :: Node userData -> Node userData -> IO SKNode
addChildren :: Bool -> SKNode -> [Node userData] -> IO ()
addActionDirectives :: SKNode -> [SDirective node children] -> IO ()
unsafeInterleaveNSArrayTolistOfNode :: NSArray SKNode -> IO [Node userData]
updateChildren :: SKNode -> [Node userData] -> [Node userData] -> IO ()
nodeToForeignPtr :: Node userData -> IO (ForeignPtr SKNode)
node_initialise :: IO ()
Scene representation
data Scene sceneData nodeData
SpriteKit scene description.
Constructors
Scene | |
Fields
|
type EventHandler userData = Event -> userData -> Maybe userData
Event handler that given an input event and node data decides whether to handle the event and how to update the node data.
If the handler chooses not to handle the presented event, it returns Nothing
. In this case, the event will be forwarded to
the next item in the responder chain.
Scene creation
sceneWithSize :: Size -> Scene sceneData nodeData
A new scene of the given size.
Marshalling functions (internal)
sceneToSKNode :: Scene sceneData nodeData -> IO SKNode
sceneToForeignPtr :: Scene sceneData nodeData -> IO (ForeignPtr SKNode)
scene_initialise :: IO ()
Actions animating nodes
Action directives
runAction :: SAction node children -> SDirective node children
Initiate a new action.
runActionWithKey :: SAction node children -> String -> SDirective node children
Initiate a new action and give it a name.
If an action with the same name is currently underway on a node that receives this action, the old action is removed first.
removeActionForKey :: String -> SDirective node children
Instructs to remove any action with the give name.
removeAllActions :: SDirective node children
Instructs to remove all actions from any node that receives this directive.
Animation actions
data SActionSpecification node children
Specification of an action that can be applied to a SpriteKit node or scene.
The first type parameter is the type of node on which the action operates. The second is the type of node of its
children. This distinction is required as actions operating on a scene may include RunActionOnChildWithName
actions that will operate on nodes (which are of a different type).
Most actions will be animated over time, given a duration.
Constructors
MoveBy !Vector | Move relative to current position (reversible). |
MoveTo !Point | Move to an absolute position (irreversible). |
MoveToX !GFloat | Move horizontally to an absolute x-position (irreversible). |
MoveToY !GFloat | Move vertically to an absolute y-position (irreversible). |
FollowPath Path !Bool !Bool | Follow path, maybe use relative offsets & maybe orient according to path (reversible). |
FollowPathSpeed Path !Bool !Bool !GFloat | As above, but specifying speed in points per sec (reversible; OS X 10.10+ & iOS 8+). |
RotateByAngle !GFloat | Rotate by a relative value, in radians (reversible). |
RotateToAngle !GFloat | Rotate counterclockwise to an absolute angle, in radians (irreversible). |
RotateToAngleShortestUnitArc !GFloat !Bool | Rotate to an absolute angle. If second argument '== True', in the direction resulting in the smallest rotation; otherwise, interpolated (irreversible). |
SpeedBy !GFloat | Changes how fast the node executes actions by a relative value (reversible). |
SpeedTo !GFloat | Changes how fast the node executes actions to an absolute value (irreversible). |
ScaleBy !GFloat !GFloat | Relative change of x and y scale values (reversible). |
ScaleTo !GFloat !GFloat | Change x and y scale values to an absolute values (irreversible). |
ScaleXTo !GFloat | Change x scale value to an absolute value (irreversible). |
ScaleYTo !GFloat | Change y scale value to an absolute value (irreversible). |
Unhide | Makes a node visible (reversible; instantaneous; OS X 10.10+ & iOS 8+). |
Hide | Hides a node (reversible; instantaneous; OS X 10.10+ & iOS 8+). |
FadeIn | Changes the alpha value to 1.0 (reversible). |
FadeOut | Changes the alpha value to 0.0 (reversible). |
FadeAlphaBy !GFloat | Relative change of the alpha value (reversible). |
FadeAlphaTo !GFloat | Change the alpha value to an absolute value (irreversible). |
ResizeByWidthHeight !GFloat !GFloat | Adjust the size of a sprite (reversible). |
ResizeToHeight !GFloat | Change height of a sprite to an absolute value (irreversible). |
ResizeToWidth !GFloat | Change width of a sprite to an absolute value (irreversible). |
ResizeToWidthHeight !GFloat !GFloat | Change width and height of a sprite to an absolute value (irreversible). |
SetTexture Texture !Bool | Change a sprite's texture, maybe resizing the sprite (irreversible; instantaneous; without resizing only OS X 10.10+ & iOS 7.1+). |
AnimateWithTextures [Texture] !TimeInterval !Bool !Bool | Animate setting the textures, pausing by the given time interval between textures.
If first |
SetNormalTexture Texture !Bool | Change a sprite's normal texture, maybe resizing (irreversible; instantaneous; OS X 10.11+ & iOS 9+). |
AnimateWithNormalTextures [Texture] !TimeInterval !Bool !Bool | Animate normal textures, pausing by the given time interval between textures.
If first |
ColorizeWithColor Color !GFloat | Animate a sprite's color and blend factor (irreversible). |
ColorizeWithColorBlendFactor !GFloat | Animate a sprite's blend factor (irreversible). |
ApplyForceImpulse ForceImpulse | Apply the specified force or impulse to the physics body (reverible). FIXME: not yet implemented: change of charge |
ChangeMassTo GFloat | Change the mass of the node's physics body to the new value (irreversible). |
ChangeMassBy GFloat | Change the mass of the node's physics body by the given value (reversible). FIXME: not yet implemented: physics field strength change and falloff |
PlaySoundFileNamed String !Bool | Play a sound, maybe waiting until the sound finishes playing (irreversible). FIXME: not yet implemented: actions acting on sound nodes |
RemoveFromParent | Removes the animated node from its parent (irreversible; instantaneous). |
RunActionOnChildWithName (Action children) String | Run an action on a named child node (reversible; instantaneous). |
Group [SAction node children] | Run all actions in the group in parallel (reversible). |
Sequence [SAction node children] | Run all actions in the group in sequence (reversible). |
RepeatActionCount (SAction node children) !Int | Repeat an action a fixed number of times (reversible). |
RepeatActionForever (SAction node children) | Repeat an action undefinitely (reversible). |
WaitForDuration !TimeInterval | Waits for the action's duration +/- half the given range value (irreversible). |
CustomAction (TimedUpdate node) | Repeatedly invoke the update function over the action duration (irreversible). |
type ActionSpecification node = SActionSpecification node node
Action specifications on proper nodes have the same type for the node to which the action is attached and its children.
data SAction node children
SpriteKit action.
NB: actionTimingFunction
not yet supported.
Constructors
Action | |
Fields
|
data ActionTimingMode
Determines the temporal progression of an action.
type ActionTimingFunction = Float -> Float
Projects an input value between 0.0 and 1.0, inclusive, to another value between 0.0 and 1.0 to indicate the temporal progression of an action. The input 0.0 must be mapped to 0.0, and 1.0 to 1.0. Inbetween those bounds, the timing function can adjust the timing of the action.
action :: SActionSpecification node children -> SAction node children
Construct an action.
Convenience functions to construct specifications of the same name
followPath :: Path -> SAction node children
followPathSpeed :: Path -> GFloat -> SAction node children
followPathAsOffsetOrientToPath :: Path -> Bool -> Bool -> SAction node children
rotateByAngle :: GFloat -> SAction node children
rotateToAngle :: GFloat -> SAction node children
rotateToAngleShortestUnitArc :: GFloat -> Bool -> SAction node children
fadeAlphaBy :: GFloat -> SAction node children
fadeAlphaTo :: GFloat -> SAction node children
resizeByWidthHeight :: GFloat -> GFloat -> SAction node children
resizeToHeight :: GFloat -> SAction node children
resizeToWidth :: GFloat -> SAction node children
resizeToWidthHeight :: GFloat -> GFloat -> SAction node children
setTexture :: Texture -> SAction node children
setTextureResize :: Texture -> Bool -> SAction node children
setNormalTexture :: Texture -> SAction node children
setNormalTextureResize :: Texture -> Bool -> SAction node children
animateWithTexturesTimePerFrame :: [Texture] -> TimeInterval -> SAction node children
animateWithTextures
is a shorthand for convenience.
animateWithTextures :: [Texture] -> TimeInterval -> SAction node children
animateWithTextures
is a shorthand for convenience.
animateWithTexturesTimePerFrameResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
animateWithTexturesResizeRestore
is a shorthand for convenience.
animateWithTexturesResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
animateWithTexturesResizeRestore
is a shorthand for convenience.
animateWithNormalTexturesTimePerFrame :: [Texture] -> TimeInterval -> SAction node children
animateWithNormalTextures
is a shorthand for convenience.
animateWithNormalTextures :: [Texture] -> TimeInterval -> SAction node children
animateWithNormalTextures
is a shorthand for convenience.
animateWithNormalTexturesTimePerFrameResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
animateWithNormalTexturesResizeRestore
is a shorthand for convenience.
animateWithNormalTexturesResizeRestore :: [Texture] -> TimeInterval -> Bool -> Bool -> SAction node children
animateWithNormalTexturesResizeRestore
is a shorthand for convenience.
colorizeWithColorColorBlendFactor :: Color -> GFloat -> SAction node children
colorizeWithColor
is a shorthand for convenience.
colorizeWithColor :: Color -> GFloat -> SAction node children
colorizeWithColor
is a shorthand for convenience.
colorizeWithColorBlendFactor :: GFloat -> SAction node children
applyForce :: Vector -> SAction node children
applyTorque :: GFloat -> SAction node children
applyForceAtPoint :: Vector -> Point -> SAction node children
applyImpulse :: Vector -> SAction node children
applyAngularImpulse :: GFloat -> SAction node children
applyImpulseAtPoint :: Vector -> Point -> SAction node children
changeMassTo :: GFloat -> SAction node children
changeMassBy :: GFloat -> SAction node children
playSoundFileNamedWaitForCompletion :: String -> Bool -> SAction node children
playSoundFileName
is a shorthand for convenience.
playSoundFileNamed :: String -> Bool -> SAction node children
playSoundFileName
is a shorthand for convenience.
removeFromParent :: SAction node children
runActionOnChildWithName :: Action children -> String -> SAction node children
group :: [SAction node children] -> SAction node children
groupActions
is to be symmetric with sequenceActions
.
groupActions :: [SAction node children] -> SAction node children
groupActions
is to be symmetric with sequenceActions
.
sequence :: [SAction node children] -> SAction node children
sequenceActions
is for convenience in the face of sequence
.
sequenceActions :: [SAction node children] -> SAction node children
sequenceActions
is for convenience in the face of sequence
.
repeatActionCount :: SAction node children -> Int -> SAction node children
repeatActionForever :: SAction node children -> SAction node children
waitForDuration :: SAction node children
waitForDurationWithRange :: TimeInterval -> SAction node children
customAction :: TimedUpdate node -> SAction node children
Perform the given update function once per frame for the given duration. If the duration is 0, the function is only invoked once.
The node on which the action is run is passed to the update function and gets replaced by the updated node.
FIXME: We need to document the tree merging algorithm.
Marshalling support (internal)
newtype SKAction
Constructors
SKAction (ForeignPtr SKAction) |
actionToSKAction :: SAction node children -> IO SKAction
data TimedUpdateBox node
Constructors
TimedUpdateBox (TimedUpdate node) |
action_initialise :: IO ()
Physics simulation
Representation of a physics simulation for one scene
data PhysicsWorld sceneData nodeData
SpriteKit physics world.
Constructors
PhysicsWorld | |
Fields
|
data PhysicsContact nodeData
Information that chracterises the nature of a given contact between two physics bodies.
Constructors
PhysicsContact | |
Fields
|
type PhysicsContactHandler sceneData nodeData
Arguments
= sceneData | Current scene data |
-> PhysicsContact nodeData | Contact information |
-> (Maybe sceneData, Maybe (Node nodeData), Maybe (Node nodeData)) |
The function invoked when contact between two physics bodies either begins or ends.
This handler function gets access to the current scene user data as well as the two nodes associated with the contacting physics bodies. It can modify the scene user data and/or these two nodes to affect any changes that need to be made to the scene due to the beginning or ending of the contact. Only modified data needs to be returned.
physicsWorld :: PhysicsWorld sceneData nodeData
Marshalling functions (internal)
newtype SKPhysicsWorld
Constructors
SKPhysicsWorld (ForeignPtr SKPhysicsWorld) |
newtype SKPhysicsContact
Constructors
SKPhysicsContact (ForeignPtr SKPhysicsContact) |
skPhysicsContactToPhysicsContact :: SKPhysicsContact -> PhysicsContact nodeData
physicsWorld_initialise :: IO ()
Representation of the physics properties of a node
data PhysicsBody
Physics bodies are used to add physics simulation to a node.
Constructors
PhysicsBody | |
Fields
|
data MassOrDensity
How strongly a body is affected by gravity is determined either by giving its mass or by giving its density, in turn determines its mass in combination with the body's area.
Instances
data ForceImpulse
Constructors
ApplyForce Vector (Maybe Point) | Applies a force to a specific point or center of gravity of a body |
ApplyTorque GFloat | Applies an angular acceleration to a pysics body |
ApplyImpulse Vector (Maybe Point) | Applies an impulse to a specific point or center of gravity of a body |
ApplyAngularImpulse GFloat | Applies an impulse that imparts angular momentum |
Creation of volume-based physics bodies
Arguments
:: GFloat | Radius of the circle volume |
-> Maybe Point | Optional center (default: centered on owning node’s origin) |
-> PhysicsBody |
Creates a circular physics body.
Arguments
:: Size | Size of the rectangle volume |
-> Maybe Point | Optional center (default: centered on owning node’s origin) |
-> PhysicsBody |
Creates a rectangular physics body.
Arguments
:: [PhysicsBody] | Component bodies |
-> PhysicsBody |
Creates a physics body by performing a union of a group of volume-based physics bodies.
NB: The argument list may not contain a body constructed by this very function.
Arguments
:: Path | Convex polygonal path with counterclockwise winding & no self intersections |
-> PhysicsBody |
Creates a polygon-shaped physics body.
The points are specified relative to the owning node’s origin.
Arguments
:: Texture | Texture to convert into a physics body |
-> Maybe GFloat | Optional alpha threshold (default: 0) |
-> Size | Size of the physics body to return |
-> PhysicsBody |
Creates a physics body from the contents of a texture.
The texels in the texture whose alpha values equal or exceed the given alpha threshold are included in the physics body.
Creation of edge-based physics bodies
Arguments
:: Rect | Rectangle that defines the edges |
-> PhysicsBody |
Creates an edge loop from a rectangle.
The rectangle is specified relative to the owning node’s origin.
Arguments
:: Point | Starting point for the edge |
-> Point | Ending point for the edge |
-> PhysicsBody |
Creates an edge between two points.
The points are specified relative to the owning node’s origin.
Arguments
:: Path | Path without self intersections |
-> PhysicsBody |
Arguments
:: Path | Path without self intersections |
-> PhysicsBody |
Physics body queries
bodyDensity :: PhysicsBody -> GFloat
Determine a physics body's density. (Marshalling will by default provide the body mass.)
bodyArea :: PhysicsBody -> GFloat
Determine the area covered by a physics body.
Marshalling functions (internal)
newtype SKPhysicsBody
Constructors
SKPhysicsBody (ForeignPtr SKPhysicsBody) |
physicsBody_initialise :: IO ()
User events
Event information
data Event
Cocoa events.
NB: Not all event types are supported. Usually, because they would require functionality from other parts of Cocoa, which are not supported here (yet).
Constructors
KeyEvent | |
Fields
| |
MouseEvent | |
Fields
| |
EnterExitEvent | |
Fields
| |
OtherEvent | |
Fields
|
data KeyEvent
Constructors
KeyDown | |
KeyUp | |
FlagsChanged |
data MouseEvent
Constructors
LeftMouseDown | |
LeftMouseUp | |
LeftMouseDragged | |
RightMouseDown | |
RightMouseUp | |
RightMouseDragged | |
OtherMouseDown | |
OtherMouseUp | |
OtherMouseDragged | |
MouseMoved |
Instances
Marshalling functions (internal)
event_initialise :: IO ()
Internal
spritekit_initialise :: IO ()