-
Notifications
You must be signed in to change notification settings - Fork 3
Adding Life Through Animation
Nowadays animations are crucial element in game development. Berry support animated tiles by using Corona animation sequences.
First, to build an animation, you need to select tileset by left clicking on button Edit Tileset
located in the bottom right of Tiled and select Tileset >> The Animation Editor. In new window tap tile to which you want attach new animation. Next form sequence of frames by dragging tiles from right to left side of window.
Note: Tiled allows one animation per tile.
To use animation in Corona you need a couple more properties set on your tile or object. First of all, you need add property isAnimated
to object not a tile. It will simply tell Berry that this object should be animated. The rest of properties are the same as specified in display.newSprite
for sequences i.e. time
, name
, loopCount
and loopDirection
. You need add it to a tile.
If you run your game now you will notice something, your animation no longer plays. That is because you must tell Berry to play your animations, giving you more control over them.
Now that you have your sequences set up you are ready to test them in game and just like the Properties tutorial we now need to get access to our animated objects. Then after we have it we can start playing it.
-- We first need to get access to the layer our objects is on, the name is specified in Tiled
local layer = map:getObjectLayer( 'Object Layer 1' )
-- Make sure we actually have a layer
if layer then
-- Get all the objects on this layer
local objects = layer.objects
-- Loop through our objects
for i=1, #objects, 1 do
-- Check if the tile is animated (note the capitalization)
if objects[i].isAnimated then
-- Store off a copy of the object
local object = objects[i]
-- Now finally play it
object.sprite:play()
end
end
end