List of usage examples for com.badlogic.gdx.graphics.g2d Animation Animation
public Animation(float frameDuration, TextureRegion... keyFrames)
From source file:MyGdxGame.java
License:Apache License
@Override public void create() { // load the koala frames, split them, and assign them to Animations koalaTexture = new Texture("koalio.png"); TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0]; stand = new Animation(0, regions[0]); jump = new Animation(0, regions[1]); walk = new Animation(0.15f, regions[2], regions[3], regions[4]); walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG); // figure out the width and height of the koala for collision // detection and rendering by converting a koala frames pixel // size into world units (1 unit == 16 pixels) Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth(); Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight(); // load the map, set the unit scale to 1/16 (1 unit == 16 pixels) map = new TmxMapLoader().load("level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f); // create an orthographic camera, shows us 30x20 units of the world camera = new OrthographicCamera(); camera.setToOrtho(false, 30, 20);//from www .j ava 2 s. co m camera.update(); // create the Koala we want to move around the world koala = new Koala(); koala.position.set(20, 20); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.anim.CountDown.java
License:Open Source License
/** * Constructor for a CountDown Object /*from ww w . j a v a 2s. co m*/ * Automatically load the images/anim/countdown.png, countDown * * public CountDown(final int col, final int row * final String path, final boolean resume) */ public CountDown(final int col, final int row, final float time, final String path, final boolean resume) { FRAME_COLS = col; FRAME_ROWS = row; N_FRAME = col * row; STEPTIME = time; RESUME_AFTER_END = resume; countDownSheet = new Texture(path); TextureRegion[][] tmp = TextureRegion.split(countDownSheet, countDownSheet.getWidth() / FRAME_COLS, countDownSheet.getHeight() / FRAME_ROWS); countDownFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS]; int index = 0; for (int i = 0; i < FRAME_ROWS; i++) { for (int j = 0; j < FRAME_COLS; j++) { countDownFrames[index++] = tmp[i][j]; } } countDownAnimation = new Animation(STEPTIME, countDownFrames); stateTime = 0f; }
From source file:ch.coldpixel.alpha.main.Player.java
public void changeAnimation(Texture texture, int columns, int rows, float frameDuration) { sheet = texture;//from w w w .j av a 2s . c om TextureRegion[][] tmp = TextureRegion.split(sheet, sheet.getWidth() / columns, sheet.getHeight() / rows); animFrames = new TextureRegion[rows * columns]; int index = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { animFrames[index++] = tmp[i][j]; } } animation = new Animation(frameDuration, animFrames); setAnimation(animation); }
From source file:ch.coldpixel.mario.Sprites.Mario.java
public Mario(World world, PlayScreen screen) { super(screen.getAtlas().findRegion("little_mario")); this.world = world; currentState = State.STANDING; previousState = State.STANDING; stateTimer = 0;/* w w w. j a v a2 s .co m*/ runningRight = true; Array<TextureRegion> frames = new Array<TextureRegion>(); for (int i = 1; i < 4; i++) { frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16)); } marioRun = new Animation(0.1f, frames); frames.clear(); for (int i = 4; i < 6; i++) { frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16)); } marioJump = new Animation(0.1f, frames); marioStand = new TextureRegion(getTexture(), 0, 0, 16, 16); defineMario(); setBounds(0, 0, 16 / MarioBros.PPM, 16 / MarioBros.PPM); setRegion(marioStand); }
From source file:com.agateau.pixelwheels.Assets.java
License:Open Source License
Assets() { if (GamePlay.instance.showTestTrack) { tracks.add(new Track("test", "Test")); }/*from w ww . ja v a2s. co m*/ this.atlas = new StrictTextureAtlas(Gdx.files.internal("sprites/sprites.atlas")); this.wheel = findRegion("wheel"); this.explosion = new Animation<TextureRegion>(EXPLOSION_FRAME_DURATION, this.atlas.findRegions("explosion")); this.impact = new Animation<TextureRegion>(IMPACT_FRAME_DURATION, this.atlas.findRegions("impact")); this.mine = new Animation<TextureRegion>(MINE_FRAME_DURATION, this.atlas.findRegions("mine")); this.mine.setPlayMode(Animation.PlayMode.LOOP); this.turbo = new Animation<TextureRegion>(TURBO_FRAME_DURATION, this.atlas.findRegions("bonus-turbo")); this.turboFlame = new Animation<TextureRegion>(TURBO_FLAME_FRAME_DURATION, this.atlas.findRegions("turbo-flame")); this.turboFlame.setPlayMode(Animation.PlayMode.LOOP_PINGPONG); this.splash = new Animation<TextureRegion>(TURBO_FLAME_FRAME_DURATION, this.atlas.findRegions("splash")); this.gift = findRegion("gift"); this.gunAnimation = new Animation<TextureRegion>(0.1f / 3, this.atlas.findRegions("bonus-gun")); this.bullet = findRegion("bullet"); // Fix white-pixel to avoid fading borders this.dot = findRegion("white-pixel"); removeBorders(this.dot); this.skidmark = findRegion("skidmark"); this.missile = findRegion("missile"); this.target = findRegion("target"); this.helicopterBody = this.findRegion("helicopter-body"); this.helicopterPropeller = this.findRegion("helicopter-propeller"); this.helicopterPropellerTop = this.findRegion("helicopter-propeller-top"); loadVehicleDefinitions(); initSoundAtlas(); initChampionships(); }
From source file:com.android.ringfly.common.Assets.java
License:Apache License
private static void createAnimations() { demonRun = new Animation(DEMON_RUN_FRAME_DURATION, demonRunRegions); demonDie = new Animation(DEMON_DIE_FRAME_DURATION, demonDieRegions); earthFightWaterAnim = new Animation(DEMON_RUN_FRAME_DURATION, earthFightWaterRegions); woodFightEarthAnim = new Animation(DEMON_RUN_FRAME_DURATION, woodFightEarthRegions); waterFightFireAnim = new Animation(DEMON_RUN_FRAME_DURATION, waterFightFireRegions); fireFightMetalAnim = new Animation(DEMON_RUN_FRAME_DURATION, fireFightMetalRegions); metalFightWoodAnim = new Animation(DEMON_RUN_FRAME_DURATION, metalFightWoodRegions); failMetalAnim = new Animation(DEMON_RUN_FRAME_DURATION, failMetalRegions); failWoodAnim = new Animation(DEMON_RUN_FRAME_DURATION, failWoodRegions); failWaterAnim = new Animation(DEMON_RUN_FRAME_DURATION, failWaterRegions); failFireAnim = new Animation(DEMON_RUN_FRAME_DURATION, failFireRegions); failEarthAnim = new Animation(DEMON_RUN_FRAME_DURATION, failEarthRegions); popoAnim = new Animation(DEMON_RUN_FRAME_DURATION, popoRegions); hideRunAnim = new Animation(DEMON_RUN_FRAME_DURATION, hideRunRegions); metalRunAnim = new Animation(DEMON_RUN_FRAME_DURATION, metalRunRegions); taiJiRunAnim = new Animation(DEMON_RUN_FRAME_DURATION, taiJiRunRegions); allFightTaiJiDieAnim = new Animation(DEMON_RUN_FRAME_DURATION, allFightTaiJiDieRegions); metalHandAnim = new Animation(0.2f, metalHandRegions); woodHandAnim = new Animation(0.2f, woodHandRegions); waterHandAnim = new Animation(0.2f, waterHandRegions); fireHandAnim = new Animation(0.2f, fireHandRegions); earthHandAnim = new Animation(0.2f, earthHandRegions); allHandAnim = new Animation(0.2f, allHandRegions); earthDemonRun = new Animation(DEMON_RUN_FRAME_DURATION, earthDemonRunRegions); fireAnim = new Animation(DEMON_RUN_FRAME_DURATION, fireRegions); }
From source file:com.arkanoid.Actors.ActorFactory.java
License:Open Source License
/** * Create a player using the default texture. * @param world world where the player will have to live in. * @param position initial position ofr the player in the world (meters,meters). * @return a player./* w ww.jav a2 s . co m*/ */ public PlayerActor createPlayer(World world, Vector2 position) { //Texture playerTexture = manager.get("player.png"); TextureAtlas atlas = manager.get("sprites_player.txt", TextureAtlas.class); HashMap<PlayerActor.PlayerAnimations, Animation> animations = new HashMap<PlayerActor.PlayerAnimations, Animation>(); Array<TextureAtlas.AtlasRegion> playerRegions = atlas.findRegions("red_medium"); Array<TextureAtlas.AtlasRegion> playerRegionsReverse = atlas.findRegions("red_medium"); playerRegionsReverse.reverse(); playerRegions.addAll(playerRegionsReverse); animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("red_large"); playerRegionsReverse = atlas.findRegions("red_large"); playerRegionsReverse.reverse(); playerRegions.addAll(playerRegionsReverse); animations.put(PlayerActor.PlayerAnimations.RED_LARGE, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("red_medium_create"); animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM_CREATE, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("red_medium_destoy"); animations.put(PlayerActor.PlayerAnimations.RED_MEDIUM_DESTROY, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("blue_medium"); playerRegionsReverse = atlas.findRegions("blue_medium"); playerRegionsReverse.reverse(); playerRegions.addAll(playerRegionsReverse); animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("blue_large"); playerRegionsReverse = atlas.findRegions("blue_large"); playerRegionsReverse.reverse(); playerRegions.addAll(playerRegionsReverse); animations.put(PlayerActor.PlayerAnimations.BLUE_LARGE, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("blue_medium_create"); animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM_CREATE, new Animation(1f / (float) playerRegions.size, playerRegions)); playerRegions = atlas.findRegions("blue_medium_destoy"); animations.put(PlayerActor.PlayerAnimations.BLUE_MEDIUM_DESTROY, new Animation(1f / (float) playerRegions.size, playerRegions)); return new PlayerActor(world, animations, position); }
From source file:com.arkanoid.Actors.ActorFactory.java
License:Open Source License
public BlockActor createBlock(World world, Vector2 position, String color) { TextureAtlas atlas = manager.get("sprites_board.txt", TextureAtlas.class); TextureRegion texture = atlas.findRegion("block_" + color); Animation animation = null;/* w w w .ja v a 2 s.c o m*/ int hardness = 1; if (color.equals("plate") || color.equals("golden")) { hardness = color.equals("golden") ? 99 : 2; Array<TextureAtlas.AtlasRegion> blockRegions = atlas.findRegions("block_" + color); animation = new Animation(0.5f / (float) blockRegions.size, blockRegions); } BlockActor block = new BlockActor(world, position, texture, animation, hardness); if (color.equals("plate") || color.equals("golden")) { block.StartAnimation(); } return block; }
From source file:com.arnopaja.supermac.helpers.load.AssetLoader.java
License:Creative Commons License
public static void load() { tilesTexture = new Texture(getHandle("canvas/landscape_tiles.png")); tilesTexture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); //-------------------------- // Tiles //-------------------------- treeBig = SpriteUtils.makeSprite(tilesTexture, 0, 0, 2, 2); treeSmall = SpriteUtils.makeSprite(tilesTexture, 2, 0); grass0 = SpriteUtils.makeSprite(tilesTexture, 3, 0); grass1 = SpriteUtils.makeSprite(tilesTexture, 4, 0); grass2 = SpriteUtils.makeSprite(tilesTexture, 5, 0); bush = SpriteUtils.makeSprite(tilesTexture, 6, 0); bushH = SpriteUtils.makeSprite(tilesTexture, 7, 0); bushFlowersH = SpriteUtils.makeSprite(tilesTexture, 8, 0); bushV = SpriteUtils.makeSprite(tilesTexture, 9, 0); bushFlowersV = SpriteUtils.makeSprite(tilesTexture, 10, 0); sidewalk = SpriteUtils.makeSprite(tilesTexture, 11, 0); cobbleRed = SpriteUtils.makeSprite(tilesTexture, 0, 2); cobble = SpriteUtils.makeSprite(tilesTexture, 1, 2); asphalt = SpriteUtils.makeSprite(tilesTexture, 5, 4); asphaltGrassE = SpriteUtils.makeSprite(tilesTexture, 0, 3); asphaltGrassW = SpriteUtils.makeSprite(tilesTexture, 0, 3, false, true); asphaltGrassN = SpriteUtils.makeSprite(tilesTexture, 0, 4); asphaltGrassS = SpriteUtils.makeSprite(tilesTexture, 0, 4, true, false); asphaltGrassNE = SpriteUtils.makeSprite(tilesTexture, 2, 3); asphaltGrassSE = SpriteUtils.makeSprite(tilesTexture, 2, 3, true, false); asphaltGrassSW = SpriteUtils.makeSprite(tilesTexture, 2, 3, true, true); asphaltGrassNW = SpriteUtils.makeSprite(tilesTexture, 2, 3, false, true); asphaltLineH = SpriteUtils.makeSprite(tilesTexture, 4, 3); asphaltLineV = SpriteUtils.makeSprite(tilesTexture, 4, 4); asphaltCobbleE = SpriteUtils.makeSprite(tilesTexture, 6, 3, false, true); asphaltCobbleW = SpriteUtils.makeSprite(tilesTexture, 6, 3); asphaltCobbleN = SpriteUtils.makeSprite(tilesTexture, 5, 3); asphaltCobbleS = SpriteUtils.makeSprite(tilesTexture, 5, 3, true, false); asphaltCobbleNE = SpriteUtils.makeSprite(tilesTexture, 6, 4, false, true); asphaltCobbleSE = SpriteUtils.makeSprite(tilesTexture, 6, 4, true, true); asphaltCobbleSW = SpriteUtils.makeSprite(tilesTexture, 6, 4, true, false); asphaltCobbleNW = SpriteUtils.makeSprite(tilesTexture, 6, 4); TextureRegion[] temp = new TextureRegion[12]; for (int i = 0; i < 7; i++) { temp[i] = SpriteUtils.makeSprite(tilesTexture, 17 + 3 * i, 0, 3, 3); if (i != 0) { temp[12 - i] = temp[i];//from w w w . jav a2 s.c om } } asteroid = new Animation(0.5f, temp); //-------------------------- // Buildings //-------------------------- weyerhauser = SpriteUtils.makeSprite(tilesTexture, 0, 5, 24, 12); campusCenter = SpriteUtils.makeSprite(tilesTexture, 24, 5, 20, 16); chapel = SpriteUtils.makeSprite(tilesTexture, 44, 5, 14, 16); kirk = SpriteUtils.makeSprite(tilesTexture, 58, 29, 32, 16); leonardCenter = SpriteUtils.makeSprite(tilesTexture, 58, 5, 52, 24); library = SpriteUtils.makeSprite(tilesTexture, 0, 17, 16, 12); oldMain = SpriteUtils.makeSprite(tilesTexture, 16, 17, 6, 12); olin = SpriteUtils.makeSprite(tilesTexture, 42, 21, 16, 32); olinRiceStairs = SpriteUtils.makeSprite(tilesTexture, 38, 43, 3, 5); rice = SpriteUtils.makeSprite(tilesTexture, 34, 53, 24, 16); MapLoader.initTileMap(); // Must be called after all tiles and buildings are loaded //-------------------------- // Entities //-------------------------- entitiesTexture = new Texture(getHandle("canvas/entities.png")); chestBrownClosed = SpriteUtils.makeSprite(tilesTexture, 0, 0); chestBrownOpen = SpriteUtils.makeSprite(tilesTexture, 0, 1); chestRedClosed = SpriteUtils.makeSprite(tilesTexture, 1, 0); chestRedOpen = SpriteUtils.makeSprite(tilesTexture, 1, 1); chestGreenClosed = SpriteUtils.makeSprite(tilesTexture, 2, 0); chestGreenOpen = SpriteUtils.makeSprite(tilesTexture, 2, 1); //-------------------------- // Characters //-------------------------- charactersHandle = getHandle("characters"); for (FileHandle handle : charactersHandle.list()) { loadCharacter(handle); } //-------------------------- // Handles and Caches //-------------------------- itemHandle = getHandle("items.txt"); spellHandle = getHandle("spells.txt"); dialogueHandle = getHandle("macalester/dialogues.txt"); cleanDialogueHandle = getHandle("macalester/dialogues_clean.txt"); mapHandle = getHandle("macalester/maps"); plotHandle = getHandle("macalester/plot.txt"); entitiesHandle = getHandle("macalester/entities.txt"); SuperParser.parseAll(AssetLoader.itemHandle, GenericItem.class); SuperParser.parseAll(AssetLoader.spellHandle, Spell.class); grids = MapLoader.generateGrids(AssetLoader.mapHandle); //-------------------------- // Music and Sounds //-------------------------- //TODO: Give credit to Rolemusic for the music under the Creative Commons Attribution License //Artist: Rolemusic //Album: gigs n' contest worldMusic = loadMusic("Rolemusic_-_03_-_Another_beek_beep_beer_please.mp3"); battleMusic = loadMusic("Rolemusic_-_04_-_Scape_from_the_city.mp3"); bossMusic = loadMusic("Rolemusic_-_05_-_Death_on_the_battlefield.mp3"); compSciMagic = Gdx.audio.newSound(getHandle("sounds/compscimagic.ogg")); natSciMagic = Gdx.audio.newSound(getHandle("sounds/natscimagic.ogg")); healingSound = Gdx.audio.newSound(getHandle("sounds/healingmagic.ogg")); powerupSound = Gdx.audio.newSound(getHandle("sounds/powerup.ogg")); BattleClass.init(); // needed to init the magic sounds //-------------------------- // Other //-------------------------- font = new BitmapFont(getHandle("font/text.fnt")); shadow = new BitmapFont(getHandle("font/shadow.fnt")); scaleFont(FONT_HEIGHT / AssetLoader.font.getLineHeight()); prefs = Gdx.app.getPreferences("com_arnopaja_supermac"); }
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 w w w .ja va 2 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)); }