我用SDL2/C++来显示一张图片,如果玩家按下箭头键(上、下、左、右),它会显示相应的“上”、“下”、“左”、“右”图片”。 我正在使用“loadTexture()”函数将图像加载为纹理。
如果我将“loadTexture()”函数和按键函数(使用 SDL_PollEvent)放在 main() 中,程序就可以运行。但是,当我将上述两个函数从 main() 中推出时,main() 函数会报错,因为它没有接收到来自“loadTexture()”函数的输入。
我试图创建一个指向纹理数组的指针,但它不起作用。 如果它完美运行,按键功能将接收纹理的特定值。 (例如,“Left_button_pressed”命令需要接收纹理[3],这是从“Left.png”图像加载的纹理) 那么,我该如何解决呢?