diff --git a/examples/imagelayer/GameWindow.qml b/examples/imagelayer/GameWindow.qml index e52945a..1c2c4f1 100644 --- a/examples/imagelayer/GameWindow.qml +++ b/examples/imagelayer/GameWindow.qml @@ -40,7 +40,6 @@ QuasiGame { drawType: Quasi.TiledDrawType tileWidth: 32 tileHeight: 32 - animated: true source: ":/large_enough.png" horizontalStep: -5 layerType: Quasi.MirroredType @@ -63,7 +62,19 @@ QuasiGame { } Keys.onPressed: { - layer.animated = !layer.animated + if (event.key == Qt.Key_Right) { + if (layer.horizontalStep > 0) + layer.horizontalStep *= -1; + + layer.moveX(); + event.accepted = true; + } else if (event.key == Qt.Key_Left) { + if (layer.horizontalStep < 0) + layer.horizontalStep *= -1; + + layer.moveX(); + event.accepted = true; + } } } } diff --git a/src/imagelayer.cpp b/src/imagelayer.cpp index 6a49bb3..b28b2a6 100644 --- a/src/imagelayer.cpp +++ b/src/imagelayer.cpp @@ -32,9 +32,6 @@ ImageLayer::ImageLayer(Layer *parent) , m_areaToDraw(2.0) , m_columnOffset(0) , m_latestPoint(0) - , m_globalXPos(0.0) - , m_localXPos(0.0) - , m_localYPos(0.0) , m_initialized(false) { connect(this, SIGNAL(horizontalDirectionChanged()), @@ -353,24 +350,9 @@ void ImageLayer::drawPixmap() } // move to a X value -void ImageLayer::moveX(const qreal &x) +void ImageLayer::moveX() { - qreal newValue = x; - qreal delta = m_globalXPos + newValue; - - m_globalXPos = newValue * -1; - m_localXPos -= delta; - - if (m_localXPos <= -width()) { - drawPixmap(); - m_localXPos = width() + m_localXPos; - } else if (m_localXPos >= 0) { - if (m_globalXPos != 0) { - drawPixmap(); - m_localXPos = -width() + m_localXPos; - } else - m_localXPos = 0; - } + updateHorizontalStep(); } void ImageLayer::moveY(const qreal &y) @@ -412,9 +394,6 @@ void ImageLayer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option if (!m_currentImage) return; - if (m_isAnimated) - updateHorizontalStep(); - painter->drawImage(m_currentHorizontalStep, 0, *m_currentImage); } diff --git a/src/imagelayer.h b/src/imagelayer.h index d141f13..71e1847 100644 --- a/src/imagelayer.h +++ b/src/imagelayer.h @@ -69,7 +69,7 @@ class ImageLayer : public Layer int count() const; - void moveX(const qreal &x); + Q_INVOKABLE void moveX(); void moveY(const qreal &y); #if QT_VERSION >= 0x050000 @@ -120,10 +120,6 @@ protected slots: bool m_drawGrid; QColor m_gridColor; - qreal m_globalXPos; - qreal m_globalYPos; - qreal m_localXPos; - qreal m_localYPos; qreal m_currentHorizontalStep; bool m_initialized; diff --git a/src/layer.cpp b/src/layer.cpp index d476ecf..99663fe 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -30,7 +30,6 @@ //! Class constructor Layer::Layer(QuasiDeclarativeItem *parent) : QuasiPaintedItem(parent) - , m_isAnimated(false) , m_horizontalStep(1.0) , m_type(Quasi::InfiniteType) { @@ -45,16 +44,6 @@ Layer::~Layer() { } -void Layer::setAnimated(bool animated) -{ - if (m_isAnimated == animated) - return; - - m_isAnimated = animated; - - emit animatedChanged(); -} - void Layer::setHorizontalStep(const qreal &step) { if (m_horizontalStep == step) diff --git a/src/layer.h b/src/layer.h index d128e6b..c864f3e 100644 --- a/src/layer.h +++ b/src/layer.h @@ -69,7 +69,6 @@ class Layer: public QuasiPaintedItem { Q_OBJECT - Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged) Q_PROPERTY(qreal horizontalStep READ horizontalStep WRITE setHorizontalStep NOTIFY horizontalStepChanged) Q_PROPERTY(Quasi::LayerType layerType READ layerType WRITE setLayerType NOTIFY layerTypeChanged) @@ -77,9 +76,6 @@ class Layer: public QuasiPaintedItem Layer(QuasiDeclarativeItem *parent = 0); virtual ~Layer(); - bool isAnimated() const { return m_isAnimated; } - void setAnimated(bool animated); - qreal horizontalStep() const { return m_horizontalStep; } void setHorizontalStep(const qreal &step); @@ -87,13 +83,11 @@ class Layer: public QuasiPaintedItem void setLayerType(const Quasi::LayerType &type); signals: - void animatedChanged(); void horizontalStepChanged(); void horizontalDirectionChanged(); void layerTypeChanged(); protected: - bool m_isAnimated; qreal m_horizontalStep; Quasi::LayerType m_type; };