【发布时间】:2019-09-14 21:48:46
【问题描述】:
我刚刚使用了 SDL_SetRenderDrawColor(ren, 255,0,0,255);
对于 SDL_Rect rec 但未更改颜色,窗口使用 SDL_RenderPresent(ren) 以黑色呈现;
还需要使用什么吗?可能是 SDL_RenderCopy?
有人知道发生了什么吗?
#include "game.h"
Game::Game(){
SDL_Init(0);
SDL_CreateWindowAndRenderer(800, 600, 0, &win, &ren);
SDL_SetWindowTitle(win, "Game-SDL2");
running=true;
count=0;
loop();
}
Game::~Game(){
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
}
void Game::loop(){
while(running){
lastFrame = SDL_GetTicks();
int static lastTime;
if (lastFrame >= (lastTime+1000))
{
lastTime=lastFrame;
frameCount=0;
count++;
}
render();
input();
update();
if (count > 3) running=false;
}
}
void Game::render(){
SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
SDL_Rect rect;
rect.x, rect.y=0;
rect.w=800;
rect.h=600;
SDL_RenderFillRect(ren, &rect);
frameCount++;
int timerFPS = SDL_GetTicks()-lastFrame;
if (timerFPS > (1000/60)){
SDL_Delay((1000/60)-timerFPS);
}
SDL_RenderPresent(ren, &rect);
}
【问题讨论】: