demos/sub-attaq/boat.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    60 {
    60 {
    61     QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat);
    61     QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat);
    62     for (int i = 1; i <= 4; i++) {
    62     for (int i = 1; i <= 4; i++) {
    63         PixmapItem *step = new PixmapItem(QString("explosion/boat/step%1").arg(i),GraphicsScene::Big, boat);
    63         PixmapItem *step = new PixmapItem(QString("explosion/boat/step%1").arg(i),GraphicsScene::Big, boat);
    64         step->setZValue(6);
    64         step->setZValue(6);
    65         step->setOpacity(0); 
    65         step->setOpacity(0);
    66 
    66 
    67         //fade-in
    67         //fade-in
    68         QPropertyAnimation *anim = new QPropertyAnimation(step, "opacity");
    68         QPropertyAnimation *anim = new QPropertyAnimation(step, "opacity");
    69         anim->setEndValue(1);
    69         anim->setEndValue(1);
    70         anim->setDuration(100);
    70         anim->setDuration(100);
    71         group->insertAnimationAt(i-1, anim);
    71         group->insertAnimation(i-1, anim);
    72 
    72 
    73         //and then fade-out
    73         //and then fade-out
    74         QPropertyAnimation *anim2 = new QPropertyAnimation(step, "opacity");
    74         QPropertyAnimation *anim2 = new QPropertyAnimation(step, "opacity");
    75         anim2->setEndValue(0);
    75         anim2->setEndValue(0);
    76         anim2->setDuration(100);
    76         anim2->setDuration(100);
    90     setFlags(QGraphicsItem::ItemIsFocusable);
    90     setFlags(QGraphicsItem::ItemIsFocusable);
    91 
    91 
    92     //The movement animation used to animate the boat
    92     //The movement animation used to animate the boat
    93     movementAnimation = new QPropertyAnimation(this, "pos");
    93     movementAnimation = new QPropertyAnimation(this, "pos");
    94 
    94 
    95     //The movement animation used to animate the boat
    95     //The destroy animation used to explode the boat
    96     destroyAnimation = setupDestroyAnimation(this);
    96     destroyAnimation = setupDestroyAnimation(this);
    97 
    97 
    98     //We setup the state machien of the boat
    98     //We setup the state machine of the boat
    99     machine = new QStateMachine(this);
    99     machine = new QStateMachine(this);
   100     QState *moving = new QState(machine);
   100     QState *moving = new QState(machine);
   101     StopState *stopState = new StopState(this, moving);
   101     StopState *stopState = new StopState(this, moving);
   102     machine->setInitialState(moving);
   102     machine->setInitialState(moving);
   103     moving->setInitialState(stopState);
   103     moving->setInitialState(stopState);