本文整理汇总了C++中Entity::DrawText方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::DrawText方法的具体用法?C++ Entity::DrawText怎么用?C++ Entity::DrawText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity::DrawText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
void Menu::Draw(bool nextImg, SDL_Surface *screen)
{
//Move the objects before drawing.
for (unsigned int i = PhysicObjects.size(); i; i-- )
{
PhysicObject* tempObj = PhysicObjects.front();
PhysicObjects.pop_front();
tempObj->Move(PhysicObjects);
PhysicObjects.push_back(tempObj);
}
//Draw the background.
SDL_Rect *pos = new SDL_Rect;
pos->x = 0;
pos->y = 0;
SDL_BlitSurface( background, NULL, screen, pos);
//Draw the enities.
for (unsigned int i = Entities.size(); i; i-- )
{
Entity* tempEnt = Entities.front();
Entities.pop_front();
tempEnt->Draw(nextImg, screen);
if (tempEnt->getVisible())
tempEnt->DrawText(screen);
Entities.push_back(tempEnt);
}
}
示例2: main
int main(int argc, char *argv[]) {
Matrix projectionMatrix;
Matrix modelMatrix;
Matrix viewMatrix;
init();
ShaderProgram program(RESOURCE_FOLDER "vertex_textured.glsl", RESOURCE_FOLDER "fragment_textured.glsl");
glUseProgram(program.programID);
float lastFrameTicks = 0.0f;
// float vertices[] = {-0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5};
// float texCoords[] = {0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0};
// float vertices[] = {-0.09, -0.09, 0.09, -0.09, 0.09, 0.09, -0.09, -0.09, 0.09, 0.09, -0.09, 0.09};
Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 4096 );
SDL_Event event;
bool done = false;
/* Sprites courtesy of http://gooperblooper22.deviantart.com/art/Space-Invaders-Sprite-Sheet-135338373 */
GLuint spriteSheetTexture = LoadTexture("space_invaders_sprite_sheet_by_gooperblooper22.png");
GLuint white = LoadTexture("white.png");
GLuint textTexture = LoadTexture("font1.png");
Mix_Music *bgm = Mix_LoadMUS("bgm.mp3");
Mix_Chunk *missile = Mix_LoadWAV("157439__nengisuls__misslie-1.wav");
bool pressed = false;
int score = 0;
int currentIndex = 0;
int state;
const int numFrames = 2;
float animation[] = {(74.0f/617.0f),(107.0f/617.0f)};
float animationElapsed = 0.0f;
float framesPerSecond = 0.0004f;
std::vector<SheetSprite> aliens;
while (!done) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
done = true;
}
}
program.setProjectionMatrix(projectionMatrix);
program.setModelMatrix(modelMatrix);
program.setViewMatrix(viewMatrix);
float ticks = (float)SDL_GetTicks()/1000;
float elapsed = ticks - lastFrameTicks;
lastFrameTicks = ticks;
animationElapsed += 1/elapsed;
if(animationElapsed > 1.0/framesPerSecond) {
currentIndex++;
animationElapsed = 0.0;
if(currentIndex > numFrames-1) {
currentIndex = 0;
}
}
glClear(GL_COLOR_BUFFER_BIT);
score = ticks;
SheetSprite menu(spriteSheetTexture, 160.0f/617.0f, 1.0f/2035.0f, 250.0f/617.0f, 171.0f/2035.0f, 0.5);
Entity text;
Player cannon(spriteSheetTexture, 277.0f/617.0f, 227.0f/2035.0f, 26.0f/617.0f, 17.0f/2035.0f, 0.05);
SheetSprite alien(spriteSheetTexture, animation[currentIndex], (225.0f/2035.0f), 22.0f/617.0f, 16.0f/2035.0f, 0.05);
const Uint8 *keys = SDL_GetKeyboardState(NULL);
switch (state) {
case STATE_MAIN_MENU:
menu.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, true);
menu.draw(program);
if (!Mix_PlayingMusic()) {
Mix_PlayMusic(bgm, -1);
}
if (keys[SDL_SCANCODE_RETURN]) {
state++;
}
break;
case STATE_GAME_LEVEL:
text.DrawText(program, textTexture, "Score:" + std::to_string(score), 0.075, 0, -0.23, 0.9);
cannon.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, white, alien);
cannon.draw(program);
alien.update(lastFrameTicks, elapsed, projectionMatrix, viewMatrix, program, false);
alien.draw(program);
if (keys[SDL_SCANCODE_SPACE]) {
Mix_PlayChannel( -1, missile, 0);
Mix_VolumeChunk(missile, 15);
}
if (keys[SDL_SCANCODE_ESCAPE] && (state == 1)) {
pressed = true;
state++;
}
break;
case STATE_PAUSE:
if (Mix_PlayingMusic()) {
Mix_PausedMusic();
}
text.DrawText(program, textTexture, "Paused", 0.1, 0, -0.23, 0);
//.........这里部分代码省略.........