本文整理汇总了C++中Sprite::AddClip方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::AddClip方法的具体用法?C++ Sprite::AddClip怎么用?C++ Sprite::AddClip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprite
的用法示例。
在下文中一共展示了Sprite::AddClip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FireProjectile
void MainState::FireProjectile() {
if (!m_FireReady) {
return;
}
// (TODO:) manage projectiles; they are currently causing memory leaks
Projectile* projectile = (Projectile*)m_EnginePtr->GetEntityManager()->CreateEntity("Projectile");
projectile->TranslateTo(m_Player->GetWorldPosition());
Texture* tex = m_EnginePtr->GetTextureRegistry()->GetTexture("projectile.png");
Sprite* sprite = m_EntityManagerPtr->CreateSprite((Entity*)projectile, tex, 1);
sprite->AddClip("idle", 0, 0, 30, 5, 1, 1, 1);
sprite->SetOrigin(Vec2(0, 3));
PhysBody* body = m_EntityManagerPtr->CreatePhysBody((Entity*)projectile, kPhysBodyDynamic, kPhysLayerFriendProj);
body->SetOrigin(Vec2(0, 3));
body->SetWidth(30.0);
body->SetHeight(5.0);
if (m_Player->GetFlipY()) {
projectile->FlipY(true);
body->SetVelocity(Vec2(-1.0, 0.0));
}
else {
projectile->FlipY(false);
body->SetVelocity(Vec2(1.0, 0.0));
}
m_EnginePtr->GetScene()->AddEntity(projectile, 0);
// Adds the projectile to the projectile array
m_ProjectileArray.PushBack(projectile);
m_FireReady = false;
}
示例2: BaseGameState
MainState::MainState(GameEngine* engine): BaseGameState(engine),
m_ProjectileArray(kProjectileMax)
{
m_EntityManagerPtr = engine->GetEntityManager();
m_PhysWorldPtr = engine->GetPhysWorld();
// Set the game controller
m_Controller = new GameController(this);
memset((void*)m_PlayerDirState, 0, sizeof(bool) * 4);
// Creates the player entity
m_Player = (Player*)m_EntityManagerPtr->CreateEntity("Player");
// Creates the player sprite
Texture* playerTex = m_EnginePtr->GetTextureRegistry()->GetTexture("metalslug.png");
Sprite* playerSprite = m_EntityManagerPtr->CreateSprite((Entity*)m_Player, playerTex, 1);
playerSprite->AddClip("idle", 5, 0, 30, 40, 1, 1, 1);
playerSprite->PlayClip("idle", true);
playerSprite->SetOrigin(Vec2(15, 20));
// Create the player phys body
PhysBody* playerBody = m_EntityManagerPtr->CreatePhysBody((Entity*)m_Player, kPhysBodyControlled, kPhysLayerFriend);
playerBody->SetOrigin(Vec2(15, 20));
playerBody->SetWidth(30.0);
playerBody->SetHeight(40.0);
// Creates the enemy entity
m_Enemy = (Enemy*)m_EntityManagerPtr->CreateEntity("Enemy");
m_Enemy->TranslateTo(Vec2(200.0, 0.0));
// Creates the enemy sprite
Texture* enemyTex = m_EnginePtr->GetTextureRegistry()->GetTexture("ms_enemy.png");
Sprite* enemySprite = m_EntityManagerPtr->CreateSprite((Entity*)m_Enemy, enemyTex, 1);
enemySprite->AddClip("idle", 0, 4, 30, 40, 1, 1, 1);
enemySprite->PlayClip("idle", true);
enemySprite->SetOrigin(Vec2(15, 20));
// Create the enemy phys body
PhysBody* enemyBody = m_EntityManagerPtr->CreatePhysBody((Entity*)m_Enemy, kPhysBodyStatic, kPhysLayerEnemy);
enemyBody->SetOrigin(Vec2(15, 20));
enemyBody->SetWidth(30.0);
enemyBody->SetHeight(40.0);
m_PhysWorldPtr->ResetAllLayerIgnore();
// Sets which layer ignores which
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerFriend);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemy, kPhysLayerEnemy);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriendProj, kPhysLayerFriendProj);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemyProj, kPhysLayerEnemyProj);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerEnemy);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerFriend, kPhysLayerFriendProj);
m_PhysWorldPtr->AddLayerIgnore(kPhysLayerEnemy, kPhysLayerEnemyProj);
m_FireReady = true;
//delete[] pngData;
}