0
我有一個精靈渲染器,它告訴我的遊戲引擎如何渲染精靈。此類中的更新方法每秒調用大約120
次。以這樣的速度穿越精靈表格太快了。在畫布上播放精靈表比幀率慢
在我的精靈類中,我有一個名爲duration
的屬性,它告訴渲染器精靈應該玩多少秒。一旦它達到最後一幀,它應該重新開始。
我不完全確定如何計算這個與update
每秒運行120
次,精靈表應該持續x
秒直到重新開始。
class SpriteRenderer extends Component {
// The current frame
public frame: number = 0;
// The sprite reference
public sprite: Sprite = null;
update() {
// Number of frames in the sprite sheet
let frames = this.sprite.frames;
if (frames > 0) {
// The time in seconds the sprite sheet should play
let duration = this.sprite.duration;
if (/* What should go here? */) {
this.frame++;
if (this.frame > frames - 1) {
this.frame = 0;
}
}
}
}
}
八九不離十,'this.currentTime + = 0.01;'在我的情況應該是'this.currentTime + = Time.deltaTime;''this.udateTime'將是' duration'。將我的持續時間設置爲「1」,它每秒播放1幀,這比它更接近。 –
是的,我正在更新我的答案,以計算每秒應該添加的時間以及需要多長時間。 –
更緊密!我的if現在看起來像這樣:if(this.currentTime> duration * Time.deltaTime)'my'deltaTime'約爲'0.008'。它仍然有點快。如果我將持續時間設置爲5,則大約需要1秒... –