本文整理汇总了C++中Gfx::update方法的典型用法代码示例。如果您正苦于以下问题:C++ Gfx::update方法的具体用法?C++ Gfx::update怎么用?C++ Gfx::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gfx
的用法示例。
在下文中一共展示了Gfx::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ( int argc, char** argv ) {
SDL_Texture* s1Texture = NULL;
SDL_Texture* s1TextureShift = NULL;
SDL_Rect s1Rect = { 0, 0, 18, 24 }; //player x y w h
SDL_Texture* e1Texture = NULL;
SDL_Rect e1Rect = { 310, 240, 16, 16 }; //enemy x y w h
Input *input = new Input();
Sprite *sprite = new Sprite();
Gfx *gfx = new Gfx();
General *general = new General();
float fps, frames, frameStartTime, frameEndTime;
gfx->gfxinit(screenw, screenh); // open window with 620x480 res. with 8 bit color
s1Texture = gfx->createTexture("gfx/s1.bmp", 0);
s1TextureShift = gfx->createTexture("gfx/s1sneek.bmp", 1);
e1Texture = gfx->createTexture("gfx/e1.bmp", 0);
/* program main loop */
while (!input->isGameDone()) {
// get time when frame starts
frameStartTime = SDL_GetTicks();
input->inputLoop();
sprite->move(input, s1Rect, e1Rect);
general->checkCollision(input, s1Rect, e1Rect, screenw, screenh);
gfx->clearScreen(100,0,0);
if (!input->isShiftPressed()) {
gfx->drawTexture(s1Texture, s1Rect);
} else {
gfx->drawTexture(s1TextureShift, s1Rect);
}
gfx->drawTexture(e1Texture, e1Rect);
gfx->update();
// get time at the end of frame after updating
frameEndTime = SDL_GetTicks();
// increment frames
++frames;
fps = frames / (SDL_GetTicks() / 1000);
// Supposed ms per frame is 16.6666ms since 1000/60
// if frame finishes early
if ((frameEndTime - frameStartTime) < (1000/60)) {
SDL_Delay((1000 / 60) - (frameEndTime - frameStartTime));
}
}
delete sprite;
delete input;
delete general;
gfx->close();
delete gfx;
return 0; // return success!
}
示例2: main
int main(int argc, char *argv[]) {
FILE* fp = fopen("config.txt", "r");
if (fp) {
int a, b;
if (fscanf(fp," cores %d", &a) == 1) plotter.n_threads = a;
if (fscanf(fp," def_res %d %d", &a, &b) == 2) {
gfx.screen_w_default = a;
gfx.screen_h_default = b;
}
if (fscanf(fp," max_iter %d", &a) == 1) plotter.max_iter = a;
}
if (SDL_Init(SDL_INIT_EVERYTHING) == -1 || !gfx.init()) return 1;
plotter.init();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
while (true) {
frame_time = SDL_GetTicks();
input.update();
if (input.key_pressed(SDLK_ESCAPE) || input.is_quitting())
break;
if (input.key_down( SDLK_LCTRL ) &&
input.mouse_pressed(SDL_BUTTON_LEFT)) {
plotter.center();
} else if (input.mouse_pressed(SDL_BUTTON_LEFT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(zoom_factor * 5);
} else {
plotter.zoom(zoom_factor);
}
} else if (input.mouse_pressed(SDL_BUTTON_RIGHT)) {
if (input.key_down(SDLK_LSHIFT)) {
plotter.zoom(1/(zoom_factor * 5));
} else {
plotter.zoom(1/zoom_factor);
}
}
if (input.key_pressed(SDLK_f)) {
plotter.end_plotting();
gfx.toggle_fullscreen();
plotter.resize(gfx.get_screen_w(), gfx.get_screen_h());
plotter.plot();
//zoom_on();
}
if (input.key_pressed(SDLK_p)) {
plotter.print_pos();
}
gfx.update();
int time_rem = 1000 / FPS - (SDL_GetTicks() - frame_time);
if (time_rem >= 5)
SDL_Delay(time_rem);
}
plotter.end_plotting();
SDL_Quit();
return 0;
}