Multiple Animation Instances

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Cryonics
Prole
Posts: 2
Joined: Thu Nov 26, 2009 12:10 pm

Multiple Animation Instances

Post by Cryonics »

I want to spawn/de-spawn several animated objects on screen with random interval.

Code: Select all

MyObjects = love.graphics.newAnimation(Object_img, 32, 32, 1)
And then draw, would make the animations sync.

My initial idea was that I could use something like:
Myobject .. Var = love.graphics.newAnimation(Object_img, 32, 32, 1)

It looks to me that unless LUA/LÖVE are capable of generic naming of objects, one would have to use the following:

Code: Select all

MyObject1 = love.graphics.newAnimation(Object_img, 32, 32, 1)
MyObject2 = love.graphics.newAnimation(Object_img, 32, 32, 1)
MyObject3 = love.graphics.newAnimation(Object_img, 32, 32, 1)
etc
Problem with this is that 1) limited by how many objects you predefine 2) it's not very efficient/practical
Sure if I only had to make <10 objects it would be manageable, but lets say I wanted more.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiple Animation Instances

Post by Robin »

For this we would use a table:

Code: Select all

MyObjects = {}
table.insert(MyObjects, love.graphics.newAnimation(Object_img, 32, 32, 1))
table.insert(MyObjects, love.graphics.newAnimation(Object_img, 32, 32, 1))
table.insert(MyObjects, love.graphics.newAnimation(Object_img, 32, 32, 1))
table.insert(MyObjects, love.graphics.newAnimation(Object_img, 32, 32, 1))
Then all animations are accessible via []:

Code: Select all

MyObjects[1] -- the first
MyObjects[2] -- the second
index = 47
MyObjects[index] -- the 47th
Help us help you: attach a .love.
Cryonics
Prole
Posts: 2
Joined: Thu Nov 26, 2009 12:10 pm

Re: Multiple Animation Instances

Post by Cryonics »

Makes sense, thanks a lot :)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests