animate-0.3.0: Animation for sprites

Safe HaskellNone
LanguageHaskell2010

Animate

Synopsis

Documentation

type Seconds = Float Source #

Avoided newtype wrapper for convenience

type DeltaSeconds = Seconds Source #

Type aliased seconds

type Color = (Word8, Word8, Word8) Source #

Alias for RGB (8bit, 8bit, 8bit)

data Frame loc Source #

Constructors

Frame loc Seconds 

Instances

Eq loc => Eq (Frame loc) Source # 

Methods

(==) :: Frame loc -> Frame loc -> Bool #

(/=) :: Frame loc -> Frame loc -> Bool #

Show loc => Show (Frame loc) Source # 

Methods

showsPrec :: Int -> Frame loc -> ShowS #

show :: Frame loc -> String #

showList :: [Frame loc] -> ShowS #

data Animations key loc Source #

Type safe animation set. Use an sum type with an Enum and Bounded instance for the animation, a.

Instances

Eq loc => Eq (Animations key loc) Source # 

Methods

(==) :: Animations key loc -> Animations key loc -> Bool #

(/=) :: Animations key loc -> Animations key loc -> Bool #

Show loc => Show (Animations key loc) Source # 

Methods

showsPrec :: Int -> Animations key loc -> ShowS #

show :: Animations key loc -> String #

showList :: [Animations key loc] -> ShowS #

data Loop Source #

Constructors

Loop'Always

Never stop looping. Animation can never be completed.

Loop'Count Int

Count down loops to below zero. 0 = no loop. 1 = one loop. 2 = two loops. etc.

Instances

Eq Loop Source # 

Methods

(==) :: Loop -> Loop -> Bool #

(/=) :: Loop -> Loop -> Bool #

Show Loop Source # 

Methods

showsPrec :: Int -> Loop -> ShowS #

show :: Loop -> String #

showList :: [Loop] -> ShowS #

data Position key Source #

State for progression through an animation | `example = Position minBound 0 0 LoopAlways

Constructors

Position key FrameIndex Seconds Loop 

Instances

Eq key => Eq (Position key) Source # 

Methods

(==) :: Position key -> Position key -> Bool #

(/=) :: Position key -> Position key -> Bool #

Show key => Show (Position key) Source # 

Methods

showsPrec :: Int -> Position key -> ShowS #

show :: Position key -> String #

showList :: [Position key] -> ShowS #

data FrameStep Source #

You can ignore. An intermediate type for stepPosition to judge how to increment the current frame.

Constructors

FrameStep'Counter Seconds

New counter to compare against the frame's delay.

FrameStep'Delta DeltaSeconds

How much delta to carry over into the next frame.

class (Ord key, Bounded key, Enum key) => Key key Source #

Sematically for an animation key constraint

class Key key => KeyName key where Source #

Animation Keyframe. keyName is used for JSON parsing.

Minimal complete definition

keyName

Methods

keyName :: key -> Text Source #

data SpriteSheet key img Source #

Generalized sprite sheet data structure

Constructors

SpriteSheet (Animations key SpriteClip) img 

animations :: Key key => (key -> [Frame loc]) -> Animations key loc Source #

Generate animations given each constructor

framesByAnimation :: Key key => Animations key loc -> key -> Vector (Frame loc) Source #

Lookup the frames of an animation

initPosition :: Key key => key -> Position key Source #

New Position with its animation key to loop forever

initPositionLoops :: Key key => key -> Int -> Position key Source #

New Position with its animation key with a limited loop

stepFrame :: Frame loc -> Position key -> DeltaSeconds -> FrameStep Source #

Intermediate function for how a frame should be step through.

stepPosition :: Key key => Animations key loc -> Position key -> DeltaSeconds -> Position key Source #

Step through the animation resulting a new position.

isAnimationComplete :: Key key => Animations key loc -> Position key -> Bool Source #

The animation has finished all its frames. Useful for signalling into switching to another animation. With a Loop'Always, the animation will never be completed.

positionHasLooped Source #

Arguments

:: Position key

Previous

-> Position key

Next

-> Bool 

Simple function diff'ing the position for loop change

currentFrame :: Key key => Animations key loc -> Position key -> Frame loc Source #

Use the position to find the current frame of the animation.

currentLocation :: Key key => Animations key loc -> Position key -> loc Source #

Use the position to find the current location, lik a sprite sheet clip, of the animation.

nextKey :: Key key => key -> key Source #

Cycle through the next animation key

prevKey :: Key key => key -> key Source #

Cycle through the previous animation key

readSpriteSheetInfoJSON Source #

Arguments

:: FilePath

Path of the sprite sheet info JSON file

-> IO SpriteSheetInfo 

Quick function for loading SpriteSheetInfo. | Check the example.

readSpriteSheetJSON Source #

Arguments

:: KeyName key 
=> (FilePath -> Maybe Color -> IO img)

Inject animage loading function

-> FilePath

Path of the sprite sheet info JSON file

-> IO (SpriteSheet key img) 

Quick function for loading SpriteSheetInfo, then using it to load its image for a SpriteSheet | Check the example.