Java 类com.badlogic.gdx.graphics.g2d.Animation 实例源码

项目:SpaceChaos    文件:AtlasAnimationComponent.java   
protected void createCachedAnimations(Map<String, Integer> map) {
    int i = 0;

    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        String animationName = entry.getKey();
        int frameCounter = entry.getValue();

        // calculate duration per frame
        float durationPerFrame = this.sumDuration / frameCounter;

        // get regions
        Array<TextureAtlas.AtlasRegion> regions = this.atlas.findRegions(animationName);

        // create animation
        Animation<TextureRegion> anim = new Animation<>(durationPerFrame, regions, Animation.PlayMode.LOOP);

        // add animation to map
        this.animationMap.put(animationName, anim);

        i++;
    }
}
项目:SpaceChaos    文件:AnimationTextureUtils.java   
public static Animation<TextureRegion> createAnimationFromTexture(Texture texture, float duration, int rows,
        int cols) {
    // split texture into texture regions
    TextureRegion[][] tmp = TextureRegion.split(texture, texture.getWidth() / cols, texture.getHeight() / rows);

    TextureRegion[] frames = new TextureRegion[cols * rows];
    int index = 0;

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            frames[index++] = tmp[i][j];
        }
    }

    // create new animation
    Animation<TextureRegion> animation = new Animation<TextureRegion>(duration, frames);

    return animation;

}
项目:miniventure    文件:MobAnimationController.java   
TextureRegion pollAnimation(float delta) {
    // update the animation
    animationTime += delta;
    // fetch the current frame
    String textureName = state.name().toLowerCase() + "-" + mob.getDirection().name().toLowerCase();
    Animation<TextureRegion> ani = animations.get(textureName);
    if(animationTime > ani.getAnimationDuration()) animationTime = 0; // reset the animationTime to prevent any possibility of overflow
    TextureRegion frame = ani.getKeyFrame(animationTime, true);

    // reset the animation
    prevState = state;
    state = requestedAnimations.poll();
    if(state == null) state = AnimationState.IDLE;
    if(state != prevState)
        animationTime = 0; // if we're going to render a new animation, we should start it from the beginning, I think. Though, I could see this not ending up being a good idea... NOTE: this is not just set to zero because it seems this causes a divide by zero error when fetching the keyframe.
    requestedAnimations.clear();

    return frame;
}
项目:TH902    文件:BaseSprite.java   
/**
 * @param color
 *            0 - blue; 1 - red; 2 - green; 3 - yellow
 */
public static Entity Create(Vector2 position, int color, int maxhp, Component... Ves) {
    if (color < 0 || color > 3) {
        throw new IllegalArgumentException("Color of the enemy (sprite) should be between 0 and 3!");
    }
    Entity entity = Entity.Create();
    Transform transform = new Transform(position, new Vector2(0.5f, 0.5f));
    entity.AddComponent(transform);
    BaseSprite component = new BaseSprite();
    component.selfColor = color;
    component.animation = new AnimationDrawable();
    if (texture != ResourceManager.enemies.get(0)) {
        texture = ResourceManager.enemies.get(0);
        regions = TextureRegion.split(texture, texture.getWidth() / 12, texture.getHeight() / 4);
    }
    component.animation.setAnimation(new Animation<TextureRegion>(1, regions[color]));
    EnemyHP hp = new EnemyHP(maxhp);
    entity.AddComponent(hp);
    entity.AddComponent(new EnemyJudgeCircle(48 * transform.scale.x, hp));
    entity.AddComponent(new EnemyChaseable(hp));
    entity.AddComponent(component);
    for (Component tmpc : Ves) {
        entity.AddComponent(tmpc);
    }
    return entity;
}
项目:Ponytron    文件:Pony.java   
public void init() {

        CURRENT_STATE = PONY_STATE.STANDING;
        isFacingRight = false;

        runAnimation = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("pony_01"), AssetDoctor.getTextureRegion_ATLAS("pony_02"));
        runAnimation.setPlayMode(Animation.PlayMode.LOOP);

        cheerAnimation = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("pony_cheer_00"), AssetDoctor.getTextureRegion_ATLAS("pony_cheer_01"), AssetDoctor.getTextureRegion_ATLAS("pony_cheer_02"));
        cheerAnimation.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

        currentSprite = new Sprite(AssetDoctor.getSprite("pony"));
        resizeSprite(currentSprite);
        moveToX = x;
        moveToY = y;
    }
项目:arcadelegends-gg    文件:BulletRenderer.java   
@Override
public void inserted(int entityId, RenderSystem renderSystem) {
    RenderComponent render = renderSystem.getMapperRender().get(entityId);
    PositionComponent position = renderSystem.getMapperPosition().get(entityId);
    if (render.animations.size == 0) {
        for (Map.Entry<String, RenderComponent.RenderTemplate.AnimationTemplate> entry : render.renderTemplate.animationTemplates.entrySet()) {
            TextureRegion texture = renderSystem.getLevelAssets().get(entry.getValue().texture);

            TextureRegion[][] tmp = texture.split(
                    +texture.getRegionWidth() / entry.getValue().frameColumns,
                    +texture.getRegionHeight() / entry.getValue().frameRows);
            TextureRegion[] frames = new TextureRegion[entry.getValue().frameColumns * entry.getValue().frameRows];
            int index = 0;
            for (int i = 0; i < entry.getValue().frameRows; i++) {
                for (int j = 0; j < entry.getValue().frameColumns; j++) {
                    frames[index++] = tmp[i][j];
                }
            }
            render.animations.put(entry.getKey(), new Animation<TextureRegion>(entry.getValue().frameDuration, new Array<>(frames), Animation.PlayMode.LOOP));
        }
    }
    Decal decal = Decal.newDecal(render.width, render.height, render.getCurrentKeyFrame(renderSystem.getStateTime()), render.transparent);
    decal.rotateX(renderSystem.getWorldDegree());
    decal.setPosition(position.position.x, position.position.y, 0);
    renderSystem.getDecalMap().put(entityId, decal);
}
项目:Hackerman    文件:Entity.java   
/**
 * Creates a player and assigns a texture to it.
 * Creates an animation by splitting the given sprite sheet into an array of TILE_WIDTHxTILE_HEIGHT dimension.
 * ERROR should be 9x4 but ends up being 4x2
 * @param playerTexture
 * @param dynamicEntity
 */
public Entity(Texture playerTexture, DynamicEntity dynamicEntity) {
    int orientation = dynamicEntity.getDirection().getCode();
    TextureRegion[][] playerTextures = TextureRegion.split(playerTexture,TILE_WIDTH,TILE_HEIGHT);
    this.dynamicEntity = dynamicEntity;
    switch (orientation) {
        case Direction.UP:
            animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[0][0], playerTextures[0][1], playerTextures[0][2],playerTextures[0][3],playerTextures[0][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
            break;
        case Direction.DOWN:
            animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[2][0], playerTextures[2][1], playerTextures[2][2],playerTextures[2][3],playerTextures[2][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
            break;
        case Direction.LEFT:
            animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[1][0], playerTextures[1][1], playerTextures[1][2],playerTextures[1][3],playerTextures[1][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
            break;
        case Direction.RIGHT:
            animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[3][0], playerTextures[3][1], playerTextures[3][2],playerTextures[3][3],playerTextures[3][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
            break;
        default:
            animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[0][0], playerTextures[0][1], playerTextures[0][2],playerTextures[0][3],playerTextures[0][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
    }
    animation.setPlayMode(Animation.PlayMode.LOOP);
}
项目:StarshipFighters    文件:Animator.java   
public void initialize() {
    // Load SpriteSheet
    spriteSheet = new Texture(Gdx.files.internal(filePath));

    // Extract Sprites
    TextureRegion[][] tmp = TextureRegion.split(spriteSheet, spriteSheet.getWidth() / frameCols, spriteSheet.getHeight() / frameRows);

    // Place into 1D array
    animationSprites = new TextureRegion[columnCutOff * rowCutOff];
    int index = 0;
    for (int i = 0; i < rowCutOff; i++) {
        for (int j = 0; j < columnCutOff; j++) {
            animationSprites[index++] = tmp[i][j];
        }
    }

    // Load animation frames
    animationTextureRegion = new Animation<TextureRegion>(frameLengthTime, animationSprites);

}
项目:KyperBox    文件:GameState.java   
public GameState(String name, String tmx, StateManager manager) {
    this.tmx = tmx;
    setManager(manager);
    if(name!=null)
    this.name = name;
    else
        this.name = "";
    sprites = new ObjectMap<String, Sprite>();
    animations = new ObjectMap<String, Animation<String>>();
    fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats
    particle_effects = new ObjectMap<String, ParticleEffectPool>();
    pvalues = new Array<String>();
    time_scale = 1f;
    shaders = new ObjectMap<String, ShaderProgram>();
    svalues = new Array<String>();
}
项目:libGdx-xiyou    文件:JumpBall.java   
private void init() {
    mSkillAtlas = MyGdxGame.assetManager.getTextureAtlas(Constant.FIREBALL_WIDGET);

    //升龙斩动画初始化
    mRJumpAtkRegions = new TextureAtlas.AtlasRegion[4];
    for (int i = 0; i < mRJumpAtkRegions.length - 1; i++) {
        mRJumpAtkRegions[i] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit" + (i + 1)));
    }
    mRJumpAtkRegions[3] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit3"));
    mLJumpAtkRegions = new TextureAtlas.AtlasRegion[4];
    for (int i = 0; i < mLJumpAtkRegions.length - 1; i++) {
        mLJumpAtkRegions[i] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit" + (i + 1)));
        mLJumpAtkRegions[i].flip(true, false);
    }
    mLJumpAtkRegions[3] = mLJumpAtkRegions[2];
    mRJumpAtkAni = new Animation(1 / 12f, mRJumpAtkRegions);
    mLJumpAtkAni = new Animation(1 / 12f, mLJumpAtkRegions);
}
项目:retro-reversi    文件:CellView.java   
public CellView(GamePresenter presenter, int x, int y, int boardX, int boardY) {
    this.presenter = presenter;
    actorX = x;
    actorY = y;
    this.boardX = boardX;
    this.boardY = boardY;
    setBounds(actorX, actorY, tile.getWidth(), tile.getHeight());
    previousPiece = presenter.getCurrentPiece(boardX, boardY);
    addListeners();

    ICONS.put('B', black);
    ICONS.put('W', white);
    ICONS.put('X', suggestion);
    ICONS.put('-', null);

    System.arraycopy(blackFramesTmp[0], 0, blackFrames, 0, 7);
    System.arraycopy(whiteFramesTmp[0], 0, whiteFrames, 0, 7);
    blackAnimation = new Animation<TextureRegion>(0.09f, blackFrames);
    whiteAnimation = new Animation<TextureRegion>(0.09f, whiteFrames);
}
项目:GangsterSquirrel    文件:BossEnemy.java   
/**
 * Sets up the enemy in the game
 * @param screen the play screen
 * @param spawnPositionX the spawn position as tile index on the x axis
 * @param spawnPositionY the spawn position as tile index on the y axis
 */
public BossEnemy(PlayScreen screen, float spawnPositionX, float spawnPositionY) {
    super(screen, spawnPositionX, spawnPositionY);

    playScreen = screen;

    // Set gameplay variables of super class for this specific type of enemy
    damageMinMax = new int[] { 10, 20 };
    health = 50;
    horizontalMoveImpulseVelocity = 0.1f;
    horizontalMaxMovementVelocity = 0.5f;

    // Animation set up
    flyFrames = new Array<>();
    for(int i = 0; i < 12; i++) {
        flyFrames.add(new TextureRegion(screen.getEnemyBossTextureAtlas().findRegion("bird"), 0, i * ENEMY_PIXEL_HEIGHT, ENEMY_PIXEL_WIDTH, ENEMY_PIXEL_HEIGHT)
        );
    }

    flyAnimation = new Animation<TextureRegion>(0.2f, flyFrames);

    currentAnimation = "bird_fly";

    stateTime = 0;
    setBounds(getX(), getY(), ENEMY_PIXEL_WIDTH / MainGameClass.PPM, ENEMY_PIXEL_HEIGHT / MainGameClass.PPM + getHeight() / 2);
}
项目:space-travels-3    文件:Explosion.java   
public Explosion(float x, float y, float width, float height, TextureAtlas textureAtlas)
{
    this.physicsComponent = new PhysicsComponent(
        x,
        y,
        0f,
        (height + width) / 4f,
        new GameEntityGroup(GameEntityGroup.GroupOverride.NONE),
        this.getClass(),
        false,
        PhysicsComponentType.DYNAMIC);

    this.graphicComponent = new AnimatedGraphicComponent(
        textureAtlas,
        Constants.Visual.EXPLOSION_LIFETIME,
        width,
        height,
        this.physicsComponent,
        Animation.PlayMode.NORMAL);

    this.sound = AssMan.getGameAssMan().get(AssMan.getAssList().explosionSound);
    this.sound.play(SettingsManager.getSettings().volumeFX);
}
项目:ld37    文件:ScheduleSubView.java   
public Animation getAnimation(String image, int frameCount, float frameDuration) {
    TextureRegion[] frames = new TextureRegion[frameCount];

    for (int i = 0; i < frameCount; ++i) {
        frames[i] =
            new TextureRegion(
                new Texture(
                    Gdx.files.internal(
                        PATH_PREFIX+image+String.format("%04d", i)+PATH_SUFFIX
                    )
                )
            );
    }

    Animation animation = new Animation(frameDuration, frames);
    return animation;
}
项目:dice-heroes    文件:AddEffectVisualizer.java   
@Override public IFuture<Void> visualize(final AddEffect result) {
    final Array<TextureAtlas.AtlasRegion> regions = Config.findRegions("animation/effect-" + result.ability.name);
    if (regions.size == 0)
        return Future.completed();
    final WorldObjectView view = visualizer.viewController.getView(result.getTarget());
    final AnimationSubView subView = new AnimationSubView(0.1f, regions, Animation.PlayMode.LOOP);
    subView.getActor().setPosition(1, 2);
    subView.priority = 1;
    view.addSubView(subView);
    visualizer.viewController.world.dispatcher.add(Creature.REMOVE_EFFECT, new EventListener<EffectEvent>() {
        @Override public void handle(EventType<EffectEvent> type, EffectEvent event) {
            if (event.effect != result.effectToApply || event.creature != result.creatureToAddEffect)
                return;
            visualizer.viewController.world.dispatcher.remove(Creature.REMOVE_EFFECT, this);
            SoundManager.instance.playMusicAsSound("boss-protection-loss");
            subView.getActor().addAction(Actions.alpha(0, DURATION));
            subView.getActor().addAction(Actions.delay(DURATION, Actions.run(new Runnable() {
                @Override public void run() {
                    view.removeSubView(subView);
                }
            })));
        }
    });
    return Future.completed();
}
项目:cgc-game    文件:ChainLink.java   
public ChainLink(Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody);

    //Determine half-values for use with rendering logic

    // These numbers are calculated based on the texture dimensions of the associated art asset.
    // The relationship is: 1.0f in world space is 96x96 in pixels (see art asset to get dimensions)
    // By default, half-width and half-height are calculated based on the base image's dimensions
    // when rotated/aligned horizontally.
    //this.halfHeight = -0.104166667f;
    //this.halfWidth = -0.15625f;

    rotation = body.getAngle() * Data.RADDEG;
}
项目:cgc-game    文件:Helicopter.java   
public Helicopter(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType entityType, Body body)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, entityType, body);
    gameWorld = theWorld;
    Gdx.app.log("In the pipe", "five by five");
    rotation = 90;

    //SoundManager.playSound("helicopter", false);

    hoverTask = new Timer.Task() {

        public void run() 
        {
            stopped = false;
            returnTrip = true;
            getBody().setLinearVelocity(new Vector2(4,0));
        }
    };

    hoverClock = new CGCTimer(hoverTask, hoverTime, false, "hoverClock");
    body.setLinearVelocity(new Vector2(4, 0));
}
项目:cgc-game    文件:SpotlightCop.java   
public SpotlightCop(CGCWorld theWorld, Animation newLowAnimation, 
        Animation newMidAnimation, Animation newHighAnimation, 
        EntityType pEntityType, Body attachedBody, short pID, 
        float cameraPosX, float cameraPosY)
{
    super(theWorld, newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);

    body.getFixtureList().get(0).setSensor(true);

    // Create spotlight
    Body b = CGCWorld.getBF().createCircle(cameraPosX, cameraPosY, 
            2.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
    b.getFixtureList().get(0).setSensor(true);
    b.setFixedRotation(true);
    spotlight = new Spotlight(null, null, TextureAnimationDrawer.spotlightAnim,
            EntityType.TARGETER, b, CGCWorld.getCamera(), getPID());
    b.setUserData(spotlight);
    spotlight.addToWorldLayers(CGCWorld.getLH());

    alive = true;
    lowState = AnimationState.STAND;
}
项目:cgc-game    文件:RookieCop.java   
public RookieCop(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType, Body attachedBody, short pID)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);

    gameWorld = theWorld;

    maxGrabStrength = MAX_GRAB_STRENGTH_BASE + Math.round(((float)(Math.random() * 2) - 1.0f) * MAX_GRAB_RANGE);
    currentGrabStrength = maxGrabStrength;
    noGrab = false;
    setCoins(0);

    grabCooldownTask = new Timer.Task() 
    {   
        public void run() 
        {   
            currentGrabStrength = maxGrabStrength;
            noGrab = false;
        }
    };

    grabCooldownTimer = new CGCTimer(grabCooldownTask, grabCooldown, false, "grabCooldownTimer");
}
项目:123Dor    文件:GameScreen.java   
private Animation getAnimation(Cowboy.State state, String side){
    if(state.equals(Cowboy.State.SHOOT)){
        if(side.equals("left"))
            return shotLeftAnimation;
        else
            return shotRightAnimation;
    }else if(state.equals(Cowboy.State.LOSE)){
        if(side.equals("left"))
            return dieLeftAnimation;
        else
            return dieRightAnimation;
    }else if(state.equals(Cowboy.State.WIN)){
        if(side.equals("left"))
            return winLeftAnimation;
        else
            return winRightAnimation;
    }else{
        return null;
    }
}
项目:cgc-game    文件:Prisoner.java   
public Prisoner(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType, Body attachedBody, short pID)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, 
            pEntityType, attachedBody, pID);

    gameWorld = theWorld;
    towerContacts = new Array<GuardTower>();
    lightContacts = new Array<Spotlight>();
    sensorContacts = new Array<Sensor>();
    grabbedByArray = new Array<RookieCop>();
    keyID = (int) (playerID+1);

    maxStamina = MAX_STAMINA_BASE + Math.round(((float)(Math.random() * 2) - 1.0f) * MAX_STAMINA_RANGE);
    currentStamina = maxStamina;
}
项目:cgc-game    文件:Sheriff.java   
public Sheriff(Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType,
        Body attachedBody, Boss bo, float startAlpha)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType,
            attachedBody, startAlpha);
    boss = bo;
    fireTask = new Timer.Task()
    {

        public void run()
        {
            fire();
        }
    };

    fireTimer = new CGCTimer(fireTask, fireTime, true, "fireTimer");

    do
    {
        target = CGCWorld.getPrisoners().random();
    }while(!target.isAlive() || target == null);

    TimerManager.addTimer(fireTimer);
}
项目:Battle-City-Multiplayer    文件:Assets.java   
public static Animation createAnimation(TextureAtlas atlas,
        String regionName, float frameDuration, Animation.PlayMode mode) {
    ArrayList<TextureRegion> frames = new ArrayList<>();

    int idx = 0;
    TextureAtlas.AtlasRegion region;

    while ((region = atlas.findRegion(regionName, idx)) != null) {
        frames.add(region);
        idx++;
    }

    TextureRegion[] regions = new TextureRegion[idx];
    Animation anim = new Animation(frameDuration, frames.toArray(regions));
    anim.setPlayMode(mode);        
    return anim;
}
项目:cgc-game    文件:GameEntity.java   
public GameEntity(Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
    lowAnimation = newLowAnimation;
    midAnimation = newMidAnimation;
    highAnimation = newHighAnimation;
    entityType = pEntityType;
    alpha = 1.0f;
    lowStateTime = 0.0f;
    midStateTime = 0.0f;
    highStateTime = 0.0f;
    recalcHalfDimensions();
    scaled = false;
    body = attachedBody;

    transformMod = new Vector3(0, 0, 1);

    // These numbers are calculated based on the texture dimensions of the associated art asset.
    // The relationship is: 1.0f in world space is 96x96 in pixels (see art asset to get dimensions)
    // By default, half-width and half-height are calculated based on the base image's dimensions
    // when rotated/aligned horizontally.
    scaling = new Vector2(1.0f, 1.0f);
}
项目:TerraLegion    文件:AnimationDrawable.java   
public AnimationDrawable(SpriteSheet sheet) {
    final int startX = 0;
    final int startY = 0;
    final int frames = 3;

    Array<TextureRegion> tempSpritesUp = AnimationDrawable.grabSprites(sheet, startX, startY, frames);
    Array<TextureRegion> tempSpritesDown = AnimationDrawable.grabSprites(sheet, startX, startY + 2, frames);
    Array<TextureRegion> tempSpritesLeft = AnimationDrawable.grabSprites(sheet, startX, startY + 1, frames, true);
    Array<TextureRegion> tempSpritesRight = AnimationDrawable.grabSprites(sheet, startX, startY + 1, frames);

    AnimationDrawable.addMiddleReversed(tempSpritesUp, false);
    AnimationDrawable.addMiddleReversed(tempSpritesDown, false);
    AnimationDrawable.addMiddleReversed(tempSpritesLeft, false);
    AnimationDrawable.addMiddleReversed(tempSpritesRight, false);

    animations.put(Type.WALK_DOWN, new Animation(1f / (frames * 1.5f), tempSpritesDown));
    animations.put(Type.WALK_UP, new Animation(1f / (frames * 1.5f), tempSpritesUp));
    animations.put(Type.WALK_LEFT, new Animation(1f / (frames * 1.5f), tempSpritesLeft));
    animations.put(Type.WALK_RIGHT, new Animation(1f / (frames * 1.5f), tempSpritesRight));

    for(Animation animation : animations.values()) {
        animation.setPlayMode(Animation.PlayMode.LOOP);
    }

    setAnimationByType(Type.WALK_DOWN); // default animation
}
项目:cgc-game    文件:RiderBullet.java   
public RiderBullet(Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType,
        Body attachedBody, Vector2 target, Vector2 targetOffset, boolean deathBullet) {
    super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType,
            attachedBody, target, targetOffset);
    kill = deathBullet;

    if (kill) 
    {
        Flight_Speed = 1.0f;
    }
    else
    {
        Flight_Speed = 2.0f;
    }
}
项目:cocos2d-java    文件:ActionInterval.java   
/** Creates the action with an Animation and will restore the original frame when the animation is over.
 *
 * @param animation A certain animation.
 * @param modifier true : reset sprite size to frame; false:use sprite size
 * @return An autoreleased Animate object.
 */
public static Animate create(Animation animation, boolean modifierSprite) {
 Animate ret = new Animate();
 if(ret.initWithAnimation(animation, modifierSprite)) {
  return ret;
 }
 return null;
}
项目:cocos2d-java    文件:ActionInterval.java   
public Animate reverse() {
 final TextureRegion[] srcRegions = _animation.getKeyFrames();
 final int n = srcRegions.length;
 TextureRegion[] newRegions = new TextureRegion[n]; 
 for(int i = 0; i < n; ++i) {
  newRegions[i] = srcRegions[n - 1 - i];
 }
 Animation newAnimation = new Animation(_animation.getFrameDuration(), newRegions);
 newAnimation.setPlayMode(_animation.getPlayMode());
 return Animate.create(newAnimation);
}
项目:cocos2d-java    文件:ActionInterval.java   
/** initializes the action with an Animation and will restore the original frame when the animation is over */
public boolean initWithAnimation(Animation animation, boolean modifierSprite) {
 if (animation == null) {
      CCLog.error("Animate", "Animate::initWithAnimation: argument Animation must be non-nullptr");
      return false;
 }
 if(super.initWithDuration(animation.getAnimationDuration())) {
  _currFrameIndex = 0;
  _modifierSprite = modifierSprite;
  _animation = animation;
  return true;
 }
 return false;
}
项目:cocos2d-java    文件:FiniteActionTests.java   
public void onEnter() {
    super.onEnter();

    Texture t = CC.LoadImage("walkanim.png");
    TextureRegion[] ts = t.splitRowCol(1, 4);   //

    for(int i = 0; i < 4; ++i) {
        Sprite.createWithSpriteFrame(ts[i]).addTo(this).setPosition(100 + 100 * i, 200);
    }

    Animation animation = new Animation(3/30f, ts);
    Sprite spriteAnimation = (Sprite) Sprite.create().addTo(this);

    //修正sprite大小等动画 size设置无效
    spriteAnimation.runAction(RepeatForever.create(
            Animate.create(animation, true)));
    spriteAnimation.setContentSize(100, 100);
    spriteAnimation.setPosition(600, 320);

    //不修正sprite大小的动画
    Sprite spriteAnimation2 = (Sprite) Sprite.create().addTo(this);
    spriteAnimation2.runAction(RepeatForever.create(
            Animate.create(animation)));

    spriteAnimation2.setContentSize(100, 100);
    spriteAnimation2.setPosition(800, 320);
}
项目:feup-lpoo-armadillo    文件:PowerUpView.java   
/**
 * Creates the animation used for this PowerUp Type.
 *
 * @param game the game this view belongs to. Needed to access the
 *             asset manager to get textures.
 * @param fileName the path to the file that contains the animation sheet.
 * @return the animation used for this PowerUp
 */
private Animation<TextureRegion> createAnimation(Armadillo game, String fileName) {
    Texture texture = game.getAssetManager().get(fileName);
    TextureRegion[][] regions = TextureRegion.split(texture, texture.getWidth() / NUM_FRAMES, texture.getHeight());

    TextureRegion[] frames = new TextureRegion[NUM_FRAMES];
    System.arraycopy(regions[0], 0, frames, 0, NUM_FRAMES);

    return new Animation<>(FRAME_TIME, frames);
}
项目:odb-artax    文件:GameScreenAssetSystem.java   
private void loadSprites() {
    final Json json = new Json();
    spriteLibrary = json.fromJson(SpriteLibrary.class, Gdx.files.internal("sprites.json"));
    for (SpriteData sprite : spriteLibrary.sprites) {
        Animation animation = add(sprite.id, sprite.x, sprite.y, sprite.width, sprite.height, sprite.countX, sprite.countY, this.tileset, sprite.milliseconds * 0.001f);
    }
}
项目:odb-artax    文件:MapSystem.java   
@Override
protected void initialize() {
    map = new TmxMapLoader().load("map" + G.level + ".tmx");

    layers = new Array<TiledMapTileLayer>();
    for (MapLayer rawLayer : map.getLayers()) {
        layers.add((TiledMapTileLayer) rawLayer);
    }
    width = layers.get(0).getWidth();
    height = layers.get(0).getHeight();

    // need to do this before we purge the indicators from the map.
    mapCollisionSystem.canHoverMask = getMask("canhover");
    mapCollisionSystem.deadlyMask = getMask("deadly");
    mapCollisionSystem.solidForRobotMask = getMask("solidforrobot");

    for (TiledMapTileSet tileSet : map.getTileSets()) {
        for (TiledMapTile tile : tileSet) {
            final MapProperties props = tile.getProperties();
            if (props.containsKey("entity")) {
                Animation<TextureRegion> anim = new Animation<>(10, tile.getTextureRegion());
                String id = (String) props.get("entity");
                if (props.containsKey("cable-type")) {
                    id = cableIdentifier(tile);
                } else if (props.containsKey("powered")) {
                    id = props.get("entity") + "_" + (((Boolean) props.get("powered")) ? "on" : "off");
                    if (props.containsKey("accept")) {
                        id = id + "_" + props.get("accept");
                    }
                }
                assetSystem.sprites.put(id, anim);
            }
        }
    }
}
项目:Parasites-of-HellSpace    文件:Boom.java   
public Boom(float x, float y)
{
    texture = AssetLoader.assetManager.get("explosion.pack", TextureAtlas.class);
    animation = new Animation<TextureRegion>(1/15f, texture.getRegions());
    sprite = new Sprite(animation.getKeyFrame(0));
    elapsedTime = 0;
    sprite.setPosition(x, y);
    rotationAngle = MathUtils.random(359);
    sprite.setRotation(rotationAngle);
}
项目:SpaceChaos    文件:AtlasAnimationComponent.java   
public Animation<TextureRegion> getAnimationByName(String animationName) {
    // get animation
    Animation<TextureRegion> animation = this.animationMap.get(animationName);

    if (animation == null) {
        throw new IllegalStateException("Could not found animation: " + animationName);
    }

    return animation;
}
项目:miniventure    文件:MobAnimationController.java   
public MobAnimation(String mobSpriteName) {
    animations = new HashMap<>();

    for(AnimationState state: AnimationState.values) {
        for(String dir: Direction.names) {
            String name = state.name().toLowerCase()+"-"+dir;
            animations.put(name, new Animation<>(state.frameDuration, GameCore.entityAtlas.findRegions(mobSpriteName+"/"+name)));
        }
    }
}
项目:TH902    文件:PlayerReimu.java   
public PlayerReimu(int type) {
    mType = type;
    Texture texture = ResourceManager.textures.get("Reimu");
    TextureRegion[][] splitted = TextureRegion.split(texture, texture.getWidth() / 8, texture.getHeight() / 3);
    animationStay = new Animation<TextureRegion>(5, splitted[0]);
    animationStay.setPlayMode(PlayMode.LOOP);
    animationLeft = new Animation<TextureRegion>(4, splitted[1]);
    animationLeft.setPlayMode(PlayMode.LOOP);
    animationRight = new Animation<TextureRegion>(4, splitted[2]);
    animationRight.setPlayMode(PlayMode.LOOP);
}
项目:summer17-android    文件:Hero.java   
public Hero(World world, PlayScreen screen) {
    super(screen.getAtlas().findRegion("dudeRun4"));
    this.world = world;
    currentState = State.STANDING;
    previousState = State.STANDING;
    stateTimer = 0;
    runningRight = true;
    isLanded = true;
    this.playScreen = screen;

    Array<TextureRegion> frames = new Array<TextureRegion>();
    //running animation
    for (int i = 1; i < 5; i++) {
        frames.add(new TextureRegion(getTexture(), i * 53, 2, 40, 60));
    }
    heroRun = new Animation(0.1f, frames);
    frames.clear();

    //climbing animation
    for (int i = 6; i < 9; i++) {
        frames.add(new TextureRegion(getTexture(), i * 53, 2, 40, 60));
    }
    heroClimb = new Animation(0.1f, frames);


    defineHero();

    //determines size and starting position of standing on spritesheet
    heroStand = new TextureRegion(getTexture(), 2, 2, 40, 60);
    setBounds(0, 0, 40 / NoObjectionGame.PPM, 60 / NoObjectionGame.PPM);
    setRegion(heroStand);
}
项目:Ponytron    文件:Bullet.java   
public void init() {
    CURRENT_STATE = BULLET_STATE.LIVE;
    animation = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("bullet_a00"), AssetDoctor.getTextureRegion_ATLAS("bullet_a01"));
    animation.setPlayMode(Animation.PlayMode.LOOP);
    currentSprite = new Sprite(animation.getKeyFrame(elapsedTime));
    resizeSprite(currentSprite);
}
项目:Ponytron    文件:Spatula.java   
public Spatula(float x, float y) {
    super(x, y);
    FRAME_DURATION = 0.15f;
    SCALE = 2.5f;
    STEP_DIST = 15.0f;
    STEP_COOLDOWN = 0.150f;
    anim = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("spatula_00"), AssetDoctor.getTextureRegion_ATLAS("spatula_01"));
    anim.setPlayMode(Animation.PlayMode.LOOP);
    SPRITE = new Sprite(anim.getKeyFrame(0.0f));
    resizeSprite(SPRITE);
    killsound = DS.explosionSound;
}