我正在使用 SDL 在 c++ 中制作一个类似 Yahtzee 的(带有得分的骰子游戏)。这是我自己开发的第一个 SDL 项目。
问题可以描述为:当我开始游戏时,文本渲染良好。我可以得分并继续比赛。但是,如果我等待几分钟(无论我是否还在玩),文本最终会停止呈现。我可以继续游戏,但是没有文字显示,之前显示的文字也不再显示。
我对这个问题完全感到困惑。直到现在才发生,因为之前的比赛都没有足够长的时间让我注意到。
注意:我偶然发现的一件事是软件和硬件渲染。我不知道为什么,但我尝试使用硬件进行渲染,但这并没有解决问题。
另一个注意事项:代码的文本渲染部分接近结尾,在一个 for 循环中。
我迷路了,有人能帮帮我吗?我会发布代码,但它很长,很荒谬,我认为这不是问题。
int GUI(State& GameState)
{
apply_surface( 0, 0, background, screen ); //background
apply_surface( SCORE_X, SCORE_Y, scoreImage, screen ); //score card
apply_surface( KEPT_TRAY_X, KEPT_TRAY_Y, keptTray, screen ); //kept tray
apply_surface( TEXT_BOX_X, TEXT_BOX_Y, textBox, screen ); //text box
//Blatantly handles only the next event on the queue per frame
if( SDL_PollEvent( &event ) )
eventHandler(GameState);
//place button
if(GameState.placeButtonClicked)
{
apply_surface( GameState.buttonV[GameState.placeButtonClicked].x, GameState.buttonV[GameState.placeButtonClicked].y, clickedButton, screen );
}
//dice[1]
apply_surface( *GameState.diceV[1].pointX, *GameState.diceV[1].pointY, *GameState.diceV[1].surfaceValue, screen );
//dice[2]
apply_surface( *GameState.diceV[2].pointX, *GameState.diceV[2].pointY, *GameState.diceV[2].surfaceValue, screen );
//dice[3]
apply_surface( *GameState.diceV[3].pointX, *GameState.diceV[3].pointY, *GameState.diceV[3].surfaceValue, screen );
//dice[4]
apply_surface( *GameState.diceV[4].pointX, *GameState.diceV[4].pointY, *GameState.diceV[4].surfaceValue, screen );
//dice[5]
apply_surface( *GameState.diceV[5].pointX, *GameState.diceV[5].pointY, *GameState.diceV[5].surfaceValue, screen );
//rollButton
if(GameState.navV[1].clicked)
{
apply_surface( GameState.navV[1].x, GameState.navV[1].y, rollButtonClicked, screen);
}
else
{
apply_surface( GameState.navV[1].x, GameState.navV[1].y, rollButton, screen );
}
//endTurnButton
if(GameState.navV[2].clicked)
{
apply_surface( GameState.navV[2].x, GameState.navV[2].y, endTurnButtonClicked, screen );
}
else
{
apply_surface( GameState.navV[2].x, GameState.navV[2].y, endTurnButton, screen );
}
//displaying the clickedButton if a score is clicked
if(GameState.placeButtonClicked != 0)
{
apply_surface( GameState.buttonV[GameState.placeButtonClicked].x, GameState.buttonV[GameState.placeButtonClicked].y, clickedButton, screen );
}
//displaying the scores for each "button" (each score segment)
for(int i = 1; i <= (GameState.buttonV.size() - 1); i++)
{
if(GameState.buttonV[i].value >= 0)
{
message = TTF_RenderText_Solid( scoreFont, GameState.buttonV[i].valueString, scoreFontColor );
apply_surface( GameState.buttonV[i].x + 10, GameState.buttonV[i].y + 2, message, screen );
}
}
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
decGUICounters(GameState);
return 0;
}