#include "qquickspriteengine_p.h"
#include <QtQuick/private/qsgcontext_p.h>
#include <private/qsgadaptationlayer_p.h>
+#include <private/qqmlglobal_p.h>
#include <QtQuick/qsgnode.h>
#include <QtQuick/qsgtexturematerial.h>
#include <QtQuick/qsgtexture.h>
-#include <QtQuick/qquickcanvas.h>
+#include <QtQuick/qquickwindow.h>
#include <QtQml/qqmlinfo.h>
#include <QFile>
#include <cmath>
\qmlclass AnimatedSprite QQuickAnimatedSprite
\inqmlmodule QtQuick 2
\inherits Item
+ \ingroup qtquick-visual
\brief Draws a sprite animation
AnimatedSprite provides rendering and control over animations which are provided
frame rate of your display, or manually advance and control the progress.
For details of how a sprite animation is defined see the \l{Sprite Animation} overview.
- Note that the AnimatedSprite element does not use Sprite elements to define multiple animations,
+ Note that the AnimatedSprite type does not use Sprite types to define multiple animations,
but instead encapsulates a single animation itself.
*/
this, SLOT(sizeVertices()));
}
+bool QQuickAnimatedSprite::isCurrentFrameChangedConnected()
+{
+ IS_SIGNAL_CONNECTED(this, QQuickAnimatedSprite, currentFrameChanged, (int));
+}
+
void QQuickAnimatedSprite::reloadImage()
{
if (!isComponentComplete())
void QQuickAnimatedSprite::start()
{
- if (m_running)
+ m_running = true;
+ if (!isComponentComplete())
return;
m_curLoop = 0;
m_timestamp.start();
m_spriteEngine->updateSprites(0);
m_spriteEngine->start(0);
}
- m_running = true;
+ emit currentFrameChanged(0);
emit runningChanged(true);
update();
}
void QQuickAnimatedSprite::stop()
{
- if (!m_running)
- return;
m_running = false;
+ if (!isComponentComplete())
+ return;
m_pauseOffset = 0;
emit runningChanged(false);
}
if (image.isNull())
return 0;
m_sheetSize = QSizeF(image.size());
- m_material->texture = canvas()->createTextureFromImage(image);
+ m_material->texture = window()->createTextureFromImage(image);
m_material->texture->setFiltering(QSGTexture::Linear);
m_spriteEngine->start(0);
m_material->animT = 0;
AnimatedSpriteVertices *p = (AnimatedSpriteVertices *) g->vertexData();
- p->v1.tx = 0;
- p->v1.ty = 0;
+ QRectF texRect = m_material->texture->normalizedTextureSubRect();
- p->v2.tx = 1.0;
- p->v2.ty = 0;
+ p->v1.tx = texRect.topLeft().x();
+ p->v1.ty = texRect.topLeft().y();
- p->v3.tx = 0;
- p->v3.ty = 1.0;
+ p->v2.tx = texRect.topRight().x();
+ p->v2.ty = texRect.topRight().y();
- p->v4.tx = 1.0;
- p->v4.ty = 1.0;
+ p->v3.tx = texRect.bottomLeft().x();
+ p->v3.ty = texRect.bottomLeft().y();
+ p->v4.tx = texRect.bottomRight().x();
+ p->v4.ty = texRect.bottomRight().y();
quint16 *indices = g->indexDataAsUShort();
indices[0] = 0;
double frameAt; //double just for modf
qreal progress = 0.0;
+ int lastFrame = m_curFrame;
if (!m_paused) {
//Advance State (keeps time for psuedostates)
m_spriteEngine->updateSprites(timeInt);
} else {
frameAt = m_curFrame;
}
+ if (m_curFrame != lastFrame && isCurrentFrameChangedConnected())
+ emit currentFrameChanged(m_curFrame);
if (m_spriteEngine->sprite()->reverse())
frameAt = (m_spriteEngine->spriteFrames() - 1) - frameAt;
qreal y = m_spriteEngine->spriteY() / m_sheetSize.height();