Improved card animation performance
+ Cards now animate smoother and faster + removed redundant computations performed each frame
This commit is contained in:
parent
dc58d1a61e
commit
2193d247d0
3 changed files with 10 additions and 5 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "tab_game.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
|
||||
|
||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _revealedCard, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, _owner, _cardid, parent), zone(0), revealedCard(_revealedCard), attacking(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
{
|
||||
|
@ -360,15 +361,16 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
|
||||
bool CardItem::animationEvent()
|
||||
{
|
||||
int delta = 18;
|
||||
int delta = DELTA;
|
||||
if (!tapped)
|
||||
delta *= -1;
|
||||
|
||||
tapAngle += delta;
|
||||
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
setTransform(QTransform().translate(CARD_WIDTH_HALF, CARD_HEIGHT_HALF).rotate(tapAngle).translate(-CARD_WIDTH_HALF, -CARD_HEIGHT_HALF));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@ class QAction;
|
|||
class QColor;
|
||||
|
||||
const int MAX_COUNTERS_ON_CARD = 999;
|
||||
const float CARD_WIDTH_HALF = CARD_WIDTH / 2;
|
||||
const float CARD_HEIGHT_HALF = CARD_HEIGHT / 2;
|
||||
const int DELTA = 10;
|
||||
|
||||
class CardItem : public AbstractCardItem {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -262,7 +262,7 @@ void GameScene::registerAnimationItem(AbstractCardItem *card)
|
|||
{
|
||||
cardsToAnimate.insert(static_cast<CardItem *>(card));
|
||||
if (!animationTimer->isActive())
|
||||
animationTimer->start(50, this);
|
||||
animationTimer->start(15, this);
|
||||
}
|
||||
|
||||
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
|
||||
|
|
Loading…
Reference in a new issue