本文整理汇总了C++中StateManager::draw方法的典型用法代码示例。如果您正苦于以下问题:C++ StateManager::draw方法的具体用法?C++ StateManager::draw怎么用?C++ StateManager::draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateManager
的用法示例。
在下文中一共展示了StateManager::draw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
double lastFPSTime = glfwGetTime();
int fps = 0;
while (!m_win->shouldClose()) {
glfwPollEvents();
double now = glfwGetTime();
m_stateManager.update();
m_stateManager.draw();
m_win->swapBuffers();
if (now - lastFPSTime > 1) {
char fpsString[200];
sprintf(
fpsString, "Pxljm 2015 [%d FPS @%dx%d]",
fps, m_win->width(), m_win->height());
m_win->title(fpsString);
fps = 0;
lastFPSTime = now;
}
fps++;
}
delete m_win;
glfwTerminate();
}
示例2: main
int main(int argc, const char* argv[])
{
ResourceLoader loader(argv[0] + std::string("\\..\\..\\Resources"));
StateManager states;
states.setState(std::unique_ptr<MenuScreen>(new MenuScreen(loader)));
sf::RenderWindow app(sf::VideoMode(768, 768, 32), "Ethan Game");
app.EnableKeyRepeat(false);
sf::Clock clock;
double timeForSimulation = 0;
while (app.IsOpened())
{
sf::Event event;
while (app.GetEvent(event))
{
switch(event.Type)
{
case sf::Event::Closed:
app.Close();
break;
default:
states.handleEvent(event);
}
}
timeForSimulation+= clock.GetElapsedTime();
clock.Reset();
while (timeForSimulation >= 1.0/60.0)
{
states.update(1.0/60.0);
timeForSimulation -= 1.0/60;
}
states.draw(app);
app.Display();
}
return 0;
}
示例3: main
int main() {
srand((long)time(0));
//load screen stuff like resolution, sound settings, ETC
GameConfiguration gameConfiguration;
gameConfiguration.load();
sf::RenderWindow window(sf::VideoMode(DEFAULT_SCREEN_RESOLUTION.x, DEFAULT_SCREEN_RESOLUTION.y), "Contra");
sf::Event event;
StateManager stateManager;
shared_ptr<GameState> mainMenu = make_shared<GameStateMainMenu>(window, stateManager);
if(mainMenu) {
stateManager.push(mainMenu);
}
sf::Clock timer;
const sf::Time maxDeltaTime = sf::seconds(0.025);
while(window.isOpen()) {
while(window.pollEvent(event)) {
//handle other window events first
if(event.type == sf::Event::Closed) {
window.close();
}
//window resized so reset default view
if(event.type == sf::Event::Resized) {
sf::Vector2f newSize(event.size.width, event.size.height);
sf::View newView;
newView.setSize(newSize);
window.setView(newView);
}
stateManager.handleInputEvents(event, window);
}
stateManager.handleStateEvents(window);
sf::Time delta = timer.restart();
if(delta > maxDeltaTime) {
delta = maxDeltaTime;
}
stateManager.update(delta.asSeconds(), window);
window.clear();
stateManager.draw(window);
window.display();
if(stateManager.isEmpty()) {
//no states left to handle so may as well clsoe the game
break;
}
}
//do some cleanup crap
}