Skip to content

Actor API

Neer edited this page Nov 18, 2019 · 2 revisions

Actor:init()

An internal function to set internal variables for the actor to some default values!

actor=Actor:switch(newState)

Switchs the current animation for the actor. Stops the previous animation and starts the new animation defined by newState! See also onSwitch

Actor:render(...)

Renders the Actor or more precisely just the current state/animation for the actor! The varargs are basically love.draw parameters starting from x!

b_IsActive=Actor:isActive()

Checks if the current animation of the actor is active or not

actor=Actor:stopAnimation()

Stops the current animation!

actor=Actor:startsAnimation()

Starts the current animation for the actor!

actor=Actor:addAnimation(animName,param)

Adds a new animation animName for the actor defined by param which could either be a image name (an XML must exist in the same path by the name for that to work), or an Animation or a table defining a new animation exactly similar to the one expected in animx.newAnimation!

exportSuccessful=Actor.exportToXML(filename)

Exports the actor (all the animations associated with it) to a single XML file! It must be noted that this may result in buggy behaviour if animations are from different sources so use this only when all the animations belong to the same source/atlas!

For the interface animx.hideWarnings defines whether or not to show warning if something went wrong (like a filename by the same name already exists, etc)!

actor=Actor:onSwitch(fn)

Defines the handler that should be executed whenever an animation is changed/switched! The handler takes in the actor and the previousState as parameters!

animation=Actor:getAnimation(name)

Returns the given or current animation if given arg is nil

animation=Actor:getCurrentAnimation()

Returns the current animation that's being rendered. It does the exact same job as Actor:getAnimation() with no arguments!!

allAnimations=Actor:getStates()

Gets a table of all the states (animations basically). The order is undefined!

actor=Actor:loopAll()

Loops all the animations in the actor. See also animation modes! So you don't have to go through all animations and loop each one individually!

name=Actor:getName()

Returns the name of the current state/animation!

width,height=Actor:getDimensions()

Returns the dimensions of the quad for the current animation! Also see Animation:getDimensions()

width=Actor:getWidth()

Returns the width of the quad for the current animation! Also see Animation:getWidth()

height=Actor:getHeight()

Returns the height of the quad for the current animation! Also see Animation:getHeight()

actor=Actor:setStyle(val)

Sets the style of the image for the current animation! Also see Animation:setStyle()

actor=Actor:flip(x,y)

Flips the current animation along given axes (boolean values). Also see Animation:flip()

actor=Actor:flipX(b)

Flips the current animation along x-axis if b is some truthy value. Also see Animation:flipX()

actor=Actor:flipY(b)

Flips the current animation along y-axis if b is some truthy value. Also see Animation:flipY()

Aliases


There are numerous aliases for the above functions which you can use:-

Actor.getCurrentAnim=Actor.getCurrentAnimation
Actor.getState=Actor.getName
Actor.changeAnim=Actor.switch
Actor.set=Actor.switch
Actor.draw=Actor.render