本文整理汇总了C++中Star::setTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ Star::setTexture方法的具体用法?C++ Star::setTexture怎么用?C++ Star::setTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Star
的用法示例。
在下文中一共展示了Star::setTexture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
TempSettings gamesettings;
gamesettings.mapw = 10;
gamesettings.maph = 6;
gamesettings.mapx = 0;
gamesettings.mapy = 0;
gamesettings.mapmidx = gamesettings.mapw/2.0;
gamesettings.mapmidy = gamesettings.maph/2.0;
gamesettings.window_width = 1300;
gamesettings.window_height = 800;
// initialize window, renderer, textures
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
std::cerr << "SDL_Init error: " << SDL_GetError() << std::endl;
return 1;
}
if (TTF_Init() != 0){
std::cerr << "TTF_Init error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
SDL_Window* window = SDL_CreateWindow("deathblade_floating", 0, 0, gamesettings.window_width, gamesettings.window_height, SDL_WINDOW_SHOWN);
if (window == nullptr){
std::cerr << "SDL_CreateWindow error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == nullptr){
std::cerr << "SDL_CreateRenderer error: " << SDL_GetError() << std::endl;
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
std::string resource_path = getResourcePath("");
std::string charfile = resource_path + "initialcharacter.png";
std::string bgfile = resource_path + "initialbackgroundtile.png";
std::string starfile = resource_path + "star.png";
std::string wallfile = resource_path + "wall.png";
SDL_Texture* character_texture = IMG_LoadTexture(renderer, charfile.c_str());
SDL_Texture* bgtile_texture = IMG_LoadTexture(renderer, bgfile.c_str());
SDL_Texture* star_texture = IMG_LoadTexture(renderer, starfile.c_str());
SDL_Texture* wall_texture = IMG_LoadTexture(renderer,wallfile.c_str());
if (character_texture == nullptr || bgtile_texture == nullptr || star_texture == nullptr || wall_texture == nullptr){
std::cerr << "IMG_LoadTexture error: " << SDL_GetError() << std::endl;
SDL_DestroyTexture(character_texture);
SDL_DestroyTexture(bgtile_texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
std::string fontfile = resource_path + "sample.ttf";
TTF_Font* font = TTF_OpenFont(fontfile.c_str(), 15);
if (font == NULL){
std::cerr << "TTF_OpenFont error: " << SDL_GetError() << std::endl;
}
CameraControl camera(&gamesettings);
ObjectController objects;
DeveloperConsoleClass console(&gamesettings);
console.add_controller(&console);
console.add_controller(&camera);
const double tilew = 0.5;
const double tileh = 0.5;
double mousex = gamesettings.mapmidx;
double mousey = gamesettings.mapmidy;
int mousepx = gamesettings.window_width/2;
int mousepy = gamesettings.window_height/2;
double wallthickness = 0.1;
TextureWall bottomwall, topwall, leftwall, rightwall;
bottomwall.x = gamesettings.mapw/2;
bottomwall.y = gamesettings.maph+wallthickness/2;
bottomwall.setTexture(wall_texture,gamesettings.mapw,wallthickness);
objects.add_object(&bottomwall);
topwall.x = gamesettings.mapw/2;
topwall.y = -wallthickness/2;
topwall.setTexture(wall_texture,gamesettings.mapw,wallthickness);
objects.add_object(&topwall);
leftwall.x = -wallthickness/2;
leftwall.y = gamesettings.maph/2;
leftwall.setTexture(wall_texture,wallthickness,gamesettings.maph);
objects.add_object(&leftwall);
rightwall.x = gamesettings.mapw + wallthickness/2;
rightwall.y = gamesettings.maph/2;
rightwall.setTexture(wall_texture,wallthickness,gamesettings.maph);
objects.add_object(&rightwall);
//.........这里部分代码省略.........