但是我不能让一个简单的开始菜单工作。我一直在尝试调用void函数,使用switch和简单的if语句……如何在raylib中使用switch或if语句创建一个简单的菜单,而不用关闭并打开程序的一个新窗口?我猜是在While循环中的某个地方?
#include"raylib.h"intmain(void){//Initialization//--------------------------------------------------------------------------------------constintscreenWidth=800;constintscreenHeight=450;InitWindow(screenWidth,screenHeight,"raylib[core]example-basicwindow");SetTargetFPS(60);//Setourgametorunat60frames-per-second//--------------------------------------------------------------------------------------//Maingameloopwhile(!WindowShouldClose())//DetectwindowclosebuttonorESCkey{BeginDrawing();ClearBackground(RAYWHITE);DrawText("Congrats!Youcreatedyourfirstwindow!",190,200,50,LIGHTGRAY);EndDrawing();if(IsKeyPressed(KEY_Q))DrawText("Newthinghere",200,210,60,GREEN);if(IsKeyPressed(KEY_W))DrawText("Newthingherenumbertwo",200,210,60,BLACK);}//----------------------------------------------------------------------------------CloseWindow();return0;}我一直在尝试中断、暂停和转到一些东西,我如何在不关闭窗口的情况下结束While循环,我需要更改while循环的语句吗?
如果我没弄错的话,你想在游戏开始前看到一个菜单。您可以在同一窗口中实现这一点,而不是尝试启动一个新窗口。
现在,确切的解决方案将根据您制作的游戏类型而变化,但我能想到的最简单的解决方案是在while循环中使用if语句来检查我们是否在菜单中。它可能看起来像这样。