Class peachy

A parser/renderer for Aseprite animations in LÖVE.

Methods

peachy:new (dataFile, imageData, initialTag) Creates a new Peachy animation object.
peachy:setTag (tag) Switch to a different animation tag.
peachy:setFrame (frame) Jump to a particular frame index (1-based indexes) in the current animation.
peachy:draw (x, y, rot, sx, sy, ox, oy) Draw the animation's current frame in a specified location.
peachy:update (dt) Update the animation.
peachy:nextFrame () Move to the next frame.
peachy:call_onLoop () Check for callbacks
peachy:pause () Pauses the animation.
peachy:play () Unpauses the animation.
peachy:stop (onLast) Stops the animation (pause it then return to first frame or last if specified)
peachy:onLoop (fn, ...) Adds a callback function that will be called when the animation loops
peachy:togglePlay () Toggle between playing/paused.
peachy:getWidth () Provides width stored in the metadata of a current frame
peachy:getHeight () Provides height stored in the metadata of a current frame
peachy:_pingpongBounce () Internal: handles the ping-pong animation type.
peachy:_initializeFrames () Internal: loads all of the frames

Loads quads and frame duration data from the JSON.

peachy:_initializeTags () Internal: loads all of the animation tags
peachy:_checkImageSize () Internal: checks that the loaded image size matches the metadata


Methods

peachy:new (dataFile, imageData, initialTag)
Creates a new Peachy animation object.

If imageData isn't specified then Peachy will attempt to load it using the filename from the JSON data.

If no initial tag is set then the object will be paused (i.e. not displayed) with no tag. The animation will start playing immediately once created.

Parameters:

  • dataFile string a path to an Aseprite JSON file. It is also possible to pass a predecoded table, which is useful for performance when creating large amounts of the same animation.
  • imageData Image a LÖVE image to animate.
  • initialTag string the name of the animation tag to use initially.

Returns:

    the new Peachy object.

Usage:

    -- Load the image ourselves and set animation tag to "Spin".
    -- Will start playing immediately.
    spinner = peachy.new("spinner.json", love.graphics.newImage("spinner.png"), "Spin")
peachy:setTag (tag)
Switch to a different animation tag. In the case that we're attempting to switch to the animation currently playing, nothing will happen.

Parameters:

  • tag string the animation tag name to switch to.
peachy:setFrame (frame)
Jump to a particular frame index (1-based indexes) in the current animation.

Errors if the frame is outside the tag's frame range.

Parameters:

  • frame number the frame index to jump to.

Usage:

    -- Go to the 4th frame
    sound:setFrame(4)
peachy:draw (x, y, rot, sx, sy, ox, oy)
Draw the animation's current frame in a specified location.

Parameters:

  • x number the x position.
  • y number the y position.
  • rot number the rotation to draw at.
  • sx number the x scaling.
  • sy number the y scaling.
  • ox number the origin offset x.
  • oy number the origin offset y.
peachy:update (dt)
Update the animation.

Parameters:

  • dt number frame delta. Should be called from love.update and given the dt.
peachy:nextFrame ()
Move to the next frame. Internal: unless you want to skip frames, this generally will not ever need to be called manually.
peachy:call_onLoop ()
Check for callbacks
peachy:pause ()
Pauses the animation.
peachy:play ()
Unpauses the animation.
peachy:stop (onLast)
Stops the animation (pause it then return to first frame or last if specified)

Parameters:

  • onLast
peachy:onLoop (fn, ...)
Adds a callback function that will be called when the animation loops

Parameters:

  • fn
  • ...
peachy:togglePlay ()
Toggle between playing/paused.
peachy:getWidth ()
Provides width stored in the metadata of a current frame
peachy:getHeight ()
Provides height stored in the metadata of a current frame
peachy:_pingpongBounce ()
Internal: handles the ping-pong animation type.

Should only be called when we actually want to bounce. Swaps the direction.

peachy:_initializeFrames ()
Internal: loads all of the frames

Loads quads and frame duration data from the JSON.

Called from peachy.new

peachy:_initializeTags ()
Internal: loads all of the animation tags Called from peachy.new
peachy:_checkImageSize ()
Internal: checks that the loaded image size matches the metadata Called from peachy.new
generated by LDoc 1.4.6 Last updated 2018-07-20 22:05:46