本文整理汇总了C++中AnimatedSprite::Animate方法的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedSprite::Animate方法的具体用法?C++ AnimatedSprite::Animate怎么用?C++ AnimatedSprite::Animate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnimatedSprite
的用法示例。
在下文中一共展示了AnimatedSprite::Animate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void ZombieGame::Run() {
// Start the game loop
while (window->IsOpened())
{
// Process events
sf::Event Event;
while (window->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
window->Close();
if(Event.Type == sf::Event::KeyPressed) {
if(Event.Key.Code == sf::Key::Return) {
isGameOn = !isGameOn;
}
}
}
if(gameover) {
//window->Close();
}
// Clear screen
window->Clear(sf::Color(255, 255, 255));
// Draw background
window->Draw(*sprfond);
// Draw terrain
window->Draw(*sprterrain);
if(isGameOn) {
// Set camera
if(interface->GetX() >= 0.7)
camera->Move(10, 0);
else if(interface->GetX() <= 0.3)
camera->Move(-10, 0);
camera->Update();
if(rand()%500 <= 1) {
//for(unsigned int i = 0; i<4+rand()%4; i++) {
sprzombies.push_back(new Zombie(imgzombie, imgterrain));
AddSprite(sprzombies.back());
//}
}
// Update all sprites :
for(int i=0; i<sprites.size(); i++) {
AnimatedSprite* a = dynamic_cast<AnimatedSprite*>(sprites[i]);
if(a != NULL) a->Animate();
sprites[i]->Update();
}
// Delete all killed zombies :
vector<Zombie*>::iterator it=sprzombies.begin();
while(it!=sprzombies.end())
{
if((*it)->IsDead())
{
RemoveSprite(*it);
sprzombies.erase(it);
}
else
{
it++;
}
}
}
// Draw all the objects on the window
for(int i=0; i<sprites.size(); i++) {
window->Draw(*(sprites[i]));
}
// Draw the mouse position :
sf::Vector2f mouse_pos = GetMousePosition();
sf::Shape circle = sf::Shape::Circle(mouse_pos.x, mouse_pos.y, 10, sf::Color::Red);
window->Draw(circle);
// Update the window
window->Display();
}
}