sfml如何让一个形状移动到某个点
Sfml how to make a shape move to a certain point
我在执行插值以将对象移动到屏幕上的某个点时遇到问题。
代码如下:
factor += timer.getElapsedTime().asSeconds() * speed;
for(int i = 0; i < 50; i++) {
circleObjectArray[i].setPosition(Interpolate(movePositionsX[rand() % 5], movePositionsY[rand() % 5], factor));
window.draw(circleObjectArray[i]);
}
我想使用插值函数的这个主体,但我无法调用它
sf::Vector2f Interpolate(const sf::Vector2& pointA, const sf::Vector2& pointB, float factor) {
if(factor > 1.f)
factor = 1.f;
else if(factor < 0.f)
factor = 0.f;
return pointA + (pointB - pointA) * factor;
}
谢谢你的时间:D
你需要给你的形状移动时间。对于每个形状,您应该存储插值函数的三个输入。然后,每帧稍微更新一下因子,并通过使用存储的参数调用 Interpolate 来渲染它。例如,每帧增加 1/60 将使形状以 60 fps 的速度在一秒内完成一次完整的移动。
当因子达到 1 时,select 下一个过渡的新参数就像你现在做的那样,或者可能等待几帧 select 下一个目标。由你决定。
至于你的实际编译错误:sf::Vector2
是模板类型。你不能单独使用它。要么写 sf::Vector2<float>
,要么使用预定义的类型别名 sf::Vector2f
.
我在执行插值以将对象移动到屏幕上的某个点时遇到问题。
代码如下:
factor += timer.getElapsedTime().asSeconds() * speed;
for(int i = 0; i < 50; i++) {
circleObjectArray[i].setPosition(Interpolate(movePositionsX[rand() % 5], movePositionsY[rand() % 5], factor));
window.draw(circleObjectArray[i]);
}
我想使用插值函数的这个主体,但我无法调用它
sf::Vector2f Interpolate(const sf::Vector2& pointA, const sf::Vector2& pointB, float factor) {
if(factor > 1.f)
factor = 1.f;
else if(factor < 0.f)
factor = 0.f;
return pointA + (pointB - pointA) * factor;
}
谢谢你的时间:D
你需要给你的形状移动时间。对于每个形状,您应该存储插值函数的三个输入。然后,每帧稍微更新一下因子,并通过使用存储的参数调用 Interpolate 来渲染它。例如,每帧增加 1/60 将使形状以 60 fps 的速度在一秒内完成一次完整的移动。
当因子达到 1 时,select 下一个过渡的新参数就像你现在做的那样,或者可能等待几帧 select 下一个目标。由你决定。
至于你的实际编译错误:sf::Vector2
是模板类型。你不能单独使用它。要么写 sf::Vector2<float>
,要么使用预定义的类型别名 sf::Vector2f
.