Help with physics.

Ok so i am trying to get an image to fall from the top, outside of the screen; so like above the screen so you cant see it. And i want it go from there to outside the bottom; so below the screen. And the problem i am having is i cant figure out how to do it, i have searched it, read the resources and i cant figure it out. If someone could link me to a tutorial or help me out with the code i would greatly appreciate it.

oops i accidentally posted another one of these too.

Hey there, here's a basic example;

1
2
3
4
5
6
require ( "physics" )
physics.start()
physics.setGravity( 0, 7.5 )
 
local circle = display.newCircle( 160, -100, 30 )
physics.addBody(circle, "dynamic")

OK thank you for that, but also how would i make it go like randomly and have more than one? Kind of like a snow flake effect type thing.

Yay i seem to have gotten it they way i wanted it by using the code you gave me (thank you) and adding some more and modifying the one you gave me. Here is the code i am using at the moment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local physics = require("physics");
physics.start();
 
require ( "physics" )
physics.start()
physics.setGravity( 0, 7.5 )
 
local function spawnCircle()
        local Circle = display.newCircle( 160, -100, 30 )
        Circle:setReferencePoint(display.TopReferencePoint);
        physics.addBody(Circle, "dynamic")
 
end
 
tmr = timer.performWithDelay(100, spawnCircle, 400);

This is good but you should also make sure you get rid of the objects - otherwise they fall off the screen and keep going ;)

You could put a "floor" below where you can on the screen and then on collision remove the snowflakes.

Peach :)

Yes good suggestion thank you, i was just a few minutes ago when i ran it noticed that they kept going down and made the animation very laggy i will go do that now, thanks.

No worries, Corona for Newbies Part 4 has a tutorial on collision detection if you need it; http://techority.com/2011/06/19/corona-for-newbies-part-4-physics/

Peach :)

views:1566 update:2011/12/31 9:35:10
corona forums © 2003-2011