[英]How do I slow down an a sprite animation with processing java
我試圖減慢我從這個網站找到的精靈動畫: https ://processing.org/examples/animatedsprite.html
這是動畫的類:
class Animation {
PImage[] images;
int imageCount;
int frame;
Animation(String imagePrefix, int count) {
imageCount = count;
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
// Use nf() to number format 'i' into four digits
String filename = "images/" + imagePrefix + nf(i, 2) + ".png";
images[i] = loadImage(filename);
}
}
void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos);
}
int getWidth() {
return images[0].width;
}
}
從顯示動畫的網站上,它說:
編寫一個顯示動畫 GIF 的程序很容易,但不允許對顯示順序和顯示速率進行太多控制。
到目前為止,動畫以當前幀速率(大約 60 FPS)播放,但如果我想以 5 FPS 播放呢? 顯然,我不能只放慢整個幀速率,因為我只想放慢動畫,而不是我的整個項目/畫布。
我嘗試通過執行以下操作來減慢動畫速度:
if (frameCount % 10 == 1) {
//Show image
}
但上述方法會閃爍圖像,僅每十幀顯示一次。 我將如何成功減慢動畫的顯示速度,以使幀不會出現這么快?
這是動畫現在的樣子:
這就是我想要的樣子:
謝謝你的幫助。
你太近了! :)
您幾乎可以使用frameCount
獲得解決方案,只需將幀更新與繪圖分開即可。 您想根據 frameCount 更新(每隔一段時間),但要連續顯示:
void display(float xpos, float ypos) {
if(frameCount % 12 == 0){
frame = (frame+1) % imageCount;
}
image(images[frame], xpos, ypos);
}
(感覺調整到最適合您項目的 12 (60/5))
無恥插件,你也可以使用我寫的image-sequence-player庫,它允許你調用setDelay(1000/5)
讓圖像序列以 5fps 播放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.