當前位置: 首頁>>代碼示例>>Java>>正文


Java Animation類代碼示例

本文整理匯總了Java中com.badlogic.gdx.graphics.g2d.Animation的典型用法代碼示例。如果您正苦於以下問題:Java Animation類的具體用法?Java Animation怎麽用?Java Animation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Animation類屬於com.badlogic.gdx.graphics.g2d包,在下文中一共展示了Animation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCachedAnimations

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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++;
    }
}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:23,代碼來源:AtlasAnimationComponent.java

示例2: createAnimationFromTexture

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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;

}
 
開發者ID:opensourcegamedev,項目名稱:SpaceChaos,代碼行數:21,代碼來源:AnimationTextureUtils.java

示例3: pollAnimation

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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;
}
 
開發者ID:chrisj42,項目名稱:miniventure,代碼行數:20,代碼來源:MobAnimationController.java

示例4: Create

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:cn-s3bit,項目名稱:TH902,代碼行數:30,代碼來源:BaseSprite.java

示例5: init

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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;
    }
 
開發者ID:dsaves,項目名稱:Ponytron,代碼行數:17,代碼來源:Pony.java

示例6: inserted

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
@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);
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:27,代碼來源:BulletRenderer.java

示例7: Entity

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:cderienzo,項目名稱:Hackerman,代碼行數:30,代碼來源:Entity.java

示例8: initialize

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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);
	
}
 
開發者ID:ja-brouil,項目名稱:StarshipFighters,代碼行數:21,代碼來源:Animator.java

示例9: GameState

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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>();
}
 
開發者ID:kyperbelt,項目名稱:KyperBox,代碼行數:17,代碼來源:GameState.java

示例10: init

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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);
}
 
開發者ID:heyzqt,項目名稱:libGdx-xiyou,代碼行數:19,代碼來源:JumpBall.java

示例11: CellView

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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);
}
 
開發者ID:antonioalmeida,項目名稱:retro-reversi,代碼行數:21,代碼來源:CellView.java

示例12: BossEnemy

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:johannesmols,項目名稱:GangsterSquirrel,代碼行數:32,代碼來源:BossEnemy.java

示例13: Explosion

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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);
}
 
開發者ID:overengineering,項目名稱:space-travels-3,代碼行數:24,代碼來源:Explosion.java

示例14: getAnimation

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
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;
}
 
開發者ID:kibertoad,項目名稱:ld37,代碼行數:18,代碼來源:ScheduleSubView.java

示例15: visualize

import com.badlogic.gdx.graphics.g2d.Animation; //導入依賴的package包/類
@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();
}
 
開發者ID:ratrecommends,項目名稱:dice-heroes,代碼行數:26,代碼來源:AddEffectVisualizer.java


注:本文中的com.badlogic.gdx.graphics.g2d.Animation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。