本文整理了Java中com.badlogic.gdx.graphics.g2d.Animation.getKeyFrames()
方法的一些代码示例,展示了Animation.getKeyFrames()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Animation.getKeyFrames()
方法的具体详情如下:
包路径:com.badlogic.gdx.graphics.g2d.Animation
类名称:Animation
方法名:getKeyFrames
[英]Returns the keyframes[] array where all the frames of the animation are stored.
[中]返回存储动画所有帧的关键帧[]数组。
代码示例来源:origin: libgdx/libgdx
@Override
public void create () {
texture = new Texture(Gdx.files.internal("data/walkanim.png"));
TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0];
Array<TextureRegion> rightWalkFrames = new Array(TextureRegion.class);
for (int i = 0; i < leftWalkFrames.length; i++) {
TextureRegion frame = new TextureRegion(leftWalkFrames[i]);
frame.flip(true, false);
rightWalkFrames.add(frame);
}
leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames);
rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames);
TextureRegion[] rightRegions = rightWalk.getKeyFrames(); // testing backing array type
TextureRegion firstRightRegion = rightRegions[0];
Gdx.app.log("AnimationTest", "First right walk region is " + firstRightRegion.getRegionWidth() + "x" + firstRightRegion.getRegionHeight());
cavemen = new Caveman[100];
for (int i = 0; i < 100; i++) {
cavemen[i] = new Caveman((float)Math.random() * Gdx.graphics.getWidth(),
(float)Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false);
}
batch = new SpriteBatch();
fpsLog = new FPSLogger();
}
代码示例来源:origin: xietansheng/FlappyBirdForGDX
public void setAnimation(Animation animation) {
this.animation = animation;
// 默认先显示第 0 帧
if (this.animation != null) {
TextureRegion[] keyFrames = this.animation.getKeyFrames();
if (keyFrames.length > 0) {
setRegion(keyFrames[0]);
}
}
}
代码示例来源:origin: Var3D/var3dframe
/**
* 动画播放frequency次后执行一个事件
*
* @param frequency
*/
public void setRunnableAction(int frequency, RunnableAction end) {
float time = frameTime * animation.getKeyFrames().length * frequency;
addAction(Actions.sequence(Actions.delay(time), end));
}
代码示例来源:origin: xietansheng/FlappyBirdForGDX
@Override
public void act(float delta) {
super.act(delta);
if (animation != null) {
TextureRegion region = null;
if (isPlayAnimation) {
// 如果需要播放动画, 则累加时间步, 并按累加值获取需要显示的关键帧
stateTime += delta;
region = animation.getKeyFrame(stateTime);
} else {
// 不需要播放动画, 则获取 fixedShowKeyFrameIndex 指定的关键帧
TextureRegion[] keyFrames = animation.getKeyFrames();
if (fixedShowKeyFrameIndex >= 0 && fixedShowKeyFrameIndex < keyFrames.length) {
region = keyFrames[fixedShowKeyFrameIndex];
}
}
// 设置当前需要显示的关键帧
setRegion(region);
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
private void updateCaveman() {
if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) {
if(goingRight) {
for(TextureRegion t : cavemanWalk.getKeyFrames())
t.flip(true, false);
goingRight = false;
}
cavemanX -= Gdx.graphics.getDeltaTime() * cavemanSpeed;
currentFrame = cavemanWalk.getKeyFrame(animationTime, true);
}
if(Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) {
if(!goingRight) {
goingRight = true;
for(TextureRegion t : cavemanWalk.getKeyFrames())
t.flip(true, false);
}
cavemanX += Gdx.graphics.getDeltaTime() * cavemanSpeed;
currentFrame = cavemanWalk.getKeyFrame(animationTime, true);
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
private void updateCaveman() {
if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) {
if(goingRight) {
for(TextureRegion t : cavemanWalk.getKeyFrames())
t.flip(true, false);
goingRight = false;
}
cavemanX -= Gdx.graphics.getDeltaTime() * cavemanSpeed;
currentFrame = cavemanWalk.getKeyFrame(animationTime, true);
}
if(Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) {
if(!goingRight) {
goingRight = true;
for(TextureRegion t : cavemanWalk.getKeyFrames())
t.flip(true, false);
}
cavemanX += Gdx.graphics.getDeltaTime() * cavemanSpeed;
currentFrame = cavemanWalk.getKeyFrame(animationTime, true);
}
}
代码示例来源:origin: dsaltares/libgdx-cookbook
cavemanAnims = manager.get("data/caveman-sheet.json");
cavemanWalk = cavemanAnims.getAnimation("walk");
currentFrame = cavemanWalk.getKeyFrames()[0];
cavemanX = 0;
cavemanSpeed = 180;
代码示例来源:origin: dsaltares/libgdx-cookbook
cavemanAnims = manager.get("data/caveman-sheet.json");
cavemanWalk = cavemanAnims.getAnimation("walk");
currentFrame = cavemanWalk.getKeyFrames()[0];
cavemanX = 0;
cavemanSpeed = 180;
内容来源于网络,如有侵权,请联系作者删除!