Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用QGraphicscene平滑动画_C++_Qt_Qgraphicsscene - Fatal编程技术网

C++ 使用QGraphicscene平滑动画

C++ 使用QGraphicscene平滑动画,c++,qt,qgraphicsscene,C++,Qt,Qgraphicsscene,我希望我的问题不总是同一个问题。 我有一个小女孩。 它的项目是一些QGraphicsPixmaps。 我用一个计时器移动它们,每秒钟设置x+10。 我设置+10,因为窗口大100。 使用此解决方案,我的动画不会平滑。我想我可以通过设置而不是+10a+1…+10使它们更平滑。但它不起作用 你能给我一个建议吗? 非常感谢 void GameGui::updateScene() { for (int y = 0; y < game->getHeight(); ++y) { for

我希望我的问题不总是同一个问题。 我有一个小女孩。 它的项目是一些QGraphicsPixmaps。 我用一个计时器移动它们,每秒钟设置x+10。 我设置+10,因为窗口大100。 使用此解决方案,我的动画不会平滑。我想我可以通过设置而不是+10a+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);
        }
    }
}
}
void GameGui::updateScene()
{
对于(int y=0;ygetHeight();++y){
对于(intx=0;xgetWidth();++x){
演员*a=游戏->获得(y,x);
如果(场景项[a]!=0){
场景项[a]->setX(x*大小);
场景项[a]->setY(y*尺寸);
}
}
}
}

在我的程序的核心部分,每个演员都是我的游戏角色(在他的功能中,例如移动ecc)。sceneItems是一个地图,我将每个演员与他的pixmap关联起来。x、 y是抽象场景中的位置,x*SIZE是图形场景中的位置。位置在抽象场景中更新,我在图形场景中表示它们。

我用这种方法设置了QGraphicItems的动画:

“QGraphicsItemAnimation类为QGraphicsItem提供简单的动画支持。”

链接站点的示例:

 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();
QGraphicsItem*ball=新的QGraphicsEllipseItem(0,0,20,20);
QTimeLine*定时器=新的QTimeLine(5000);
定时器->设置帧范围(0,100);
QGraphicsSiteManimation*动画=新的QGraphicsSiteManimation;
动画->设置项(球);
动画->设置时间线(计时器);
对于(int i=0;i<200;++i)
动画->setPosAt(i/200.0,QPointF(i,i));
qgraphicscene*场景=新的qgraphicscene();
场景->设置场景(0,0,250,250);
场景->附加项(球);
QGraphicsView*视图=新的QGraphicsView(场景);
查看->显示();
定时器->启动();

将计时器设置为100毫秒间隔,每次执行+1。不幸的是,这在Qt 5中已过时。它已被一个新的更通用的动画框架所取代: