Ive been adding my sprites to an array and tagging them, and then attaching them to chipmunk bodys. Is there anyway of getting the body they are attached too?
Thanks Dave
A fast, easy to use, free, and community supported 2D game engine
Ive been adding my sprites to an array and tagging them, and then attaching them to chipmunk bodys. Is there anyway of getting the body they are attached too?
Thanks Dave
I ran into a similar issue a couple days ago. You can subclass Sprite, and add a cpBody* instance variable.
Example:
@interface PhysicsSprite : Sprite {
cpBody* body;
}
@property(nonattomic, assign) cpBody* body;
@end
@implementation PhysicsSprite
@sythesize body;
@end
Now instead of Sprite, use PhysicsSprite for your sprites and you can add references to the body with something like mysprite.body = thecpbody;
- kalx
I think from cocos2D v0.8.1 you have userData property for all CocosNode objects. So you don't have to subclass sprite. Just use
yourSprite.userData = someBody;
userData is an object property? or some sort of pointer reference?
I still think subclassing is better 'cause it's way easier and more organized, you have more control over your classes and you could isolates bugs and problems in code.
Subclassing also keeps code cleaner so you GameLayer or ActionLayer has way less code and you don't have to dig in it to find something...
Cool thanks guys, will have another go when i get back from work...
You must log in to post.