本文整理汇总了C++中AnimatedSprite::setBody方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedSprite::setBody方法的具体用法?C++ AnimatedSprite::setBody怎么用?C++ AnimatedSprite::setBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnimatedSprite
的用法示例。
在下文中一共展示了AnimatedSprite::setBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
/*
This is where all game physics starts each frame. It is called each frame
by the game statem manager after player input and AI have been processed. It
updates the physical state of all dynamic objects in the game and
moves all objects to their end of frame positions, updates all necessary
object velocities, and calls all collision event handlers.
*/
void Physics::update(Game *game)
{
GameStateManager *gsm = game->getGSM();
SpriteManager *spm = gsm->getSpriteManager();
AnimatedSprite *player = spm->getPlayer();
if (once == 0) {
/* b2PolygonShape groundBox;
groundBox.SetAsBox(50.0f, 10.0f);
groundBody->CreateFixture(&groundBox, 0.0f);
*/
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(600, 9280);
body = world->CreateBody(&bodyDef);
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(32.0f, 32.0f);
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
// Set the box density to be non-zero, so it will be dynamic.
fixtureDef.density = 1.0f;
// Override the default friction.
fixtureDef.friction = 0.3f;
// Add the shape to the body.
body->CreateFixture(&fixtureDef);
//body->SetLinearVelocity(b2Vec2(0,-1000));
//body->SetUserData(player);
player->setBody(body);
// This is our little game loop.
once += 1;
}
body->ApplyForce( world->GetGravity(), body->GetWorldCenter(), true );
float32 timeStep = 1.0f / 60.0f;
int32 velocityIterations = 6;
int32 positionIterations = 2;
world->Step(timeStep, velocityIterations, positionIterations);
// Now print the position and angle of the body.
b2Vec2 position = body->GetPosition();
//b2Vec2 position2 = body2->GetPosition();
float32 angle = body->GetAngle();
printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
if (f == 0) {
World *woorld = gsm->getWorld();
vector<WorldLayer*> *layers = woorld->getLayers();
CollidableObject *sprite = NULL;
for (int i = 0; i < woorld->getNumLayers(); i++)
{
WorldLayer *layer = layers->at(i);
if (layer->hasCollidableTiles())
{
layer->findTileCollisionsForSprite(this,sprite);
}
}
f++;
}
if (player->getinvincible() == true) {
if (invincibletimer == 0) {
invincibletimer = 100;
}
invincibletimer -= 1;
if (invincibletimer == 0) {
player->setinvincible(false);
}
}
if (z!=0)z--;
if (z==0)
if (player->getinvincible() == false)
for (b2ContactEdge* edge = body->GetContactList(); edge; edge = edge->next)
//.........这里部分代码省略.........