List of usage examples for com.badlogic.gdx.graphics.g2d Animation setFrameDuration
public void setFrameDuration(float frameDuration)
From source file:com.github.fauu.helix.graphics.AnimationSet.java
License:Open Source License
public Animation get(AnimationType type, Direction direction, float duration) { Animation animation = animations.get(type).get(direction); animation.setFrameDuration(duration / animation.getKeyFrames().length); return animation; }
From source file:com.kotcrab.vis.runtime.component.VisSpriteAnimation.java
License:Apache License
public void setAnimation(Animation animation) { if (animation == null) throw new IllegalArgumentException("animation can't be null"); this.animation = animation; animation.setPlayMode(playMode);/* www. j a v a 2 s . c o m*/ animation.setFrameDuration(frameDuration); dirty = true; }
From source file:com.ruin.castile.chara.AnimationSet.java
License:Open Source License
private void load(String name) { FileHandle file = Gdx.files.internal(DIRECTORY_NAME + "/" + name + "." + EXTENSION); TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("packedimages/" + "game" + ".atlas")); Gson gson = new Gson(); JsonObject object = new JsonParser().parse(file.reader()).getAsJsonObject(); JsonArray entries = object.get("anims").getAsJsonArray(); for (int index = 0; index < entries.size(); index++) { JsonObject animObject = entries.get(index).getAsJsonObject(); AnimationType type = AnimationType.valueOf(animObject.get("name").getAsString()); JsonObject directions = animObject.get("directions").getAsJsonObject(); for (Direction dir : Direction.values()) { Direction theDir = dir;/*from www. j a v a 2 s. com*/ if (dir.shouldFlipSprite()) theDir = dir.getReverseSpriteDirection(); JsonElement entr = directions.get(theDir.toString()); if (entr == null) continue; JsonObject elements = entr.getAsJsonObject(); String[] frameNames = gson.fromJson(elements.get("frames"), String[].class); int[][] offsets = gson.fromJson(elements.get("offsets"), int[][].class); TextureRegion[] frames = new TextureRegion[frameNames.length]; for (int i = 0; i < frameNames.length; i++) { frames[i] = atlas.findRegion(frameNames[i]); if (dir.shouldFlipSprite()) { frames[i] = new TextureRegion(frames[i]); frames[i].flip(true, false); frames[i].setRegionX(frames[i].getRegionX() + offsets[i][1]); frames[i].setRegionY(frames[i].getRegionY() + offsets[i][0]); frames[i].setRegionWidth(frames[i].getRegionWidth() + offsets[i][1]); frames[i].setRegionHeight(frames[i].getRegionHeight() + offsets[i][0]); } else { frames[i].setRegionX(frames[i].getRegionX() + offsets[i][0]); frames[i].setRegionY(frames[i].getRegionY() + offsets[i][1]); frames[i].setRegionWidth(frames[i].getRegionWidth() + offsets[i][0]); frames[i].setRegionHeight(frames[i].getRegionHeight() + offsets[i][1]); } } Animation animation = new Animation(1, frames); animation.setFrameDuration(1.0f / animation.getKeyFrames().length); add(type, dir, animation); } } }