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


C++ LTexture::getWidth方法代码示例

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


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

示例1: main

int main(int argc, const char * argv[]) {
    init();
    loadMedia();
    
    bool quit = false;
    
    SDL_Event e;
    
    int frame = 0;
    
    int scrollingOffset = gameState.scrollingOffset;
    
    while (!quit) {
        while (SDL_PollEvent(&e) != 0) {
            if (e.type == SDL_QUIT) {
                quit = true;
            }
            batman->handleEvent(e);
        }
        
        SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
        SDL_RenderClear(gRenderer);
        
        // load background first with offset
        if (batman->isMovingFwd()) {
            -- scrollingOffset;
            if (scrollingOffset < -gBackGroundTexture.getWidth()) {
                scrollingOffset = 0;
            }
        }
        
        gBackGroundTexture.render(scrollingOffset, 0, gRenderer);
        gBackGroundTexture.render(scrollingOffset + gBackGroundTexture.getWidth(), 0, gRenderer);
        
        batman->render(50, SCREEN_HEIGHT - 60);
        
        SDL_RenderPresent(gRenderer);
    }
    
    // save game state
    gameState.scrollingOffset = scrollingOffset;
    printf("saving game state: scrolling offset %d\n", gameState.scrollingOffset);
    
    // close
    close();
    
    
    return 0;
}
开发者ID:xysun,项目名称:batman1,代码行数:49,代码来源:main.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
        {
            //Main loop flag
            bool quit = false;

            //Event handler
            SDL_Event e;

            //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 window events
                    gWindow.handleEvent( e );
                }

                //Only draw when not minimized
                if( !gWindow.isMinimized() )
                {
                    //Clear screen
                    SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
                    SDL_RenderClear( gRenderer );

                    //Render text textures
                    gSceneTexture.render( ( gWindow.getWidth() - gSceneTexture.getWidth() ) / 2, ( gWindow.getHeight() - gSceneTexture.getHeight() ) / 2 );

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

    //Free resources and close SDL
    close();

    return 0;
}
开发者ID:pmrobotix,项目名称:DemoFusion,代码行数:60,代码来源:35_window_events.cpp

示例3: 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;

			//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 );

				//Render current frame
				gTextTexture.render( ( SCREEN_WIDTH - gTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gTextTexture.getHeight() ) / 2 );

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

	//Free resources and close SDL
	close();

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

示例4: ifShipHit

bool ifShipHit(int projX, int projY, int shipX, int shipY)
{
	if ( projX >= shipX  && 
		(projX < (shipX + (gShipTexture.getWidth()) ) )  && 
		(projY > shipY  ) && 
		(projY < (shipY + (gShipTexture.getHeight()) ) ) )
	{
	return true;
	}
	else 
		return false;
}
开发者ID:nbudinov,项目名称:Game-Dev-Summer-2014,代码行数:12,代码来源:Main.cpp

示例5: 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 );
	}
	
	//Move the dot
	dot.move();

	//Scroll background
	--scrollingOffset;
	if( scrollingOffset < -gBGTexture.getWidth() )
	{
		scrollingOffset = 0;
	}

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

	//Render background
	gBGTexture.render( scrollingOffset, 0 );
	gBGTexture.render( scrollingOffset + gBGTexture.getWidth(), 0 );

	//Render objects
	dot.render();

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

示例6:

Dot::Dot()
{
    //Initialize the offsets
    mPosX = 0;
    mPosY = 0;

	//Set collision box dimension
	mCollider.w = gDotTexture.getWidth();
	mCollider.h = gDotTexture.getHeight();

    //Initialize the velocity
    mVelX = 0;
    mVelY = 0;
}
开发者ID:JerelynCo,项目名称:CS179.14,代码行数:14,代码来源:27_collision_detection.cpp

示例7: ifHitPlayer

bool ifHitPlayer(int playerX, int playerY, int shipProjX, int shipProjY)
{
	//cout << "px " << playerX << "py " << playerY << "sX" << shipProjX << "sY " << shipProjY << endl;
	if( shipProjX > playerX  &&
		shipProjX < playerX + gPlayerTexture.getWidth()  &&
		shipProjY > playerY - gPlayerTexture.getHeight()  )
	{
		cout << "curna TRUE";
		return true;
	}
	else {
		return false;
	}
}
开发者ID:nbudinov,项目名称:Game-Dev-Summer-2014,代码行数:14,代码来源:Main.cpp

示例8: loop

void loop () {
	//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 && e.key.keysym.sym == SDLK_RETURN )
		{
			startTime = SDL_GetTicks();
		}
	}

	//Set text to be rendered
	timeText.str( "" );
	timeText << "Milliseconds since start time " << SDL_GetTicks() - startTime; 

	//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
	gPromptTextTexture.render( ( SCREEN_WIDTH - gPromptTextTexture.getWidth() ) / 2, 0 );
	gTimeTextTexture.render( ( SCREEN_WIDTH - gPromptTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gPromptTextTexture.getHeight() ) / 2 );

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

示例9:

Ball::Ball(int x, int y, int velX, int velY){
    //Initialize the offsets
    mPosX = x;
    mPosY = y;

	//Set collision circle size
	mCollider.r = gBallTexture.getWidth() / 2;

    //Initialize the velocity
    mVelX = velX;
    mVelY = velY;

	//Move collider relative to the circle
	shiftColliders();
}
开发者ID:JerelynCo,项目名称:CS179.14,代码行数:15,代码来源:bouncingBall.cpp

示例10: ifScreenEndHit

bool ifScreenEndHit()
{
	//int firstLeftAlive = 0, firstRightAlive = 0;
	bool endHit = false;
	
	vector<vector<Ships*>>::iterator it = ships.begin();
		for(vector<Ships*>::reverse_iterator itt = (*it).rbegin(); itt != (*it).rend(); ++itt)
		{

	if( (*itt)->mPosX == 0 || (*itt)->mPosX == SCREEN_WIDTH - gShipTexture.getWidth() )
	{
		return true;			
	}
		}
	return endHit;
}
开发者ID:nbudinov,项目名称:Game-Dev-Summer-2014,代码行数:16,代码来源:Main.cpp

示例11: main

int main() {
  if(!init()) {
    printf("Failed to initialize!\n");
    return -1;
  }

  if(!loadMedia()) {
    printf("Failed to load media!\n");
    return -1;
  }

  bool quit = false;
  SDL_Event e;

  //While application is running
  while(!quit) {
    //Handle events on queue
    while(SDL_PollEvent(&e) != 0) {
      //User request quit
      if(e.type == SDL_QUIT) {
	quit = true;
      } 
      //Handle window events
      g_window.handleEvent(e);
    }
    //Only draw when not minimized
    if(!g_window.isMinimized()) {
      //Clear screen
      SDL_SetRenderDrawColor(g_renderer, 0xFF, 0xFF, 0xFF, 0xFF);
      SDL_RenderClear(g_renderer);

      //Render text textures
      g_sceneTexture.render((g_window.getWidth() - g_sceneTexture.getWidth()) / 2,
				 (g_window.getHeight() - g_sceneTexture.getHeight()) / 2 );

      //Update screen
      SDL_RenderPresent(g_renderer);
    }
  }
  close();
  return 0;
}
开发者ID:wedemalm,项目名称:lazyfoo,代码行数:42,代码来源:WindowEvents.cpp

示例12: loop

void loop () {
	//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;
}
开发者ID:peterhenryfirst,项目名称:thecyclops,代码行数:39,代码来源:24_calculating_frame_rate.cpp

示例13: 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;

			//Angle of rotation
			double degrees = 0;

			//Flip type
			SDL_RendererFlip flipType = SDL_FLIP_NONE;

			//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;
					}
					else if( e.type == SDL_KEYDOWN )
					{
						switch( e.key.keysym.sym )
						{
							case SDLK_a:
							degrees -= 60;
							break;
							
							case SDLK_d:
							degrees += 60;
							break;

							case SDLK_q:
							flipType = SDL_FLIP_HORIZONTAL;
							break;

							case SDLK_w:
							flipType = SDL_FLIP_NONE;
							break;

							case SDLK_e:
							flipType = SDL_FLIP_VERTICAL;
							break;
						}
					}
				}

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

				//Render arrow
				gArrowTexture.render( ( SCREEN_WIDTH - gArrowTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gArrowTexture.getHeight() ) / 2, NULL, degrees, NULL, flipType );

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

	//Free resources and close SDL
	close();

	return 0;
}
开发者ID:Stephen-Lamb,项目名称:Work,代码行数:84,代码来源:15_rotation_and_flipping.cpp

示例14: 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

示例15: 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;

			//The background scrolling offset
			int scrollingOffset = 0;

			//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 );
				}

				//Move the dot
				dot.move();

				//Scroll background
				--scrollingOffset;
				if( scrollingOffset < -gBGTexture.getWidth() )
				{
					scrollingOffset = 0;
				}

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

				//Render background
				gBGTexture.render( scrollingOffset, 0 );
				gBGTexture.render( scrollingOffset + gBGTexture.getWidth(), 0 );

				//Render objects
				dot.render();

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

	//Free resources and close SDL
	close();

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


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