List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion flip
public void flip(boolean x, boolean y)
From source file:ch.coldpixel.mario.Sprites.Mario.java
public TextureRegion getFrame(float dt) { currentState = getState();// w w w . java 2 s .c o m TextureRegion region; switch (currentState) { case JUMPING: region = marioJump.getKeyFrame(stateTimer); break; case RUNNING: region = marioRun.getKeyFrame(stateTimer, true); break; case FALLING: case STANDING: default: region = marioStand; break; } if ((b2body.getLinearVelocity().x < 0 || !runningRight) && !region.isFlipX()) { region.flip(true, false); runningRight = false; } else if ((b2body.getLinearVelocity().x > 0 || runningRight) && region.isFlipX()) { region.flip(true, false); runningRight = true; } stateTimer = currentState == previousState ? stateTimer + dt : 0; previousState = currentState; return region; }
From source file:com.bagon.matchteam.mtx.animation.AnimationCreator.java
License:Apache License
/** * Get animation from texture atlas (Based on TexturePacker). Each frames' * base name should be same. This is for multi textures, (Each frame stored * individually in texture atlas)/*from w w w. j av a2 s . co m*/ * <p> * EXAMPLE: <br> * baseName = "walk"<br> * frame1 = "walk00" (Actual name in texture atlas)<br> * frame2 = "walk01" (Actual name in texture atlas)<br> * frame3 = "walk02" (Actual name in texture atlas)<br> * ... * * @param textureAtlas * atlas which contains texture frames * @param animationBaseName * base name of the frames in atlas * @param numberOfFrames * number of frames of the animation * @param frameDuration * each frame duration on play * @return animation created * * */ public static Animation getAnimationFromMultiTextures(TextureAtlas textureAtlas, String animationBaseName, int numberOfFrames, float frameDuration, boolean flipX, boolean flipY) { // Key frames list TextureRegion[] keyFrames = new TextureRegion[numberOfFrames]; // Set key frames (each textures region from atlas) for (int i = 0; i < numberOfFrames; i++) { TextureRegion frame = textureAtlas.findRegions(animationBaseName).get(i); frame.flip(flipX, flipY); keyFrames[i] = frame; } // Animation animation = new Animation(frameDuration, keyFrames); return animation; }
From source file:com.codamasters.LNHelpers.AnimatedSprite.java
License:Apache License
/** flips all frames from {@code startTime} to {@code endTime} * @param startTime the animation state time of the first frame to flip * @param endTime the animation state time of the last frame to flip * @param set if the frames should be set to {@code flipX} and {@code flipY} instead of actually flipping them */ public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set) { for (float t = startTime; t < endTime; t += animation.getFrameDuration()) { TextureRegion frame = animation.getKeyFrame(t); frame.flip(flipX && (set ? !frame.isFlipX() : true), flipY && (set ? !frame.isFlipY() : true)); }/*from w ww . j a v a 2s. co m*/ }
From source file:com.explatcreations.sft.Assets.java
License:Open Source License
public static TextureRegion makeTextureRegion(Texture t, int x, int y, int width, int height) { TextureRegion region = new TextureRegion(t, x, y, width, height); region.flip(false, true); return region; }
From source file:com.forerunnergames.peril.client.ui.screens.menus.MenuScreenWidgetFactory.java
License:Open Source License
private TextureRegion createRightMenuBarShadowTextureRegion() { final TextureRegion region = new TextureRegion(createLeftMenuBarShadowTextureRegion()); region.flip(true, false); return region; }
From source file:com.garciagars.Game.java
License:Open Source License
void DrawBG(SpriteBatch batch) { batch.draw(bg, 0f, 0f, width, height); TextureRegion dangerTexture = new TextureRegion(danger); dangerTexture.flip(false, true); batch.draw(dangerTexture, 0f, dangerDistance, width, 50f); dangerCollision = new Rectangle(0f, dangerDistance, width, 50f); }
From source file:com.gdx.game.sprites.Player.java
public TextureRegion getFrame(float dt) { currentState = getState();/* www. ja v a2s. c o m*/ TextureRegion region; switch (currentState) { case JUMPING: region = marioJump.getKeyFrame(stateTimer); break; case RUNNING: region = marioRun.getKeyFrame(stateTimer, true); break; case FALLING: case STANDING: default: region = marioStand; break; } if ((b2body.getLinearVelocity().x < 0 || !runningRight) && !region.isFlipX()) { region.flip(true, false); runningRight = false; } else if ((b2body.getLinearVelocity().x > 0 || runningRight) && region.isFlipX()) { region.flip(true, false); runningRight = true; } stateTimer = (currentState == previousState) ? stateTimer + dt : 0; previousState = currentState; return region; }
From source file:com.github.fauu.helix.graphics.AnimatedDecal.java
License:Apache License
@Override public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set) { Animation animation = getAnimated(); for (float t = startTime; t < endTime; t += animation.getFrameDuration()) { TextureRegion frame = animation.getKeyFrame(t); frame.flip(flipX && (!set || !frame.isFlipX()), flipY && (!set || !frame.isFlipY())); }// w ww . j a v a2 s . c o m }
From source file:com.haxtastic.haxmasher.Art.java
License:Apache License
public static TextureRegion load(String name, int width, int height) { Texture texture = new Texture(Gdx.files.internal(name)); TextureRegion region = new TextureRegion(texture, 0, 0, width, height); region.flip(false, true); return region; }
From source file:com.idp.engine.net.NetworkImage.java
@Override protected void sizeChanged() { if (texToDraw == null) return;//from w ww . ja va 2s . c om Texture tex = texToDraw.getTexture(); if (tex == null) return; TextureRegion region = new TextureRegion(tex); float aspect = getWidth() / getHeight(); float texAspect = tex.getWidth() * 1f / tex.getHeight(); if (aspect > texAspect) { int h = (int) (tex.getHeight() * (texAspect / aspect)); region.setRegionY((tex.getHeight() - h) / 2); // important to set pos before size region.setRegionWidth(tex.getWidth()); region.setRegionHeight(h); } else { int w = (int) (tex.getWidth() / (texAspect / aspect)); region.setRegionX((tex.getWidth() - w) / 2); region.setRegionHeight(tex.getHeight()); region.setRegionWidth(w); } region.flip(false, true); // important to flip after all texToDraw = region; }