2017-04-24 106 views
0

我有一個從某個位置向上移動的橢圓。有沒有辦法停止QGraphicsScene?

void Equalizer::advance(int phase) 
{ 
    if(!phase) return; 

    QPointF location = this->pos(); 
    setPos(mapToParent(0 , -(speed))); 
} 

儘管我希望它在到達某個y座標時停止移動。我怎麼做?

+0

你爲什麼不使用QPropertyAnimation呢?處理幾乎所有你能想到的事情都會好得多。 – phyatt

+0

@phyatt,'better'是主觀的。如果在遊戲中處理玩家對象的實時移動,基於用戶輸入,這不是我想要使用的。 – TheDarkKnight

回答

1

不更新其y位置,當它到達指定的y座標,

void Equalizer::advance(int phase) 
{ 
    if(!phase) return; 

    QPointF location = this->pos(); 

    if(location.y() <= specifiedY) 
    { 
     //If the speed at which the ellipse is moving is great enough to take it beyond the specifiedY, set it to the specifiedY before the return. 
     setPos(pos().x(), specifiedY); // assuming specifiedY is in scene coordinates 
     return; 
    }   
    setPos(mapToParent(0 , -(speed))); 
} 
+0

但是不會導致QGraphicsScene在無效的情況下繼續調用這個無限循環嗎? –

+0

@JackNickolson,試試看看會發生什麼; O) – TheDarkKnight

相關問題