如何使用指针返回指针数组中的特定值?

问题描述 投票:0回答:0

我用SDL2/C++来显示一张图片,如果玩家按下箭头键(上、下、左、右),它会显示相应的“上”、“下”、“左”、“右”图片”。 我正在使用“loadTexture()”函数将图像加载为纹理。

如果我将“loadTexture()”函数和按键函数(使用 SDL_PollEvent)放在 main() 中,程序就可以运行。但是,当我将上述两个函数从 main() 中推出时,main() 函数会报错,因为它没有接收到来自“loadTexture()”函数的输入。

This is loadTexture() fuction (getRenderer() fuction only returns the SDL_Renderer value in my Game class). This fuction output is an array of SDL_Texture, which is an array of pointers

And this is my main gameloop in main() fuction. The red-underline required a SDL_Texture from loadTexture() fuction.

我试图创建一个指向纹理数组的指针,但它不起作用。 如果它完美运行,按键功能将接收纹理的特定值。 (例如,“Left_button_pressed”命令需要接收纹理[3],这是从“Left.png”图像加载的纹理) 那么,我该如何解决呢?

c++ arrays pointers visual-c++ sdl-2
© www.soinside.com 2019 - 2024. All rights reserved.