Game Development Reference
In-Depth Information
case kColorRed:
this->initWithSpriteFrameName("ball_red.png");
break;
case kColorYellow:
this->initWithSpriteFrameName("ball_yellow.png");
break;
case kColorWhite:
this->initWithSpriteFrameName("ball_white.png");
break;
}
_body->CreateFixture(&fixtureDef);
//store the b2Sprite as the body's userData
_body->SetUserData(this);
The friction fixture property involves the reaction of two touching surfaces (two bod-
ies). In this case, we want to create "friction" with the table surface, which is not a body at
all. So what we need to use instead is damping . This will apply a similar effect to friction,
but without the need for an extra surface. Damping can be applied to the linear velocity
vector of a body as follows:
_body->SetLinearDamping(1.2);
And to the angular velocity as follows:
_body->SetAngularDamping(0.2);
Also, the white ball is set to be a bullet:
_body->SetBullet(true);
This will make the simulation pay extra attention to this object in terms of collision. We
could make all balls in the game behave as bullets, but this is not only unnecessary
(something revealed through testing) but also not very processing-friendly.
Search WWH ::




Custom Search