--- Animation states using a spritesheet/imagetable. Ideal for use with `NobleSprite` objects. Suitable for other uses as well.
-- @module Noble.Animation
--
Noble.Animation={}
--- Setup
-- @section setup
--- Create a new animation "state machine". This function is called automatically when creating a new `NobleSprite`.
-- @string __view This can be: the path to a spritesheet image file or an image table object (`Graphics.imagetable`). See Playdate SDK docs for imagetable file naming conventions.
-- @return `animation`, a new animation object.
-- @usage
-- local myHero = MyHero("path/to/spritesheet")
-- @usage
-- -- When extending NobleSprite (recommended), you don't call Noble.Animation.new(),
-- -- but you do feed its __view argument into MySprite.super.init()...
-- MyHero = {}
-- class("MyHero").extends(NobleSprite)
--
-- function MyHero:init()
-- MyHero.super.init(self, "assets/images/Hero")
-- -- ...
-- -- A new NobleSprite creates a Noble.Animation object named "self.animation"
-- The current count of frame durations. This is used to determine when to advance to the next frame.
animation.frameDurationCount=1
-- The previous number of frame durations in the animation
animation.previousFrameDurationCount=1
localempty=true
--- Setup
-- @section setup
--- Add an animation state. The first state added will be the default set for this animation.
--
-- <strong>NOTE:</strong> Added states are first-degree member objects of your Noble.Animation object, so do not use names of already existing methods/properties ("current", "draw", etc.).
-- @string __name The name of the animation, this is also used as the key for the animation.
-- @int __startFrame This is the first frame of this animation in the imagetable/spritesheet
-- @int __endFrame This is the final frame of this animation in the imagetable/spritesheet
-- @string[optional] __next By default, animation states will loop, but if you want to sequence an animation, enter the name of the next state here.
-- @bool[opt=true] __loop If you want a state to "freeze" on its final frame, instead of looping, enter `false` here.
-- @param[optional] __onComplete This function will run when this animation is complete. Be careful when using this on a looping animation!
-- @int[opt=1] __frameDuration This is the number of ticks between each frame in this animation. If not specified, it will be set to 1.
-- @usage
-- -- You can reference an animation's state's properties using bog-standard lua syntax:
-- Set this animation state as default if it is the first one added.
if(empty==true)then
empty=false
self.currentFrame=__startFrame
self.current=self[__name]
self.currentName=__name
self.frameDuration=frameDuration
end
end
--- Methods
-- @section methods
--- Sets the current animation state. This can be run in a object's `update` method because it only changes the animation state if the new state is different from the current one.
-- @tparam string|Noble.Animation __animationState The name of the animation to set. You can pass the name of the state, or the object itself.
-- @bool[opt=false] __continuous Set to true if your new state's frames line up with the previous one's, i.e.: two walk cycles but one is wearing a cute hat!
-- @tparam string|Noble.Animation __unlessThisState If this state is the current state, do not set the new one.
-- When attached to a NobleSprite, this is called by `NobleSprite:draw()` when added to a scene. For non-NobleSprite sprites, put this method inside your sprite's `draw()` method, or inside @{NobleScene:update|NobleScene:update}.
-- @number[opt=0] __x
-- @number[opt=0] __y
-- @bool[opt=true] __advance Advances to the next frame after drawing this one. Noble.Animation is frame-based, not "delta time"-based, so its speed is dependent on your game's framerate.
--- Sometimes, you just want to draw a specific frame.
-- Use this for objects or sprites that you want to control outside of update loops, such as score counters, flipbook-style objects that respond to player input, etc.
-- @int __frameNumber The frame to draw from the current state. This is not an imagetable index. Entering `1` will draw the selected state's `startFrame`.
-- @string[opt=self.currentName] __stateName The specific state to pull the __frameNumber from.
-- @number[opt=0] __x
-- @number[opt=0] __y
-- @param[opt=self.direction] __direction Override the current direction.