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


C++ LTimer::start方法代码示例

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


在下文中一共展示了LTimer::start方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loop

void loop () {
	//Handle events on queue
	while( SDL_PollEvent( &e ) != 0 )
	{
		//User requests quit
		if( e.type == SDL_QUIT )
		{
			quit = true;
		}
		
		//Handle input for the dot
		dot.handleEvent( e );
	}
	
	//Calculate time step
	float timeStep = stepTimer.getTicks() / 1000.f;

	//Move for time step
	dot.move( timeStep );

	//Restart step timer
	stepTimer.start();

	//Clear screen
	SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( gRenderer );

	//Render dot
	dot.render();

	//Update screen
	SDL_RenderPresent( gRenderer );
}
开发者ID:peterhenryfirst,项目名称:thecyclops,代码行数:33,代码来源:44_frame_independent_movement.cpp

示例2: main

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			fpsTimer.start();
#ifdef __EMSCRIPTEN__
            emscripten_set_main_loop(loop, 0, 1);
#else
			//While application is running
			while (!quit)
			{
				loop();
			}
			SDL_Delay(100);
#endif
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
开发者ID:peterhenryfirst,项目名称:thecyclops,代码行数:35,代码来源:24_calculating_frame_rate.cpp

示例3: update

void update()
{
    //Calculate time step
    float timeStep = stepTimer.getTicks()/1000.f;

    //pseudo:
    //update any world stuff (background objects, etc)

    //NPC AI
    //for each npc
    //npc.strategize

    //for each object in the world
    //object.framenumber++
    //object.move (x += xv, y += yv)

    //handle collisions
    //Move for time step
    stepTimer.start();

    //Calculate FPS
    timeText.str("");
    SDL_AtomicLock( &gDataLock );
    timeText << "FPS: " << framesThisSecond;
    SDL_AtomicUnlock( &gDataLock );

    if(!gFPSTextTexture.loadFromRenderedText(timeText.str().c_str(), fpsColor))
    {
        printf("Unable to render FPS texture.\n");
    }
}
开发者ID:jphinspace,项目名称:Safeguard2,代码行数:31,代码来源:SafeguardMain.cpp

示例4: icp_outlierRemoval

Mat icp_outlierRemoval(Pixel3DSet & src, Pixel3DSet & _dst, Pixel3DSet & out,
					   double & error_out, double & time, int & iterations,
					   double outlierRemovalTimesMean, double minError,
					   int maxIterations)
{
	time = 0.0;
	LTimer clock; clock.start();
	out.clear();
	Mat ret = Mat::eye(Size(4,4), CV_32FC1);
	vector<double> dl;
	vector<int> ind;
	out = src;
	Pixel3DSet dst = _dst;
	iterations = 0;

	double best_distance = DBL_MAX;
	error_out = best_distance;

	Mat T = ret.clone();

	while(true)
	{
		dl.clear(); ind.clear();
		double current_distance = Licp::closestPointsf(out, dst, ind, dl);
		if(current_distance >= best_distance) break; //cannot do any better
		ret = T * ret;
		error_out = current_distance;
		if(minError > 0.0 && current_distance < minError) break;
		if(maxIterations >= 0 && iterations >= maxIterations) break;
		best_distance = current_distance;
		if(best_distance <= 0.0) break;

		//outlier removal
		//cout << current_distance << " is current, or is: " << outlierRemovalTimesMean << endl;
		vector<R3> srcTest, dstTest;
		vector<int> indTest;
		for(int i = 0; i < dl.size(); i++)
		{
			double test = dl[i] / best_distance;
			//cout << dl[i] << " : " << best_distance << " : " << test << " <= " << outlierRemovalTimesMean << endl;
			if(dl[i]/best_distance < outlierRemovalTimesMean)
			{
				srcTest.push_back(out[i]);
				dstTest.push_back(dst[ind[i]]);
				indTest.push_back(i);
			}
		}

		//cout << "i/o(" << out.size() << "/" << srcTest.size() << ")\n";

		T = Licp::leastSquaresTransform(srcTest, dstTest, indTest);
		for(int i = 0; i < out.size(); i++) ll_pix3d::Pixel3DSet::transform_point(T, out[i]);
		iterations++;
	}
	clock.stop();
	time = clock.getSeconds();
	return ret.clone();
}
开发者ID:lukes611,项目名称:phdThesis,代码行数:58,代码来源:Licp.cpp

示例5: startStopTimer

void startStopTimer()
{
    if (gTimer.isStarted())
    {
        gTimer.stop();
    }
    else
    {
        gTimer.start();
    }
}
开发者ID:NASD-Bulgaria,项目名称:egt-training,代码行数:11,代码来源:main.cpp

示例6: icp

Mat icp(Pixel3DSet & src, Pixel3DSet & dst, Pixel3DSet & out,
		double & error_out, double & time, int & iterations,
		double minError, int maxIterations)
{
	time = 0.0;
	LTimer clock; clock.start();
	out.clear();
	Mat ret = Mat::eye(Size(4,4), CV_32FC1);
	vector<double> dl;
	vector<int> ind;
	out = src;
	iterations = 0;

	double best_distance = DBL_MAX;
	error_out = best_distance;

	Mat T = ret.clone();

	while(true)
	{
		dl.clear(); ind.clear();
		double current_distance = closestPointsf(out, dst, ind, dl);
		if(current_distance >= best_distance) break; //cannot do any better
		ret = T * ret;
		error_out = current_distance;
		if(minError > 0.0 && current_distance < minError) break;
		if(maxIterations >= 0 && iterations >= maxIterations) break;
		best_distance = current_distance;
		T = leastSquaresTransform(out.points, dst.points, ind);
		for(int i = 0; i < out.size(); i++) ll_pix3d::Pixel3DSet::transform_point(T, out[i]);
		iterations++;
	}
	clock.stop();
	time = clock.getSeconds();
	return ret.clone();
}
开发者ID:lukes611,项目名称:phdThesis,代码行数:36,代码来源:Licp.cpp

示例7: run

// run application
void SDLApp::run()
{
    game->music.front()->play();
    
    SDL_Texture * backgroundTex = game->backgrounds.front()->getTexture();
    
    Texture * jewelTex1 = game->jewels.at(0);
    
    usint
          screenSize = min(SCREEN_WIDTH,SCREEN_HEIGHT),
          gridSize   = (screenSize * 4 / 5),
    
          gridStartX = (SCREEN_WIDTH - gridSize - gridSize/8),
          gridStartY = (SCREEN_HEIGHT - gridSize - gridSize/8),
    
          cellSize   = gridSize / 8,
          cellArea   = cellSize - 1,
          jewelSize  = jewelTex1->getWidth() * jewelTex1->getScaleX(),
          jewelStart = (usint) ((cellSize - jewelSize) / 2) + 1;
    
    SDL_Rect jewelPos;
    jewelPos.w = 70;
    jewelPos.h = 70;
    jewelPos.x = 0;
    jewelPos.y = 0;
    
    //Main loop flag
    bool quit = false;
    
    //Event handler
    SDL_Event e;
    
    LButton mArray[8][8];
    
    for (usint i=0; i<GRIDSIZE; i++)
    {
        for (usint j=0; j<GRIDSIZE; j++)
        {
            mArray[i][j].setPosition( gridStartX + cellSize * j + 1, gridStartY + cellSize * i + 1 );
            mArray[i][j].setSize( cellArea );
        }
    }
    
    //The frames per second timer
    LTimer fpsTimer;
    
    //The frames per second cap timer
    LTimer capTimer;
    
    float avgFPS;
    
    //In memory text stream
    std::stringstream timeText, scoreText, endText;
    
    //Start counting frames per second
    int countedFrames = 0, frameTicks;
    fpsTimer.start();
    
    bool keyDown;
    
    usint pI,pJ, jewel;
    
    SDL_Rect fillRect, cell;
    
    Font * scoreFont = game->fonts.front();
    
    bool clickingOn = false;
    
    Animation * animation;
    
    //game->animations.push( new Slide(60, game->jewels.front(), make_pair(0,0), make_pair(0, 480)) );
    
    //While application is running
    while( !quit )
    {
        countedFrames++;
        keyDown = false;
        
        //Handle events on queue
        while( SDL_PollEvent( &e ) != 0 )
        {
            switch( e.type )
            {
                case SDL_QUIT:
                    quit = true;
                    break;
                case SDL_KEYDOWN:
                    keyDown = true;
                    break;
                case SDL_KEYUP:
                    keyDown = false;
                    break;
                default:
                    break;
            }
        }
        if ( keyDown )
            printf("Key down!\n");
        
//.........这里部分代码省略.........
开发者ID:RicardoCoutinho,项目名称:GemsArr,代码行数:101,代码来源:SDLApp.cpp

示例8: main

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//Set text color as black
			SDL_Color textColor = { 0, 0, 0, 255 };

			//The application timer
			LTimer timer;

			//In memory text stream
			std::stringstream timeText;

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}
					//Reset start time on return keypress
					else if( e.type == SDL_KEYDOWN )
					{
						//Start/stop
						if( e.key.keysym.sym == SDLK_s )
						{
							if( timer.isStarted() )
							{
								timer.stop();
							}
							else
							{
								timer.start();
							}
						}
						//Pause/unpause
						else if( e.key.keysym.sym == SDLK_p )
						{
							if( timer.isPaused() )
							{
								timer.unpause();
							}
							else
							{
								timer.pause();
							}
						}
					}
				}

				//Set text to be rendered
				timeText.str( "" );
				timeText << "Seconds since start time " << ( timer.getTicks() / 1000.f ) ; 

				//Render text
				if( !gTimeTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) )
				{
					printf( "Unable to render time texture!\n" );
				}

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render textures
				gStartPromptTexture.render( ( SCREEN_WIDTH - gStartPromptTexture.getWidth() ) / 2, 0 );
				gPausePromptTexture.render( ( SCREEN_WIDTH - gPausePromptTexture.getWidth() ) / 2, gStartPromptTexture.getHeight() );
				gTimeTextTexture.render( ( SCREEN_WIDTH - gTimeTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gTimeTextTexture.getHeight() ) / 2 );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
	}

	//Free resources and close SDL
	close();

//.........这里部分代码省略.........
开发者ID:JerelynCo,项目名称:CS179.14,代码行数:101,代码来源:23_advanced_timers.cpp

示例9: main

int main( int argc, char* args[] ) {
  //Start up SDL and create window
  if( !init() ) {
    printf( "Failed to initialize!\n" );
  } else {
    //Load media
    if( !loadMedia() ) {
      printf( "Failed to load media!\n" );
    } else {
      //Main loop flag
      bool quit = false;

      //Event handler
      SDL_Event e;

      //The dot that will be moving around on the screen
      Dot dot;

      //Keeps track of time between steps
      LTimer stepTimer;

      //While application is running
      while( !quit ) {
        //Handle events on queue
        while( SDL_PollEvent( &e ) != 0 ) {
          //User requests quit
          if( e.type == SDL_QUIT ) {
            quit = true;
          }

          //Handle input for the dot
          dot.handleEvent( e );
        }

        //Calculate time step
        float timeStep = stepTimer.getTicks() / 1000.f;

        //Move for time step
        dot.move( timeStep );

        //Restart step timer
        stepTimer.start();

        //Clear screen
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
        SDL_RenderClear( gRenderer );

        //Render dot
        dot.render();

        //Update screen
        SDL_RenderPresent( gRenderer );
      }
    }
  }

  //Free resources and close SDL
  close();

  return 0;
}
开发者ID:kaprikawn,项目名称:sdl-starter,代码行数:61,代码来源:44_frame_independent_movement.cpp

示例10: main

int main( int argc, char* args[] ){
	//Start up SDL and create window
	if(!init()){
		printf( "Failed to initialize!\n" );
	}
	else{
		//Load media
		if(!loadMedia()){
			printf( "Failed to load media!\n" );
		}
		else{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//In memory text stream
			stringstream timeText;

			//Start global timer
			gTimer.start();

			//The frames per second timer
			LTimer fpsTimer;

			//Start counting frames per second
			int countedFrames = 0;
			fpsTimer.start();

			//Count of balls in screen
			int nBalls = 4;

			//Set text color as black
			SDL_Color textColor = {0, 0, 0, 255};

			//loadBalls in vector gBalls
			loadBalls(nBalls);

			//While application is running
			while(!quit){
				//Handle events on queue
				while(SDL_PollEvent(&e) != 0){
					//User requests quit
					if(e.type == SDL_QUIT){
						quit = true;
					}
				}

				//Clear screen
				SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
				SDL_RenderClear(gRenderer);

				//The ball in the center of the screen to which all other ball collides with
				Ball ball(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 0, 0);
				ball.render();
				
				//Calculate and correct fps
				float avgFPS = countedFrames/(fpsTimer.getTicks()/1000.f);
				if(avgFPS > 2000000){
					avgFPS = 0;
				}

				//Set text to be rendered
				timeText.str("");
				timeText << "Average Frames Per Second " << avgFPS; 

				//Render text
				if(!gFPSTextTexture.loadFromRenderedText(timeText.str().c_str(), textColor)){
					printf("Unable to render FPS texture!\n");
				}
				gFPSTextTexture.render((SCREEN_WIDTH-gFPSTextTexture.getWidth())/2, 0);

				//Move and render the balls inside the vector gBalls
				for(int i = 0; i < nBalls; i++){
					//bug: Needs to include all the balls inside the gBalls for the move method
					gBalls.at(i).move(ball.getCollider());
					gBalls.at(i).render();
				}

				//Update screen
				SDL_RenderPresent(gRenderer);
				++countedFrames;

			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
开发者ID:JerelynCo,项目名称:CS179.14,代码行数:93,代码来源:bouncingBall.cpp

示例11: main

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//Set text color as black
			SDL_Color textColor = { 0, 0, 0, 255 };

			//The frames per second timer
			LTimer fpsTimer;

			//In memory text stream
			std::stringstream timeText;

			//Start counting frames per second
			int countedFrames = 0;
			fpsTimer.start();

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}
				}

				//Calculate and correct fps
				float avgFPS = countedFrames / ( fpsTimer.getTicks() / 1000.f );
				if( avgFPS > 2000000 )
				{
					avgFPS = 0;
				}
				
				//Set text to be rendered
				timeText.str( "" );
				timeText << "Average Frames Per Second " << avgFPS; 

				//Render text
				if( !gFPSTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) )
				{
					printf( "Unable to render FPS texture!\n" );
				}

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render textures
				gFPSTextTexture.render( ( SCREEN_WIDTH - gFPSTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gFPSTextTexture.getHeight() ) / 2 );

				//Update screen
				SDL_RenderPresent( gRenderer );
				++countedFrames;
			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
开发者ID:cvg256,项目名称:SDLTestGame,代码行数:84,代码来源:24_calculating_frame_rate.cpp

示例12: main

int main(int argc, char *argv[])
{

	Tile *tiles[400];
	Mobs *ghosts[4];
	std::vector<Tile> coins;

	game.init();

	game.loadMedia();

	loadPlayerTex();

	game.loadGhosts(ghosts);

	if(	game.setTiles(tiles) == false) {
		printf("set tiles err \n");	
		return -1;
	}

	for(int i = 0; i < 400; ++i)
	{
		if(tiles[i]->getType() == 0)
			coins.push_back( Tile( tiles[i]->getBox().x, tiles[i]->getBox().y, 0 ) );
	}
	
	LTexture coinTex;
	coinTex.loadFromFile( "Data/Art/coin.png", game.getRenderer() );
	for(int i = 0; i < coins.size(); ++i)
	{
		coins[i].tileTex = &coinTex;
	}

	bool quit = false;

	LMenu menu( game.getRenderer() );
	menu.run();
	if(menu.isFinished() == 1)
		quit = true;

	Player player(32, 32);
	
	player.CurrentDirection = MovementRight;

	//game.setPlayerTex(player);

	LTimer fpsTimer;
	LTimer capTimer;
	
	int countedFrames = 0;
	int anim = 0;
	fpsTimer.start();

	const int gameEEN_FPS = 60;
	const int gameEEN_TICK_PER_FRAME = 1000 / gameEEN_FPS;

	SDL_Event e;

	while( !quit )
	{
		capTimer.start();
		while( SDL_PollEvent(&e) != 0 )
		{
			if(e.type == SDL_QUIT)
			{
				quit = true;
			}

			player.handleEvent(e);

		}


		//printf("%d, %d, %d, %d \n", leftCorn.x, leftCorn.y, leftCorn.w, leftCorn.h);

		//printf(" %d \n", player.CurrentDirection);

		game.GhostsAI(player, ghosts, tiles);

		game.GhostsCollision(ghosts, tiles);

		player.update();

		SDL_Rect topBox = {player.getPlayerBox().x + 2, player.getPlayerBox().y - 20, 1, 20};
		SDL_Rect rightBox = {player.getPlayerBox().x + player.getPlayerBox().w, player.getPlayerBox().y + 2, 20, 1};
		SDL_Rect botBox = {player.getPlayerBox().x + 2, player.getPlayerBox().y + player.getPlayerBox().h, 1, 20};
		SDL_Rect leftBox = {player.getPlayerBox().x - 20, player.getPlayerBox().y + 2, 20, 1};
		SDL_Rect topBox2 = {player.getPlayerBox().x + player.playerBox.w - 4, player.getPlayerBox().y - 20, 1, 20};
		SDL_Rect rightBox2 = {player.getPlayerBox().x + player.playerBox.w, player.getPlayerBox().y + player.playerBox.h - 4, 20, 1};
		SDL_Rect botBox2 = {player.getPlayerBox().x + player.getPlayerBox().w - 4, player.getPlayerBox().y + player.getPlayerBox().h, 1, 20};
		SDL_Rect leftBox2 = {player.getPlayerBox().x - 20, player.getPlayerBox().y + player.playerBox.h - 4, 20, 1};

		
		if (game.Collision(player, tiles) == 1 )
		{
			player.playerBox.x += PLAYER_SPEED;

			if(player.directionY == 1)
				player.CurrentDirection = MovementUp;
			if(player.directionY == 3)
//.........这里部分代码省略.........
开发者ID:nbudinov,项目名称:Game-Dev-Summer-2014,代码行数:101,代码来源:main.cpp

示例13: start

int Saloon::start() {
	if(_window != nullptr) {

		// Create an OpenGL context associated with the window.
		SDL_GLContext glContext = SDL_GL_CreateContext(_window);

		// Init and check for GL Errors.
		glInit(_displayWidth, _displayHeight);

		GLenum error = glGetError();
		if( error != GL_NO_ERROR )
		{
			logSDLError(std::cout, "GL INIT");
			return 1;
		}

		LTimer fpsTimer;
		fpsTimer.start();
		Uint32 frames = 0, FPS = 0;

		//Our event structure
		SDL_Event e;
		bool quit = false;

		int curTime, prevTime = SDL_GetTicks();

		BMFont debugFont("Fonts/system16.fnt");

		onCreate();


		while (!quit){

			while (SDL_PollEvent(&e)){
				if (e.type == SDL_QUIT)
					quit = true;
				//Use number input to select which clip should be drawn
				if (e.type == SDL_KEYDOWN){
					switch (e.key.keysym.sym){
						case SDLK_ESCAPE:
							quit = true;
							break;
						case SDLK_TAB:
							if(_debugEnabled) {
								setVSyncEnabled(false);
							}
							break;
						default:
							break;
					}
				}
				else if(e.type == SDL_KEYUP) {
					switch (e.key.keysym.sym){
						case SDLK_TAB:
							if(_debugEnabled) {
								setVSyncEnabled(true);
							}
							break;
						default:
							break;
					}
				}
			}

			if(_debugEnabled) {
				debugStart();

				curTime = SDL_GetTicks();

				deltaTime = (curTime - prevTime) / 1000.0f;

				prevTime = curTime;

				if(fpsTimer.getTicks() >= 1000) {
					FPS = frames;
					frames = 0;
					fpsTimer.reset();
				}

				frames++;

				debugWatch("FPS", FPS);
			}

			onUpdate();

			glClear(GL_COLOR_BUFFER_BIT);

			//Reset modelview matrix
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();

			glPushMatrix();

			glTranslatef(_halfDisplayWidth, _halfDisplayHeight, 0.0f);

			glPushMatrix();
			// Camera transformations
			glScalef(_camZoom, _camZoom, 1.0f);
			glRotatef(_camAng, 0, 0, 1);
//.........这里部分代码省略.........
开发者ID:jimhub,项目名称:saloon-engine,代码行数:101,代码来源:Saloon.cpp

示例14: main

int main(int argc, char **argv) {

	// Init all SDl stuff

	SDL_Routine SDL_hdl;
	if (SDL_hdl.InitSDL()) {
		logSDLError(std::cout, "SDL Init");
		return 1;
	}

	SDL_Texture *bg = loadTexture("res/bg.png", SDL_hdl.Render);
	Character Alice;

	Alice.loadTex("res/Alice_spritesheet.png", SDL_hdl.Render);

	if (bg == nullptr || Alice.char_tex == nullptr)
			return 4;

	const Uint8 *keys = SDL_GetKeyboardState(nullptr);


	// Main Loop

	Mix_Music *bg_mus = loadBGMusic("res/bg.mp3");
	playBGMusic(bg_mus);
	bool mus_status = true;

	SDL_Event e;
	bool show_fps = true;
	bool quit = false;

	TTF_Font* fps_font = openFont("res/beau.ttf", 25);
	SDL_Color textColor = {0, 0, 0};

	std::stringstream fps_text;
	SDL_Texture* txt_image;
	//SDL_Texture* txt_image = renderText("FPS test text", fps_font, textColor, renderer);
	//if (txt_image == nullptr) {
	//	return 1;
	//}

	LTimer fpsTimer;
	int countedFrames = 0;
	std::stringstream fpsText;
	float avgFPS = 0;

	fpsTimer.start();


	while (!quit) {

		SDL_RenderClear(SDL_hdl.Render);

		int bW, bH;
		SDL_QueryTexture(bg, NULL, NULL, &bW, &bH);

		// Calculate FPS
		avgFPS = countedFrames / ( fpsTimer.getTicks() / 1000.f );
		if ( avgFPS > 2000000 )
			avgFPS = 0;
		fps_text.str("");
		fps_text << "FPS: " << avgFPS;

		// Render BG
		SDL_Rect bg_box;
		bg_box.x = 0;
		bg_box.y = 0;
		bg_box.w = SCREEN_WIDTH;
		bg_box.h = SCREEN_HEIGHT;
		renderTexture(bg, SDL_hdl.Render, bg_box, nullptr);

		// Show FPS
		if (show_fps) {
			txt_image = renderText(fps_text.str().c_str(), fps_font, textColor, SDL_hdl.Render);
			if (txt_image == nullptr) {
				return 1;
			}
		}

		//SDL_PumpEvents();
		if (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = true;
			if (e.type == SDL_MOUSEBUTTONDOWN)
				quit = true;
		}

		if (keys[SDL_SCANCODE_LEFT]) {
			Alice.direction_state = 6;
			Alice.anim_frame = Alice.frame / 4;
			if (Alice.char_box.x > 0)
				Alice.char_box.x -= VELOCITY;
		}
		if (keys[SDL_SCANCODE_RIGHT]) {
			Alice.direction_state = 2;
			Alice.anim_frame = Alice.frame / 4;
			if (Alice.char_box.x <= (SCREEN_WIDTH - SPRITE_SIZE * 3))
				Alice.char_box.x += VELOCITY;
		}
		if (keys[SDL_SCANCODE_UP]) {
//.........这里部分代码省略.........
开发者ID:zagevalo,项目名称:SDL2_tut,代码行数:101,代码来源:SDL2_tut.cpp


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