SFML 2.1使用矢量创建多个精灵的完整说明
SFML 2.1 Full Explanation of using Vectors to create multiple Sprites
我在代码块中使用SFML 2.1,我不知道如何使用Vectors来克隆我的小行星精灵。它一直说,尚未声明星号_V,并弹出一个警告框,称其"在所选编码中使用非法字符",并且"更改这些字符是为了保护[我]不丢失数据"。
该程序的目标是连续创建小行星精灵,这些精灵将在屏幕上方的随机点生成,然后直接下降。程序中还有其他精灵和方面,但我从这篇文章中删除了它们,以适当地浓缩它。这似乎是唯一的问题。
int n;
int main()
{
RenderWindow window;
window.setFramerateLimit(30);
RenderWindow mainMenu;
srand( time(0));
Texture asteroid_Pic;
asteroid_Pic.loadFromFile("Asteroid.png");
std::vector<sf::Sprite> asteroid(n, Sprite(asteroid_Pic));
for (int i = 0; i < asteroid.size(); i++){
asteroid[n].setOrigin(15, 15);
asteroid[n].getPosition();
asteroid[n].setPosition(x = rand() % 790 + 10, y = rand() % -10 - 50);
}
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == Event::Closed){
window.close();
}
asteroid[n].setPosition(x, y+=1);
asteroid[n].rotate(1);
// clear the window with black color
window.clear(Color::Black);
// draw everything here...
// window.draw(...);
window.draw(player1);
window.draw(asteroid[n]);
// end the current frame
window.display();
}
return 0;
}
您的主循环中有另一个while (window.isOpen())
。你的程序将进入主循环,然后永远不会离开那个内部循环。它永远不会至少画一次。
您需要摆脱内部的while (window.isOpen())
循环,并找到另一种方法。
虽然最初的问题是关于计时器的,但你可以在这里找到游戏循环的基本解释。如果你想根据时间做一些事情(移动精灵,创建新的ingame实体),你必须在循环中处理时间。
相关文章:
- 当使用通配符和null指针调用函数时,对输出的说明
- 关于C++中具有多重继承"this"指针的说明
- 16 位到 10 位转换代码说明
- C++ 基本 CTOR 说明 - 为什么不调用赋值/复制构造函数
- OpenGL 着色器不绘制任何东西 - 糟糕的精灵类
- 编译器指出结构和 int 说明的错误 2059
- 随机数生成函数说明
- 从精灵表在 sfml 中为精灵制作动画
- 赋值到类型和空大括号. 语法说明
- C++ switch 语句:对案例进行分组,并针对每个案例给出特定的说明
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- std::extent 实现详细信息说明
- 您好,我实际上想了解以下代码.有人可以详细说明代码它到底在做什么吗?为什么它会在第 31 行崩溃
- 如何理解"Temporary objs are destroyed as the last step in evaluating the full-expression"?谁能用一些简单的例子来说明这
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 有没有办法在c ++中清除空数组,请检查下面的代码以获取说明
- 使用英特尔内部函数 (AVX) 中的混合说明
- AABB 碰撞使实际精灵的大小翻倍
- 如何在精灵表上的两个不同部分之间来回切换,同时用户仍使用 SFML 持有密钥
- SFML 2.1使用矢量创建多个精灵的完整说明