当前位置: 首页>>代码示例>>C++>>正文


C++ Gfx::gfxinit方法代码示例

本文整理汇总了C++中Gfx::gfxinit方法的典型用法代码示例。如果您正苦于以下问题:C++ Gfx::gfxinit方法的具体用法?C++ Gfx::gfxinit怎么用?C++ Gfx::gfxinit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gfx的用法示例。


在下文中一共展示了Gfx::gfxinit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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!
}
开发者ID:KiaraSimlick,项目名称:Game,代码行数:65,代码来源:main.cpp


注:本文中的Gfx::gfxinit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。