c++ - 无论如何使用矩形在 sfml 中创建动画
问题描述
有什么方法可以在 sfml 中创建动画。不是精灵表。但有 1 个矩形到另一个位置。 https://gyazo.com/0952a960bd7f9e5c9c5e1fe71d0f0b45 我想要类似的打孔效果。但我不知道从哪里开始。
有没有办法在 sfml 中制作流畅的动画?
解决方案
最优雅的方法是使用精灵表,但也可以不用。制作一个移动矩形位置并将其返回的 for 循环
float smoothness //try for your values
float directionX; //if negative punch left set values 1 or -1
float directionY; //if negative punch down set values 1 or -1
int reach;
for(int i=0;i<reach;i++)
{
rect.setPosition(
directionX*(rect.getPosition.x+smoothness)
,directionY*(rect.getPosition.y+smoothness))
}
//return to original position
for(int i=0;i<reach;i++)
{
rect.setPosition(
-directionX*(rect.getPosition.x+smoothness)
,-directionY*(rect.getPosition.y+smoothness))
}
注意: 请设置一个恒定的帧速率以使其正常工作
推荐阅读
- git - 设置 .cpanel.yml 文件以上传所有内容
- r - 在 if_else 和 df$ 中使用 rlang 将变量名作为字符串提供
- javascript - 在子文件夹中的 Vuejs 中全局注册组件
- r - 将 data.frame 的所有列合并为一个(向量连接)
- php - 如何根据下一行中的值更新单列
- regex - robots.txt 处理 URL 中的 #
- ios - reloadRowsAtIndexPath 防止 scrollToRowAtIndexPath
- java - 如何将其更改为仅数组?
- php - 找不到类“Twig_Test”
- jenkins - 当 Swagger-Diff 返回差异时让 Jenkins 失败