List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion split
public TextureRegion[][] split(int tileWidth, int tileHeight)
From source file:com.biigoh.sprites.FrameSprite.java
License:Apache License
/** * Construct sprite.// w ww . j a v a 2 s .co m * * @param textureRegion * Sprite-sheet texture. * @param rows * Sprite-sheet rows. * @param cols * Sprite-sheet columns. * @param frameDuration * Duration between frames. * @param looping * Loop animation. */ public FrameSprite(TextureRegion textureRegion, int rows, int cols, float frameDuration, boolean looping) { this.looping = looping; int tileWidth = textureRegion.getRegionWidth() / cols; int tileHeight = textureRegion.getRegionHeight() / rows; TextureRegion[][] tmp = textureRegion.split(tileWidth, tileHeight); 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]; } } // Set the sprite width and height. width = tileWidth; height = tileHeight; animation = new Animation(frameDuration, frames); stateTime = 0f; }
From source file:com.jlabarca.texture.FrameSprite.java
License:Apache License
/** * Construct sprite.//from w ww . j a v a2 s . c o m * * @param texture * Sprite-sheet texture. * @param rows * Sprite-sheet rows. * @param cols * Sprite-sheet columns. * @param frameDuration * Duration between frames. * @param looping * Loop animation. */ public FrameSprite(TextureRegion texture, int rows, int cols, float frameDuration, boolean looping) { this.looping = looping; int tileWidth = texture.getRegionWidth() / cols; int tileHeight = texture.getRegionHeight() / rows; TextureRegion[][] tmp = texture.split(tileWidth, tileHeight); 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]; } } // Set the sprite width and height. this.setWidth(tileWidth); this.setHeight(tileHeight); animation = new Animation(frameDuration, frames); stateTime = 0f; }
From source file:com.mknsri.drunktoss.Loader.Art.java
License:Open Source License
public static TextureRegion[] loadAnimation(String fileName, int width, int height, int frameCols, int frameRows) { TextureRegion img = loadSprite(fileName, width * frameCols, height * frameRows); TextureRegion[][] spritesheetTemp = img.split(width, height); TextureRegion[] spritesheet = new TextureRegion[frameRows * frameCols]; // Fix the indices frameCols--;// w w w . jav a 2 s .c om frameRows--; for (int i = 0; i <= frameRows; i++) { for (int y = 0; y <= frameCols; y++) { spritesheet[i + y] = spritesheetTemp[i][y]; } } return spritesheet; }
From source file:com.netthreads.gdx.app.sprite.StateSprite.java
License:Apache License
/** * Construct sprite./*from ww w . j a va 2 s .c o m*/ * * @param texture * Sprite-sheet texture. * @param rows * Sprite-sheet rows. * @param cols * Sprite-sheet columns. */ public StateSprite(TextureRegion texture, int rows, int cols) { int tileWidth = texture.getRegionWidth() / cols; int tileHeight = texture.getRegionHeight() / rows; TextureRegion[][] tmp = texture.split(tileWidth, tileHeight); 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]; } } // Set the sprite width and height. setWidth(tileWidth); setHeight(tileHeight); // Initialise the current frame. setFrame(0); }
From source file:com.netthreads.libgdx.sprite.FrameSprite.java
License:Apache License
public FrameSprite(TextureRegion texture, int rows, int cols, int rowsUsed, int colsUsed, float frameDuration, int restartFrame, boolean looping) { this.looping = looping; this.frameDuration = frameDuration; int tileWidth = texture.getRegionWidth() / cols; int tileHeight = texture.getRegionHeight() / rows; TextureRegion[][] tmp = texture.split(tileWidth, tileHeight); frames = new TextureRegion[rowsUsed * colsUsed]; this.restartFrame = restartFrame; int index = 0; for (int i = 0; i < rowsUsed; i++) { for (int j = 0; j < colsUsed; j++) { frames[index++] = tmp[i][j]; }//from w w w.j av a2 s . co m } // Set the sprite width and height. setWidth(tileWidth); setHeight(tileHeight); animation = new Animation(frameDuration, frames); stateTime = 0f; }
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);//from ww w . ja v a2 s .co m animations.put("Explosion", a); r = atlas.findRegion("EnemyDeath"); grid = r.split(64, 128); a = new Animation(0.06f, grid[0]); a.setPlayMode(PlayMode.NORMAL); animations.put("EnemyDeath", a); }
From source file:jordanlw.gdxGame.Game.java
License:Open Source License
public void create() { aMusicLibrary = new MusicLibrary(); aMusicLibrary.backgroundMusic.setLooping(false); aMusicLibrary.backgroundMusic.setVolume(0.15f * volume); Gdx.input.setInputProcessor(new InputProcessor()); //Load images of text gameOverTexture = new Texture(Gdx.files.internal("images/gameover.png")); gameStartTexture = new Texture(Gdx.files.internal("images/press-p-to-play.png")); //tiled background images backgroundTexture = new Texture(Gdx.files.internal("images/grey-background-seamless.jpg")); backgroundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat); TextureRegion playerLegsCropped = new TextureRegion( new Texture(Gdx.files.internal("images/feet-sheet.png"))); legsAnim = new Animation(0.105f, playerLegsCropped.split(23, 38)[0]); legsAnim.setPlayMode(Animation.PlayMode.LOOP); TextureRegion playerTorso = new TextureRegion( new Texture(Gdx.files.internal("images/human-shooting-sheet.png"))); torsoAnim = new Animation(torsoAnimLength / 6, playerTorso.split(33, 63)[0]); torsoAnim.setPlayMode(Animation.PlayMode.LOOP); //gold coin spritesheet Texture goldTexture = new Texture(Gdx.files.internal("images/goldcoin-sheet.png")); TextureRegion[][] goldTmp = TextureRegion.split(goldTexture, goldTexture.getWidth() / 4, goldTexture.getHeight());/* www. j av a 2 s . c om*/ goldSheet = goldTmp[0]; singlePixel = new TextureRegion(new Texture(Gdx.files.internal("images/singlePixel.png"))); camera = new OrthographicCamera(); camera.setToOrtho(false, windowSize.x, windowSize.y); batch = new SpriteBatch(); medkit = new Medkit(); medkit.health = 0; players.add(0, new Player()); players.get(0).isSelf = true; }
From source file:jordanlw.gdxGame.Zombie.java
License:Open Source License
public Zombie() { swarmAngle = (float) (-100 * Math.random() + 50); this.walkingSpeed = getNewWalkingSpeed(); //Load image of enemy & creates animation object for them TextureRegion enemyCropped = new TextureRegion(new Texture(Gdx.files.internal("images/zombies.png"))); anim = new Animation(0.20f, enemyCropped.split(41, 41)[0]); anim.setPlayMode(Animation.PlayMode.LOOP); animRect.width = anim.getKeyFrame(0).getRegionWidth(); animRect.height = anim.getKeyFrame(0).getRegionHeight(); //Explosion/damaged overlay spirtesheet Texture flameTexture = new Texture(Gdx.files.internal("images/explosion-sheet.png")); TextureRegion[][] flameTmp = TextureRegion.split(flameTexture, flameTexture.getWidth() / 4, flameTexture.getHeight());/*from www.j a va2 s . c o m*/ flame = new Animation(0.16f, flameTmp[0]); position.setSize(anim.getKeyFrame(0).getRegionWidth(), anim.getKeyFrame(0).getRegionHeight()); }
From source file:net.mwplay.cocostudio.ui.widget.LabelAtlas.java
License:Apache License
/** * @param tr ??/*from w w w . jav a 2 s .com*/ * @param tileWidth * @param tileHeight * @param startCharMap ,:0123456789*+-x * ,?.? * @param stringValue ,:89/50 */ public LabelAtlas(TextureRegion tr, int tileWidth, int tileHeight, String startCharMap, String stringValue) { this.tileWidth = tileWidth; this.tileHeight = tileHeight; TextureRegion[][] arr = tr.split(tileWidth, tileHeight); trs = arr[0]; if (startCharMap == null) { startCharMap = "0"; // } this.chars = startCharMap.toCharArray(); setText(stringValue); }