Hello,
I want to change some static bodys' position,and there are two way.
One is removing the old one , and creating a new body, then adding the new shape.It wastes lots of time in creating bodys and shapes.My Body and Shape's number is fixed(60).
The other way is changing the bodys' position and using cpSpaceRehashStatic(space).
cpSpaceRehashStatic(space) is wasting lots of time.
Can I have other selections?
thanks,
a chinese student.
How to change the static body position?
-
- Posts: 2
- Joined: Thu Nov 03, 2011 1:55 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: How to change the static body position?
You shouldn't move a static body. Static means that it doesn't move or change.
Instead create an infinite mass "rogue" body. cpBodyNew(INFINITY, INFINITY), not cpBodyNewStatic(). Don't call cpSpaceAddBody() because you don't want it to apply gravity. Attach normal shapes using cpSpaceAddShape(), not cpSpaceAddStaticShape(). Then you can move the body whenever you want. When you change the position, remember to change the velocity to match so that the collisions work right.
There is also cpSpaceRehashShape() to move a single static shape, but you don't want to do this every frame.
Instead create an infinite mass "rogue" body. cpBodyNew(INFINITY, INFINITY), not cpBodyNewStatic(). Don't call cpSpaceAddBody() because you don't want it to apply gravity. Attach normal shapes using cpSpaceAddShape(), not cpSpaceAddStaticShape(). Then you can move the body whenever you want. When you change the position, remember to change the velocity to match so that the collisions work right.
There is also cpSpaceRehashShape() to move a single static shape, but you don't want to do this every frame.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 2
- Joined: Thu Nov 03, 2011 1:55 am
- Contact:
Re: How to change the static body position?
Thanks very much.
My game works perfect.
My game works perfect.
Who is online
Users browsing this forum: Bing [Bot], Heise IT-Markt [Crawler] and 9 guests