Spawning Multiple Images with Gravity and Touch to Change Image ETC!

Try this code;
[lua]–Touch Balloon 2 Function
local function touchBalloon2 (event)
event.target.currentFrame = 2
end

—Spawn Balloon 2
local function spawnBalloon2 (event)
ranX = math.random(40,300)
local balloon2 = sprite.newSprite( spriteSet2 )
balloon2.currentFrame = 1
balloon2.x = math.random(20,300)
balloon2.y = 800
balloon2:addEventListener(“tap”, touchBalloon2)
transition.to(balloon2, {time=4700, y=-50, onComplete = function() balloon2:removeSelf() end})
end
timer.performWithDelay(1000, spawnBalloon2, 5)[/lua]

That’s just for the touch event.

For the spawning, you have two functions for two different balloon types so you would change how fast they spawn by adjusting how fast the timer was.

eg;
timer.performWithDelay(1000, functionName, 10)
and
timer.performWithDelay(500, functionName, 20)

Would see those second balloons spawn twice as often as the first.

Peach :slight_smile: [import]uid: 52491 topic_id: 20660 reply_id: 82886[/import]

Awesome, thank you, the spawn balloon 2 works perfect!

As for the functions, what would I do to the spawn balloon 2 to tell it to react to that function, so that I can group 3 balloons into that function and 3 into the other? Or would i just do…

timer.performWithDelay(1000, functionName, 10)

and make it into…

timer.performWithDelay(1000, spawnballoon2, 10)

Because I want 3 balloons to fall under 1 timer, and 3 balloons to fall under the other.

Is there a way to do this? [import]uid: 118461 topic_id: 20660 reply_id: 82926[/import]

Also, can I add to the touch function for it to update the score/star count? So not only does it change frame, but it also either minuses a point or minuses a star? [import]uid: 118461 topic_id: 20660 reply_id: 82932[/import]

For three balloons you’d want the timer to fire three times, so;

[lua]timer.performWithDelay(1000, spawnballoon2, 3)[/lua]

That would do three balloons. Then you’d do it again for spawnballoon1, or whatnot.

For the points, yes, just add the code to add or subtract a point under where you change what frame is showing.

Peach :slight_smile: [import]uid: 52491 topic_id: 20660 reply_id: 83078[/import]