动画代码导致无法忍受的滞后

时间:2016-04-24 20:22:34

标签: java animation lwjgl

所以,我已经获得了用于在LWJGL中设置动画字符的代码。这款游戏的运行速度约为60 FPS至5 FPS。我可以修改它吗?我听说缓存是可以做的,但我不知道这是否是一个真正的解决方案

package geniushour.engine.animation;

import geniushour.engine.time.Delay;

public class Animator{

private Sprite spr;
private int frame;
private Delay delay;

public Animator(Sprite spr, int sheetLengthX, int sheetLengthY) {
    spr.setNum(sheetLengthX,sheetLengthY);
    this.spr = spr;
    frame = 0;
    delay = new Delay(500);
    delay.terminate();
}
public void animate2f(String sheet, int px1, int py1, int px2, int py2, int waitTime){
    spr.setTexture(sheet);
    if(delay.over() && frame == 0){
        spr.setPlace(px1,py1);
        frame++;
    }
    if(delay.over() && frame == 1){
        spr.setPlace(px2,py2);
        frame = 0;
    }
    delay.start();
}
public void animate4f(String sheet, int px1, int py1, int px2, int py2, int px3, int py3, int px4, int py4, int waitTime){
    spr.setTexture(sheet);
    if(delay.over() && frame == 0){
        spr.setPlace(px1,py1);
        frame++;
    }
    else if(delay.over() && frame == 1){
        spr.setPlace(px2,py2);
        frame++;
    }
    else if(delay.over() && frame == 2){
        spr.setPlace(px3,py3);
        frame++;
    }
    else if(delay.over() && frame == 3){
        spr.setPlace(px4,py4);
        frame = 0;
    }
    delay.start();
}

}

0 个答案:

没有答案