Hi,
I have a game that i'm optimizing performance on. I'm using the latest chipmunk (5.x) and cocos2d on the iphone. the question has to do with the chipmunk side.
I recycle my sprites. So I have a spriteFactory that makes - let's say - 6 sprites. Upon collision (with a bullet), i've chosen not to destroy the sprites (and associated cpShape/cpBody) so I can use them again without having to remanufacture them.
The technique I use in the collision callback is to simply place the collided sprite offscreen at some point far, far, away. Immediately after that is done, the sprite is reset and gets back onscreen.
So... all's well...
BUT...
I am worried that when i banish a sprite temporarily to that far away point, that chipmunk is still calculating stuff on it. And that is compounded if 2 sprites are banished to overlapping points.
My question is: is there a way I can temporarily disable calaculations on a cpBody/shape and resume the claculation once it's position is reset? that might gain me some frames per second.
thanks
m0by
disable calculations on offscreen cpbody?
-
- Posts: 2
- Joined: Mon Mar 22, 2010 5:31 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: disable calculations on offscreen cpbody?
If you remove the body and collision shapes from the space, then no CPU time will be spent on them.
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: Mon Mar 22, 2010 5:31 pm
- Contact:
Re: disable calculations on offscreen cpbody?
thanks. so do i then re-add body and shape in the standard way (e.g. re-initialize them?)
cheers
cheers
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: disable calculations on offscreen cpbody?
I wouldn't really recommend reusing your objects like that as it can create a lot of headaches. If you really want, you can reinitialize any Chipmunk object by using the 'init' instead of 'new' function.
Example:
Every type that has a 'new' function should also have an 'init' function that takes a pointer to the struct followed by the same parameters that the 'new' function takes.
Example:
Code: Select all
// To create it the first time
cpBody *body = cpBodyNew(mass, moment);
// re-initialize it later
cpBodyInit(body, mass, moment);
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/
Who is online
Users browsing this forum: No registered users and 9 guests