Example usage for com.badlogic.gdx.graphics.g2d Animation setPlayMode

List of usage examples for com.badlogic.gdx.graphics.g2d Animation setPlayMode

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d Animation setPlayMode.

Prototype

public void setPlayMode(PlayMode playMode) 

Source Link

Document

Sets the animation play mode.

Usage

From source file:com.arnopaja.supermac.helpers.load.AssetLoader.java

License:Creative Commons License

public static void loadCharacter(FileHandle handle) {
    EnumMap<Direction, TextureRegion> person = new EnumMap<Direction, TextureRegion>(Direction.class);
    EnumMap<Direction, TextureRegion> stepRight = new EnumMap<Direction, TextureRegion>(Direction.class);
    EnumMap<Direction, TextureRegion> stepLeft = new EnumMap<Direction, TextureRegion>(Direction.class);
    EnumMap<Direction, Animation> personAnim = new EnumMap<Direction, Animation>(Direction.class);
    String name = handle.nameWithoutExtension();
    characterTexture = new Texture(handle);

    TextureRegion[][] regions = SpriteUtils.split(characterTexture);
    for (int i = 0; i < 4; i++) {
        Direction dir = Direction.values()[i];
        person.put(dir, regions[0][i]);//from ww w  .  j  a  va2 s.  c  om
        stepRight.put(dir, regions[1][i]);
        if (i % 2 == 0) {
            stepLeft.put(dir, regions[2][i]);
        } else {
            stepLeft.put(dir, regions[1][i]);
        }
        TextureRegion[] array = { person.get(dir), stepRight.get(dir), person.get(dir), stepLeft.get(dir) };
        Animation animation = new Animation(0.1f, array);
        animation.setPlayMode(Animation.PlayMode.LOOP);
        personAnim.put(dir, animation);
    }
    characterAssetMap.put(name, new CharacterAsset(person, personAnim));
}

From source file:com.dongbat.game.util.factory.UnitFactory.java

/**
 * Create projectile unit/*from w  ww.java2  s.  com*/
 *
 * @param world artemis world
 * @param parent entity that execute that projectile unit
 * @param position spawn position
 * @param radius unit radius
 * @return projectile unit that was just created
 */
public static Entity createProjectileUnit(World world, Entity parent, Vector2 position, float radius,
        boolean allowConsumming, boolean consumable, boolean feedParent) {
    Entity e = world.createEntity(UUID.randomUUID());

    Stats stats = new Stats();
    stats.setAllowComsumming(allowConsumming);
    stats.setConsumable(consumable);
    stats.setParent(world.getManager(UuidEntityManager.class).getUuid(parent));
    stats.setFeedParent(feedParent);

    Physics physics = new Physics();
    physics.setBody(PhysicsUtil.createBody(PhysicsUtil.getPhysicsWorld(world), position, radius, e));
    physics.getBody().setUserData(UuidUtil.getUuid(e));
    physics.getBody().setBullet(true);
    e.edit().add(physics);

    UnitMovement movement = new UnitMovement();
    movement.setDirectionVelocity(new Vector2());

    Display display = new Display();
    e.edit().add(stats).add(new Player(false)).add(new BuffComponent()).add(new SubUnit())
            .add(new CollisionComponent()).add(new Detection()).add(movement).add(display);

    display.setPosition(PhysicsUtil.getPosition(world, e));
    display.setRadius(PhysicsUtil.getRadius(world, e));
    display.setRotation(EntityUtil.getComponent(world, e, UnitMovement.class).getDirectionVelocity().angle());
    //        TextureAtlas move = AssetUtil.getUnitAtlas().get("hot_food");
    Animation animation = new Animation(0.1f, new TextureRegion(AssetUtil.cold));
    animation.setPlayMode(Animation.PlayMode.LOOP);
    display.setDefaultAnimation(new AnimatedSprite(animation));

    return e;
}

From source file:com.dongbat.game.util.factory.UnitFactory.java

public static Entity createQueen(World world, Vector2 position, float radius) {
    Entity e = world.createEntity(UUID.randomUUID());

    Stats stats = new Stats();
    stats.setAllowComsumming(false);/*  w w  w .  ja v a 2  s.c  om*/
    stats.setConsumable(true);
    stats.setBaseRateSpeed(2000);

    BuffComponent buff = new BuffComponent();

    Physics physics = new Physics();
    physics.setBody(PhysicsUtil.createBody(PhysicsUtil.getPhysicsWorld(world), position, radius, e));
    physics.getBody().setUserData(UuidUtil.getUuid(e));

    UnitMovement movement = new UnitMovement();

    float posX = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleX);
    float posY = (float) (ECSUtil.getRandom(world).getFloat(-1, 1) * scaleY);
    movement.setDirectionVelocity(new Vector2(posX, posY));

    Display display = new Display();

    e.edit().add(physics).add(stats).add(new CollisionComponent()).add(buff).add(new Queen())
            .add(new Detection()).add(movement).add(display);

    BuffUtil.addBuff(world, e, e, "QueenTeleportSchedule", -1, 1);
    BuffUtil.addBuff(world, e, e, "ProduceFoodSchedule", -1, 1);
    BuffUtil.addBuff(world, e, e, "FeedSmaller", -1, 1, "feedPerSecond", 0.2f);
    BuffUtil.addBuff(world, e, e, "SelfDefense", -1, 1, "framePerFood", 10);
    BuffUtil.addBuff(world, e, e, "QueenGrowth", -1, 1, "cap", 20);
    display.setPosition(PhysicsUtil.getPosition(world, e));
    display.setRadius(PhysicsUtil.getRadius(world, e));
    display.setRotation(EntityUtil.getComponent(world, e, UnitMovement.class).getDirectionVelocity().angle());
    TextureAtlas queen = AssetUtil.getUnitAtlas().get("queen");
    Animation animation = new Animation(0.1f, queen.getRegions());
    animation.setPlayMode(Animation.PlayMode.LOOP);
    display.setDefaultAnimation(new AnimatedSprite(animation));
    return e;
}

From source file:com.dongbat.invasion.screen.LoadingScreen.java

@Override
public void show() {
    // Tell the manager to load assets for the loading screen
    manager.load("data/loading.pack", TextureAtlas.class);
    // Wait until they are finished loading
    manager.finishLoading();/*from   ww  w. j a  v a2s.c  om*/
    // Initialize the stage where we will place everything
    stage = new Stage();
    // Get our textureatlas from the manager
    TextureAtlas atlas = manager.get("data/loading.pack", TextureAtlas.class);
    // Grab the regions from the atlas and create some images
    logo = new Image(atlas.findRegion("libgdx-logo"));
    loadingFrame = new Image(atlas.findRegion("loading-frame"));
    loadingBarHidden = new Image(atlas.findRegion("loading-bar-hidden"));
    screenBg = new Image(atlas.findRegion("screen-bg"));
    loadingBg = new Image(atlas.findRegion("loading-frame-bg"));
    // Add the loading bar animation
    Animation anim = new Animation(0.05f, atlas.findRegions("loading-bar-anim"));
    anim.setPlayMode(Animation.PlayMode.LOOP_REVERSED);
    loadingBar = new LoadingBar(anim);
    // Add all the actors to the stage
    stage.addActor(screenBg);
    stage.addActor(loadingBar);
    stage.addActor(loadingBg);
    stage.addActor(loadingBarHidden);
    stage.addActor(loadingFrame);
    stage.addActor(logo);
    // Add everything to be loaded, for instance:
    UpgradeUtil.load();
    AtlasRegistry.load();
    AssetUtil.load();

    AbilityRegistry.load();
    BuffRegistry.load();
    PlayerInputUtil.init();
    BulletRegistry.load();
    EnemyRegistry.load();
}

From source file:com.github.fauu.helix.graphics.AnimationSet.java

License:Open Source License

private void load(String name) {
    FileHandle file = Gdx.files.internal(DIRECTORY_NAME + "/" + name + "." + EXTENSION);

    FileHandle textureFile = Gdx.files.internal(DIRECTORY_NAME + "/" + name + "." + TEXTURE_EXTENSION);

    TextureRegion[][] frameSheet = TextureRegion.split(new Texture(textureFile), 32, 32);

    String[] entries = file.readString().split("[\\r\\n]+");
    for (String entry : entries) {
        String[] segments = entry.split(":");
        String[] frameIndices = segments[1].split(",");

        AnimationType type = AnimationType.valueOf(segments[0]);

        for (int i = 0; i < DIRECTIONS.length; i++) {
            TextureRegion[] frames = new TextureRegion[frameIndices.length];

            for (int j = 0; j < frameIndices.length; j++) {
                frames[j] = frameSheet[i][Integer.valueOf(frameIndices[j])];
            }// w ww. j a  va  2  s .co  m

            Animation animation = new Animation(1, frames);
            animation.setPlayMode(Animation.PlayMode.NORMAL);

            add(type, DIRECTIONS[i], 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);
    animation.setFrameDuration(frameDuration);
    dirty = true;/*w w  w .j a  v  a  2s  .  com*/
}

From source file:com.ruin.castile.chara.AnimationSet.java

License:Open Source License

public Animation get(AnimationType type, Direction direction, float duration) {
    Animation animation;
    Direction lastDirection;//from w ww.jav  a 2  s . c o m

    if (!animations.get(type).containsKey(direction))
        lastDirection = direction.convertToFourDirections();
    else
        lastDirection = direction;

    animation = animations.get(type).get(lastDirection);

    if (animation == null)
        animation = getDefault();
    animation.setPlayMode(Animation.PlayMode.LOOP);

    //animation.setFrameDuration(duration / animation.getKeyFrames().length);

    return animation;
}

From source file:game.Content.java

/***********/

public static void loadAnimations() {

    TextureRegion r = atlas.findRegion("Explosion");
    TextureRegion[][] grid = r.split(64, 64);
    Animation a = new Animation(0.045f, grid[0]);
    a.setPlayMode(PlayMode.NORMAL);
    animations.put("Explosion", a);

    r = atlas.findRegion("EnemyDeath");
    grid = r.split(64, 128);/* ww w  . j  a v a 2 s .  com*/
    a = new Animation(0.06f, grid[0]);
    a.setPlayMode(PlayMode.NORMAL);
    animations.put("EnemyDeath", a);
}

From source file:net.k3rnel.unsealed.battle.enemies.Bee.java

License:Open Source License

public Bee(TextureAtlas atlas, int hp, int x, int y) {
    super(hp, x, y);
    this.offsetX = 25;
    this.offsetY = 20;
    setGrid(x, y);// w  w  w . j av  a 2  s .  c  om
    this.atlas = atlas;
    AtlasRegion atlasRegion = atlas.findRegion("battle/entities/bee");
    TextureRegion[][] spriteSheet = atlasRegion.split(82, 78);
    TextureRegion[] frames = new TextureRegion[2];
    frames[0] = spriteSheet[0][0];
    frames[1] = spriteSheet[0][1];
    Animation animation = new Animation(0.1f, frames);
    animation.setPlayMode(Animation.LOOP);
    this.animations.put("idle", animation);
    frames = new TextureRegion[6];
    frames[0] = spriteSheet[0][2];
    frames[1] = spriteSheet[0][3];
    frames[2] = spriteSheet[0][4];
    frames[3] = spriteSheet[0][5];
    frames[4] = spriteSheet[0][6];
    frames[5] = spriteSheet[0][7];
    animation = new Animation(0.1f, frames);
    animation.setPlayMode(Animation.NORMAL);
    this.animations.put("altattacking", animation);

    this.setState(BattleEntity.stateIdle);
    this.setHeight(78);
    this.setWidth(82);
}

From source file:net.k3rnel.unsealed.battle.enemies.Clam.java

License:Open Source License

public Clam(TextureAtlas atlas, int hp, int x, int y) {
    super(hp, x, y);
    this.atlas = atlas;
    darts = new ArrayList<MagicEntity>();
    AtlasRegion atlasRegion = atlas.findRegion("battle/entities/clam");
    TextureRegion[][] spriteSheet = atlasRegion.split(41, 48);
    TextureRegion[] frames = new TextureRegion[2];
    frames[0] = spriteSheet[0][0];//  ww w .  ja  v a  2s . c  om
    frames[1] = spriteSheet[0][1];
    Animation animation = new Animation(1f, frames);
    animation.setPlayMode(Animation.LOOP);
    this.animations.put("blocking", animation);
    frames = new TextureRegion[4];
    frames[0] = spriteSheet[0][2];
    frames[1] = spriteSheet[0][3];
    frames[2] = spriteSheet[0][3];
    frames[3] = spriteSheet[0][3];
    animation = new Animation(0.85f, frames);
    animation.setPlayMode(Animation.NORMAL);
    this.animations.put("idle", animation);
    frames = new TextureRegion[6];
    frames[0] = spriteSheet[0][4];
    frames[1] = spriteSheet[0][5];
    frames[2] = spriteSheet[0][6];
    frames[3] = spriteSheet[0][5];
    frames[4] = spriteSheet[0][3];
    frames[5] = spriteSheet[0][2];
    animation = new Animation(0.2f, frames);
    animation.setPlayMode(Animation.NORMAL);
    this.animations.put("attacking", animation);
    //        x = (int)((battleoverlay.getWidth()/2)/6);
    //        y = (int)((battleoverlay.getHeight())/3);
    //        this.setPosition(x*this.getGridX(),y*this.getGridY());
    this.setState(BattleEntity.stateBlocking);
    this.setHeight(48);
    this.setWidth(48);
}