Hey all. I am trying to decide if I should use MovieClip for animations, or if I should just create my own animation system. I have looked at some MovieClip examples and tutorials but I'm slightly confused and wonder if somebody can answer a question. Is every frame in a MovieClip a separate Bitmap and each of those bitmaps a separate image file?EDIT:
Well here is my Animation Editor. It's purpose is to create animation data for sprites arranged in a grid, inside a TextureAtlas.HOWTO - EDITOR:
To get started quickly, load an atlas (player.png in the images folder should do), load an animation file (player.aaf in the images folder will suffice), and start messing about. Otherwise...1.
Click the "Load" toolbar button in the :TextureAtlas" pane to load an atlas. By default your atlas will be sliced vertically into 64x64 sized regions, which you will see populating the "TextureRegions" pane, ready to be added as frames in your animations. You can change the slice settings at any time and click the "Vertical" or Horizontal" buttons to reslice the atlas.2.
Select an animation from the list in the "Animations" pane. You can rename it and set it's other properties with the controls in the Animation pane.
2a. Click the "Loops" checkbox if you want the animation to loop when complete.
2b. Use the "Speed" slider to adjust playback speed. The formula for animation playback speed is as follows... (1 / number of frames) * playback speed.
2c. Use the "offsetX" and "offsetY" sliders to adjust the frames position. NOTE:
This information is saved but the Animator class currently ignores these values.3.
To add frames to an animation just "DoubleClick" any region in the "TextureRegion" pane and it will be added to the currently selected animations list of frames (in the "Frames" pane).4.
You can use the controls in the "Frames" pane to move the currently selected frame up and down in the list, as well as delete it.
5. In the Playback pane you can test your animations and see if they play how you want. You can use the toolbar buttons to advance/reverse frame by frame, goto first/last frames, and play/stop playback. NOTE:
Currently all animations loop in the editor.6.
Click the "Save" toolbar button in the "Animations" pane to save your animations. The file will be saved as "yourfilename.aaf" which is just a plain text file containing the region and animation information.7.
Click the "Export" toolbar button in the "Animations" pane to export the animations for use in your game. The file will be exported as "yourfilename.json" which you might guess, is a JSON file containing the region and animation data.HOWTO - GIDEROS:
The included example project has a bunch of buttons that you can click to play different animations, and a bunch of extra code. The most basic example I can come up with is as follows...
require("json") -- FOR OPERATIONS ON JSON DATA
local File = File.new() -- FOR FILE OPERATIONS
local Animator = Animator.new() -- THE ANIMATOR CLASS
local playerAtlas = Texture.new("images/player.png")-- LOAD ATLAS
local player = Actor.new(TextureRegion.new(playerAtlas, 0, 0, 0, 0)) --CREATE PLAYER ACTOR
local playerAnimations = File:loadJSON("images/player.json") -- LOAD ANIMATIONS
Animator:attach(player, playerAnimations) -- ASSIGN ANIMATIONS TO PLAYER
Animator:set(player, "run") - START ANIMATION
local function onEnterFrame(event) -- MAIN PROGRAM LOOP
local timer = os.timer()
local dt = timer - currentTimer
currentTimer = timer
Animator:update(player, dt) -- UPDATE PLAYER ANIMATION
Windows only (tested on Win8.1 64-bit), requires .net Framework 3.5
An animation file can contain only 128 animations.
Each animation can contain 64 animation frames.
I'm sure there are other things I forgot, just ask
14/3/16 - Updated Animator class to skip unnecessary calls to setRegion(). Thanks @keszegh
15/3/16 - Updated Editor and screenshot to fix Sc rollbar in "TextureAtlas" pane that was too short.