import
java.awt.Image;
import
java.util.ArrayList;
public
class
Animation {
private
ArrayList scenes;
private
int
sceneIndex;
private
long
movieTime;
→
動畫時間
private
long
totalTime;
→
場景的總時間
public
Animation(){
scenes
= new
ArrayList();
totalTime
= 0;
start();
}
//添加場景到ArrayList,並為每個場景設置時間
public
synchronized
void
addScene(Image i, long
t){ →
synchronized
只有這個方法運行
totalTime
+= t;
scenes.add(new
OneScene(i,totalTime));
}
//開始動畫
public
synchronized
void
start(){
movieTime
= 0;
sceneIndex
= 0;
}
//改變場景
public
synchronized
void
update(long
timePassed){
if(scenes.size()>1){
movieTime
+= timePassed;
if(movieTime
>= totalTime){
→
條件,如果動畫時間大於totalTime
movieTime
= 0; →
重置0
sceneIndex
= 0; →
重置0
}
while(movieTime
> getScene(sceneIndex).endTime){
→
當場景時間結束
sceneIndex++;
→ 去下一個場景
}
}
}
}
沒有留言:
張貼留言