[Resolved] Help with spawning and animating multiple images

Hey people,

I have spent nearly a week rattling my brain about how to go about my new game. I have finally decided to ask for a bit of assistance.

I’m certain that what i want it to do is possible.

Basically, I’m having many balls pinging around in a box (all with different names like ball1.png/ball10.png…) then when a ball hits an obstacle inside the box it triggers another event.

My first question is:
How would you recommend to spawn the balls, so that they all shoot off in different directions, instead of all going into the same place.

My second question:
Using the physics engine, is it possible to make the bodies retain there speed even if they hit some (a bit like using object:translate())

Umm I think that information would kick start me in the right direction, so any help would be hugely appreciated.

Thanks

Ollie [import]uid: 67534 topic_id: 24853 reply_id: 324853[/import]

For the first part you would apply random force/velocity when they were spawned - this way that would all move in a random direction.

For the second, you could reapply force/velocity or play with bounce settings to help get this working right, it will likely involve some trial and error but it shouldn’t be too hard.

Do you already know how to spawn the balls in a loop so you don’t have to add them one by one? (I ask because I know a lot of people don’t, so no offense if you are already aware of this.)

Peach :slight_smile: [import]uid: 52491 topic_id: 24853 reply_id: 100989[/import]

Hey Peach,

Firstly, thanks for the speedy reply!

I’m fairly new (and young) to Corona, so by loops, do you mean using the “for i = 1, 10 do” thing? I did attempt this however they all spawn at the same time and i found it difficult to apply different forces to them?

If that isn’t the thing you were suggesting, could you possibly point me in the direction of a tutorial? :slight_smile:

Thanks again

Ollie [import]uid: 67534 topic_id: 24853 reply_id: 100992[/import]

That is what I meant, yes. This is very basic but try running it, it might help you to understand how to apply different forces. (I hope so.)

[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 0 )

local ball = {}

for i = 1, 10 do
ball[i] = display.newCircle( 160, 240, 10 )
physics.addBody(ball[i])
ball[i]:setLinearVelocity(math.random(-100,100),math.random(-100,100))
end[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 24853 reply_id: 101174[/import]

Oh I get it now! Thank you very much!

[import]uid: 67534 topic_id: 24853 reply_id: 101283[/import]

No worries, good luck with your project :slight_smile: [import]uid: 52491 topic_id: 24853 reply_id: 101456[/import]