gpt4 book ai didi

c++ - SDL 游戏在加载二级时卡住

转载 作者:行者123 更新时间:2023-11-28 06:57:19 26 4
gpt4 key购买 nike

我的游戏的第一个关卡可以正确构建和播放,当我更改源文件以使其首先加载时,我的第二个关卡也是如此。但是,当我完成第一关并加载第二关时,游戏卡住了。具体来说,所有图像(字符、背景等)都可以正常渲染,但它们无法移动,并且控件没有任何响应(但是,调试确实显示按键仍在注册中)。

我认为最有可能导致问题的文件是我的 GameScreenManager.ccp。

#include "GameScreenManager.h"
#include "GameScreenLevel1.h"
#include "GameScreenLevel2.h"
#include "GameScreen.h"

GameScreenManager::GameScreenManager(SDL_Renderer* renderer, SCREENS startScreen)
{
mRenderer = renderer;
mCurrentScreen = NULL;

//Ensure first screen is set up.
ChangeScreen(startScreen);
}

GameScreenManager::~GameScreenManager()
{
mRenderer = NULL;
delete mCurrentScreen;
mCurrentScreen = NULL;
}

void GameScreenManager::Update(float deltaTime, SDL_Event e)
{
if(mCurrentScreen != NULL)
{
mCurrentScreen->Update(deltaTime, e);
}

//Check if Level 1 is completed
CompleteCheck();
}

void GameScreenManager::Render()
{
if(mCurrentScreen != NULL)
{
mCurrentScreen->Render();
}
}

void GameScreenManager::ChangeScreen(SCREENS startScreen)
{
//Clear up the old screen.
if(mCurrentScreen != NULL)
{
delete mCurrentScreen;
}
GameScreenLevel1* tempScreen;
GameScreenLevel2* tempScreen2;
switch(startScreen)
{
case SCREEN_LEVEL1:
tempScreen = new GameScreenLevel1(mRenderer);
mCurrentScreen = (GameScreen*)tempScreen;
tempScreen = NULL;
break;
case SCREEN_LEVEL2:
tempScreen2 = new GameScreenLevel2(mRenderer);
mCurrentScreen = (GameScreen*)tempScreen2;
tempScreen2 = NULL;
break;
}
}

void GameScreenManager::CompleteCheck()
{
if(GameScreenLevel1::complete)
{
ChangeScreen(SCREEN_LEVEL2);
}
}

有人认为他们可以发现问题吗?

最佳答案

if(GameScreenLevel1::complete)
{
ChangeScreen(SCREEN_LEVEL2);
}

似乎总是如此。您需要在加载第二个级别后将其设置为 false。

关于c++ - SDL 游戏在加载二级时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22999813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com