Android游戏引擎libgdx使用教程:舞台和演员的游戏实例(三)
我们可以使用Animation来实现。添加一张图片:
具体的原理我们看一下Animation类:
public class Animation {
final TextureRegion[] keyFrames;
public float frameDuration;
/** Constructor, storing the frame duration and key frames.
*
* @param frameDuration the time between frames in seconds.
* @param keyFrames the {@link TextureRegion}s representing the frames. */
public Animation (float frameDuration, List keyFrames) {
this.frameDuration = frameDuration;
this.keyFrames = new TextureRegion[keyFrames.size()];
for(int i = 0, n = keyFrames.size(); i < n; i++) {
this.keyFrames[i] = (TextureRegion)keyFrames.get(i);
}
}
/** Constructor, storing the frame duration and key frames.
*
* @param frameDuration the time between frames in seconds.
* @param keyFrames the {@link TextureRegion}s representing the frames. */
public Animation (float frameDuration, TextureRegion... keyFrames) {
this.frameDuration = frameDuration;
this.keyFrames = keyFrames;
}
/** Returns a {@link TextureRegion} based on the so called state time. This is the amount of seconds an object has spent in the
* state this Animation instance represents, e.g. running, jumping and so on. The mode specifies whether the animation is
* looping or not.
* @param stateTime the time spent in the state represented by this animation.
* @param looping whether the animation is looping or not.
* @return the TextureRegion representing the frame of animation for the given state time. */
public TextureRegion getKeyFrame (float android开发,青软培训