本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 );
}
示例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;
}
示例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;
}
}
示例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 );
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
//.........这里部分代码省略.........
示例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;
}