Encapsulating the CCSprite and Box2D classes in an 'Actor'

Hello,

I am new to Cocos2D-x and have been putting in some thought about the best way to design an Actor class that will encapsulate the CCSprite and a b2Body for my Box2D physics game. Is it better to extend the CCObject, CCSprite or neither and just create a ‘Wrapper’ class for the two? So far, I’ve stuck with creating a wrapper to hold both of the objects.
Here is my abstract, and I’d love to see what other people think/have come up with!

`enum BodyType {
Box,
Circle
};

class Actor {
b2Body* body;
CCSprite* sprite;
b2World* world;
BodyType* type;
public:
static Actor* create(b2World* w, CCSprite* s, BodyType type);
static Actor* create(b2World* w, CCSprite* s);
static Actor* create(b2World* w, string image, BodyType type);
static Actor* create(b2World* w, string image);

Actor(b2World* w, CCSprite* s);
Actor(b2World* w, string image);
~Actor();

void update(); //update CCSprite's position and rotation and set it to body's

};`

Thanks,
Nick

I think the simpliest way for cocos2d-x and box2d is to inherit CCNode (or CCSprite or whatever you need to draw you game object) and incapsulate pointer to b2Body. update(ccTime) needs to be overriden (or a custom method scheduled) to sync b2Body’s movements to CCNode.

OK, so I’ve overriden update(CCTime) and it doesn’t appear as though it is being called. I also tried update(float dt) but neither of them are being automatically called.
Is there a certain method that I can override which will automatically be called by cocos2d-x or do I need to specifically loop over all of my Actors and call each individual update method inside my CCLayer’s update method?
In other words, is there a loop where CCLayer automatically calls its children’s updates or do I need to create that loop myself?
I’m trying to avoid having unnecessary loops and condensing potentially two loops into one.

You need to call scheduleUpdate on your node to get update(dt) called every game loop iteration.