Skip to content

Base API

Neer edited this page Nov 18, 2019 · 4 revisions

animation=animx.newAnimation(imageURL)

Parameters

  • imageURL : The URL of the image for the animation

Returns

Sypnosis

  • Creates a new Animation from metafile! imageURL is the URL of the image and an XML file must exist in the same path by the same name describing the animation in the image!

Note that the XML format for animation is different then what is expected for an Actor! See Examples for more information!

animation=animx.newAnimation(params)

Sypnosis

  • Creates a new Animation from scratch! Doesn't mandate the existence of any XML file like the first overload (documented above)!

Returns

Parameters

  • params : A table of parameters. These parameters can be:-

    • img : The URL of - or the Image itself [MANDATORY]
    • spritesPerRow : The number of sprites per row (automatically calculated if nil)
    • numberOfQuads : The number of frames for the animation. (If nil then sprites'll be extracted 'til the end of the TileSource!)
    • delay=0.1 : The delay between any two frames
    • tileWidth,tileHeight : The dimensions of each tile in the TileSource
    • frames={} - The frames (by number) that u wanna add in the animation
    • quads={} - An already existing table of quads for animation
    • offsetX=0, offsetY=0 : The starting point of the TileSource
    • imgWidth,imgHeight (=img:getDimensions()) : The dimensions of the texture
    • style=nil : The style of the image ('rough' or 'smooth'/nil)
    • startingFrame=1 : The frame from where to start the animation (must exist)
    • startPoint=1 : The frame from where to start ripping the sprites
    • onUpdate : A handler called at every frame regardless of whether the animation is active!
    • onChange : A handler called at every animation frame change
    • onCycleOver : A handler called when one animation cycle is complete
    • onAnimOver : A handler called when the entire animation is complete
    • onAnimStart : A handler called when the entire animation is started
    • onAnimRestart : A handler called when the entire animation is restarted

Notes

The callback functions are empty functions by default and the only mandatory parameter is img! It handles a number of different cases and I couldn't possibly talk about that in this short documentation. So I suggest you check the examples to learn more about them!

Sorry for being lazy here! But the examples are neatly commented and you should have no problem following them. I have done exactly what Linus insists "Talk is cheap! Show me the code"

Aliases for the above parameters

You may not like my naming convention or you may forget some parameter name so I have added number of aliases to make it easy for you!

Image: img, image, texture, atlas, spritesheet, source

Number of Frames: nq, noOfFrames, noOfQuads, numberOfQuads, noOfTiles, images

offsetX: x, offsetX

offsetY: y, offsetY

Sprites Per Row: spr, spritesPerRow, tilesPerRow, quadsPerRow

TileWidth: qw, quadWidth, tileWidth, frameWidth

TileHeight: qh, quadHeight, tileHeight, frameHeight

ImageWidth: sw, imgWidth, textureWidth

ImageHeight: sh, imgHeight, textureHeight

onAnimationStart : onAnimStart, onAnimationStart

onAnimationOver : onAnimOver, onAnimationOver, onAnimEnd, onAnimationEnd

onCycleOver : onCycleOver, onCycleEnd

onAnimationRestart : onAnimRestart, onAnimationRestart

onChange : onChange, onFrameChange

onUpdate : onUpdate, onTick

quads=animx.newAnimationXML(image,metafile)

Parameters

  • image : The URL or the image itself required for the animation
  • metafile : The URL of the XML file describing the animation

Returns

  • An array of quads each index describing each frame in the animation!

Sypnosis

  • Creates an animation from XML! However it returns not an Animation instance but simply a set of quads describing the animation. You'll most of the time call animx.newAnimation() to call this function indirectly

actor=animx.newActor(imageURL)

Parameters

  • imageURL : The URL of the image

Returns

Sypnosis

  • Creates a new Actor from metafile! imageURL is the URL of the image and an XML file must exist in the same path by the same name describing the animation in the image!

Note that the XML format for animation is different then what is expected for an Actor! See Examples for more information!

actor=animx.newActor(animations)

Parameters

  • animations : A table of animations

Returns

Sypnosis

  • Creates a new Actor with given animations which is a table where each element in the array can either be an already-existing Animation instance or a "to-be-created" animation! See Actor:addAnimation() for more details! Also if no table is given then it creates an empty Actor (without any animations)!

animations=animx.newActorXML(image,metafile)

Parameters

  • image : The URL or the image itself which all animations share
  • metafile : The URL of the XML file describing all the animations

Returns

  • An linkhash/hashtable of animations (keyed by the animation names) each of which is an array of quads each index describing each frame in the animation!

Sypnosis

  • Creates an actor from XML! However it returns not an Actor instance but simply a hashtable describing each of those animations each of which in turn is described as a set of quads! You'll most of the time call animx.newActor() to call this function indirectly

animx.update(dt)

Parameters

Sypnosis

  • Automatically updates all Animation instances you create without you manually having to update each of them on your own!

Aliases

There are not many aliases. The only one that is present is:-

animx.newAnimatedSprite=animx.newActor

So that Sodapop users will feel more comfortable!