平滑动画与QGraphicsScene
Smooth animations with QGraphicsScene
我希望我的问题不总是同样的问题。我有一个QGraphicsScene。它的项是一些QGraphicsPixmaps。我用计时器移动它们,每秒执行SetX +10。我设置+10是因为窗口很大。使用这个解决方案,我的动画并不流畅。我认为我可以通过设置+10而不是+1…+10来使它们更平滑。但这并没有奏效。
你能给我一个建议吗?非常感谢。void GameGui::updateScene()
{
for (int y = 0; y < game->getHeight(); ++y) {
for (int x = 0; x < game->getWidth(); ++x) {
Actor* a = game->get(y, x);
if (sceneItems[a] != 0) {
sceneItems[a]->setX(x*SIZE);
sceneItems[a]->setY(y*SIZE);
}
}
}
}
每个演员都是我的游戏角色(在他的功能,如移动ecc)在我的核心部分的程序。sceneItems是一个地图,我将每个演员与他的像素图联系起来。x, y是抽象场景中的位置,x*SIZE是图形场景中的位置。位置在抽象场景中更新,我在图形场景中表示它们
我用这种方法动画了我的QGraphicItems:
" QGraphicsItemAnimation类为qgraphicsitemem提供了简单的动画支持。"http://doc.qt.io/qt - 4.8 -/- qgraphicsitemanimation.html
链接站点示例:
QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);
QTimeLine *timer = new QTimeLine(5000);
timer->setFrameRange(0, 100);
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
animation->setItem(ball);
animation->setTimeLine(timer);
for (int i = 0; i < 200; ++i)
animation->setPosAt(i / 200.0, QPointF(i, i));
QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0, 0, 250, 250);
scene->addItem(ball);
QGraphicsView *view = new QGraphicsView(scene);
view->show();
timer->start();
相关文章:
- QGraphicsItems not showing up QGraphicsScene
- Qt QGraphicsProxyWidget 与 QGraphicsScene 的交互
- Qt将许多QGraphicsPixmapItem添加到QGraphicsScene中
- QGraphicsScene 中的 QPushButton 需要双击而不是单击
- 在 QWidget 中的 QGraphicsScene 中绘制
- 在 QGraphicsScene 中组织项目
- QGraphicsItem::p aint(): 如何检查 QGraphicsScene 是否已打印
- 子类QGraphicsScene的错误
- QGraphicsScene项目在两次(x2)位置绘制
- 图形项目的QgraphicsScene中的可拖动像素
- Qt中是否有QLabel::setScaledContent等效函数用于QGraphicsScene?
- 无法读取 QGraphicsScene 的内容
- 围绕QgraphicsScene移动QGraphicsView
- 有没有办法停止QGraphicsScene
- 如何在QGraphicsScene上绘制填充多边形
- Qt QGraphicsScene::setSceneRect() 实际上并没有设置场景 rect
- Qt Application with QTabWidget, QGraphicsScene and QPushButt
- Qt - QGraphicsScene 和 QGraphicsView 不更新更改?
- 为什么不能从 QVector 将 Item 添加到 QGraphicsScene <QGraphicsItem>中?
- 将QGraphicsScene嵌入QML中