Back to project page tetris-android.
The source code is released under:
MIT License
If you think the Android project tetris-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.badlogic.androidgames.framework.gl; //from ww w .ja v a 2 s . co m public class Animation { public static final int ANIMATION_LOOPING = 0; public static final int ANIMATION_NONLOOPING = 1; final TextureRegion[] keyFrames; final float frameDuration; public Animation(float frameDuration, TextureRegion ... keyFrames) { this.frameDuration = frameDuration; this.keyFrames = keyFrames; } public TextureRegion getKeyFrame(float stateTime, int mode) { int frameNumber = (int)(stateTime / frameDuration); if(mode == ANIMATION_NONLOOPING) { frameNumber = Math.min(keyFrames.length-1, frameNumber); } else { frameNumber = frameNumber % keyFrames.length; } return keyFrames[frameNumber]; } }