Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Animation {
- Array<TextureRegion> frames;
- float maxFrameTime;
- float currentFrameTime;
- int frameCount;
- int frame;
- Boolean playedOnce;
- public void dispose(){
- frames=null;
- }
- public Animation(TextureRegion region, int frameCount, float cycleTime){
- playedOnce=false;
- frames = new Array<TextureRegion>();
- TextureRegion temp;
- int frameWidth = region.getRegionWidth() / frameCount;
- for(int i = 0; i < frameCount; i++){
- temp = new TextureRegion(region, i * frameWidth, 0, frameWidth, region.getRegionHeight());
- frames.add(temp);
- }
- this.frameCount = frameCount;
- this.maxFrameTime = cycleTime / frameCount;
- frame = 0;
- }
- public void update(float dt){
- currentFrameTime += dt;
- if(currentFrameTime > maxFrameTime){
- frame++;
- currentFrameTime = 0;
- if(frame >= frameCount-1){
- playedOnce=true;
- }
- if(frame >= frameCount){
- frame = 0;
- }
- }
- }
- public Boolean isPlayedOnce(){
- return playedOnce;
- }
- public void flip(){
- for(TextureRegion region : frames)
- region.flip(true, false);
- }
- public TextureRegion getFrame(){
- return frames.get(frame);
- }
Add Comment
Please, Sign In to add comment