This post was originally published at Introducing the new Animation Plugin

Corona Labs is pleased to announce the immediate availability of a new plugin: Animations. This plugin was originally planned to be an extension to the existing transition.* library. During the design, there were sufficient changes that warranted it being a new library. We also decided to make this a plugin instead of a core feature to help keep the core lightweight.

The plugin is broken into two main categories: tweens and timelines. Tweens are your standard transitions like moving an object over time, fading an object in and out, etc. Tweens have new features including scalable speeds and additional events. Timelines allow you to have more control over what happens to a tween over time. You can set timeline markers that you can advance or return to. You can have events fire when the timeline passes a marker.

Since it’s a plugin, you will need to go to the Corona Marketplace and activate it.

Next you will need to include it in your build.settings:

plugins = 
        ["plugin.animation"] =
        
            publisherId = "com.coronalabs"
        ,
    },

And require the plugin in modules where you will use it:

local animation = require("plugins.animation")

For normal transitions, the call is now:

local myAnimation = animation.to( object,  x = 200, alpha = 0 ,  time = 1000, onComplete = whenDoneFunction  )

Notice there are two tables involved, the first table is for object parameters, the second one for transition parameters.

For timelines, you can now program animations that can contain multiple sequential and/or overlapping tweens, each performing unique tweens on one or multiple objects. Additionally, you can set time markers anywhere across the span of the timeline as jump-to points. For example, you could:

local function timelineListener( obj )
    print( "Timeline completed; ID: " .. obj.id )
end
 
-- Create a timeline object
local timelineParams = 
    tweens = 
         startTime=0, tween= object1,  x=display.contentWidth-50 ,  time=4000, iterations=5, reflect=true  } },
         startTime=1000, tween= object1,  y=400 ,  time=4000, easing=easing.outQuad  } }
    },
    markers = 
         name="marker_start", time=0 ,
         name="marker_2000", time=2000 
    },
    id = "timeline1",
    onComplete = timelineListener
}
local newTimeline = animation.newTimeline( timelineParams )

Which will do a transition that moves an object back and forth on the X axis five times over four seconds. Then starting one second in, move the object down the screen over four seconds and setting markers to allow you to go back to the beginning of the timeline or jump to two seconds in.

The animation plugin is free to use. You can learn more about the plugin and its new features by reading the documentation for the plugin. Like many of our other Lua based libraries, we are going to go ahead and make this open source so you can download the source code and make your own changes to the library.

Let us know what you think about this new great addition to Corona in our Community Forums.

View article:  

This post was originally published at Introducing the new Animation Plugin