- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我希望我的问题不总是同一个问题。我有一个 QGraphicsScene。它的项目是一些 QGraphicsPixmaps。我用一个计时器移动它们,每秒执行一次 SetX +10。我设置了 +10,因为窗口很大 100。使用此解决方案,我的动画效果不流畅。我想我可以通过将 +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);
}
}
}
}
在我的程序的核心部分,每个 Actor 都是我的游戏角色(在他的功能中,例如移动 ecc)。 sceneItems 是一张 map ,我将每个 Actor 关联到他的像素图。 x, y 是抽象场景中的位置,x*SIZE 是图形场景中的位置。这些位置在抽象场景中更新,我在图形场景中表示它们。
最佳答案
我用这种方法为我的 QGraphicItems 设置了动画:
“QGraphicsItemAnimation 类为 QGraphicsItem 提供了简单的动画支持。” 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();
关于c++ - 使用 QGraphicsScene 平滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8533499/
再会! 对于 Qt 4.7.3,下面的示例在 QGraphicsScene::~QGraphicsScene() 调用时崩溃: #include #include int main( int ar
我正在尝试将图像添加到 QGraphicsView/QGraphicsScene 以便稍后我可以根据用户的输入在其上绘制简单的几何图形。我需要确保图像适合 QGraphicsView 而不管其纵横比如
根据 Qt 规范 QGraphicsScene 是一个viewless QGraphicsItems 的数据模型。 我有一个可以在窗口和非窗口模式下使用的工具 (当为其提供命令行参数时)。 在非窗口模
我有一个 QGraphicsScene上面有图形和文字。当我尝试打印时,图形很好,但文本使用以磅为单位定义的字体大小,因此 scene->render()当我通过它时 QPainter用 QPrint
他们想在按下和移动鼠标按钮时拖动这条贝塞尔曲线.. 我这样做了: void MainWindow::mouseMoveEvent(QMouseEvent *e) { qDebug()buttons()
使用下面的代码片段,我创建了一个包含 100.000 个矩形的场景。 表现不错; View 响应没有延迟。 QGraphicsScene * scene = new QGraphicsScene; f
我试图了解如何在 QGraphicsScene 中重新定义选择和转换项目(一旦选择)的方式。 .例如改变一条线的长度,移动一条线,通过移动一个点来改变一个多边形。 我创建了一个 QGraphicsVi
我正在使用 QGraphicsScene 类。如何检测鼠标离开 QGraphicsScene ?是否有任何内部函数可以实现此目的? 最佳答案 如果您想检测释放事件,您必须覆盖 mouseRelease
我有一个小部件,它分为两个子小部件。一个显示图片,另一个提供编辑图片的选项。图片子部件的水平空间应是编辑子部件的 5 倍。我在网格布局中指定此约束。但是,一旦我将 QGraphicsScene(和 V
我创建了一个小应用程序,我试图使其在调整主窗口大小(GraphicsView 和场景也是如此)时整个场景(像素图和矩形)垂直缩放以完全适合内部图形 View 。我不想要垂直滚动条,也不希望它水平缩放。
我有一个 QGraphicsScene,我已经确定了我的中心点在哪里,但我现在需要弄清楚如何根据该信息将我的项目放置在场景中。 我有 2 条数据需要处理:距离和方位。 Range 显然是距离中心点(或
我想在我的主窗口中跟踪鼠标。我在 QGraphicsView 中启用了 moustracking这是 GraphicsView 子类的构造函数,其余是默认行为。 GraphicsView::Graph
我有一个非常简单的 QGraphicsScene 派生类: class SceneComponent : public QGraphicsScene { Q_OBJECT public:
我正在尝试使用 qgraphicsview qgraphicsitem 来创建像国际象棋一样的场景。 我正在按照官方示例尝试创建它,但没有显示任何内容。代码几乎是一样的。首先,我想知道是我的 Cell
我正在尝试将 QgraphicsView(QColorDialog) 小部件添加到 Palette 对话框中,但是 QGraphicsScene 对应于 QColorDialog 小部件总是空白,如果
我有这样的程序:在我的小部件中,我有 qpushbuttons、qslider 和 qgraphicsview。我将 qgraphicsscene 放在 qgraphicsview 中。问题是,当我在
我正在创建一个显示 QGraphicsScene 的 QGraphicsView。 我将场景的背景设置为 QImage 位图,其中: scene()->setBackgroundBrush(myQIm
我有一个从某个位置向上移动的椭圆。 void Equalizer::advance(int phase) { if(!phase) return; QPointF location =
我的目标: 我想在 QGraphicsView 上的位置 x = 0,y = 0 处绘制一个长度和宽度为 100 的简单矩形。那应该看起来像这样 到目前为止我做了什么我在主页(MainWindow)的
我正在 Qt 5.1 中编写一个小型 CAD 应用程序,我正在尝试弄清楚如何使 QGraphicsScene 的坐标与真实世界的尺寸相对应。例如,我打算将坐标保持在其原始形式(值,单位),以便在从毫米
我是一名优秀的程序员,十分优秀!