[英]How to pass members of arrays as parameters in functions, C++
I'm relatively new to C++, and am trying to create a simple map for a game (I am using sfml). 我是C ++的新手,正在尝试为游戏创建一个简单的地图(我正在使用sfml)。
I'm creating an array of white rectangles, and I want to pass members of the array as arguments in function calls. 我正在创建一个白色矩形数组,我想将该数组的成员作为函数调用中的参数传递。
For example: 例如:
Sprite WallSprites[10];
for (int i = 0; i < 10; i++) {
WallSprites[i].setTexture(Wall);
WallSprites[i].scale(0.3, 0.6);
}
WallSprite[0].setPosition(400,300);
while (window.isOpen())
{
window.clear();
window.draw(WallSprite[0]);
window.display();
}
The code above won't compile, and I'm not sure how to proceed from here. 上面的代码无法编译,我不确定如何从此处继续。 I'm pretty sure I'm not implementing the concepts correctly;
我敢肯定我没有正确实现这些概念。 any help would be greatly appreciated.
任何帮助将不胜感激。 Thanks!
谢谢!
I notice that you have a typo in your code that would prevent it from compiling: 我注意到您的代码中有一个错字,这会阻止它的编译:
WallSprite[0].setPosition(400,300);
while(window.isOpen())
{
window.clear();
window.draw(WallSprite[0]);
window.display();
}
Should be: 应该:
WallSprites[0].setPosition(400,300); // Forgot the 's' in 'WallSprites'
while(window.isOpen())
{
window.clear();
window.draw(WallSprites[0]); // Forgot the 's' in 'WallSprites'
window.display();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.