Ok,
I can spawn images easily and move them about using transitions etc but I seem to have hit a small problem
I need to spawn animated sprites in the same manner.
My problem is I would like to use the same method as below which I have been using for other objects.
math.randomseed( os.time() )
local images = {}
images[#images + 1] = "leafs.png"
images[#images + 1] = "leafs1.png"
images[#images + 1] = "leafs2.png"
images[#images + 1] = "leafs3.png"
local function leafSpawn()
local index = math.random( 1, #images )
local leaf = display.newImage( images[index] )
leaf.myName = "leaf"
leaf:addEventListener("collision", leaf)
leaf.x = -100
leaf.y = math.random(20,250)
transition.from(leaf, {time = math.random(2400,4500), delay = 0, x = leaf.x +580, onComplete=function() end})
At the moment I have this, it will spawn a single random dandelion each time, so I guess I need to add a timer function to it in order to spawn a certain number of dandelions like the leafSpawn functions i have above.
Any help would be appreciated .
module(..., package.seeall)
local physics = require "physics"
physics.start()
physics.setGravity(0,0)
--physics.setDrawMode( "hybrid" )
math.randomseed( os.time() )
function new()
local sheet = graphics.newImageSheet( "dandelion.png", { width=44.19, height=45.34, numFrames=99 } )
local dandelion = display.newSprite( sheet, { name="dandelion", start=1, count=99, time=250 } )
local w,h = display.viewableContentWidth, display.viewableContentWidth
dandelion:play()
dandelion.myName = "dandelion"
dandelion:addEventListener("collision", dandelion)
dandelion.x = -100
dandelion.y = math.random(20,250)
transition.from(dandelion, {time = math.random(2400,4500), delay = 0, x = dandelion.x +580, onComplete=function() end})
end
I have been making all my image objects into modules and then importing to main.lua.
[import]uid: 127675 topic_id: 30559 reply_id: 330559[/import]
[import]uid: 116842 topic_id: 30559 reply_id: 122462[/import]
[import]uid: 116842 topic_id: 30559 reply_id: 122609[/import]