1
我目前正在製作一個Js動畫。如何做一個騎車價值javascript
讓我解釋一下:
我有一個讓每個Y位置this.y
幾個對象。我想讓它們像this.y -= 0.1
一樣向上移動,每個延遲。
問題:當對象從原始位置向上移動10px(此代碼爲this.y += 0.1
)時,我想將方向改爲向下。當它從原始位置移動-10px時,將方向改爲向上(this.y -= 0.1
)。
這是一種騎行價值。任何想法 ?我認爲一個增加另一個變量,像這樣:
this.incr = 0;
this.incr += 0.1;
if(this.incr == 1){
this.y += 0.1;
}
else if(this.incr == -1){
this.y -= 0.1;
}
我知道這不是好辦法,但我不能找到解決方案。