I’ve managed to create a struct for UserData, but when I switch from using
ballBodyDef.userData = _ball;
to
MyBodyData *bodyData = new MyBodyData();
bodyData->someNumber = 4;
bodyData->sprite = _ball;
_body->SetUserData(bodyData);
the following fails:
for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) {
{
if (b->GetUserData() != NULL)
{
CCSprite *myActor = (CCSprite*)b->GetUserData();
myActor.position = CGPointMake(
b->GetPosition().x * PTM_RATIO,
b->GetPosition().y * PTM_RATIO );
myActor.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
I’m sure it has to do with the fact that the compiler cannot find/set the position of myActor, but I don’t know how to include/retrieve/set the position of the body using a struct…
You can’t cast
MyBodyData*toCCSprite*. You have to write: