List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion isFlipX
public boolean isFlipX()
From source file:ch.coldpixel.mario.Sprites.Mario.java
public TextureRegion getFrame(float dt) { currentState = getState();/*from ww w.j a v a 2s . co 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.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)); }/*ww w. java 2 s .c o m*/ }
From source file:com.gdx.game.sprites.Player.java
public TextureRegion getFrame(float dt) { currentState = getState();//from w ww. ja v a 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.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())); }/*from w ww .j av a2s . c o m*/ }
From source file:com.me.cyberPunkJam.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.frameDuration) { TextureRegion frame = animation.getKeyFrame(t); frame.flip(flipX && (set ? !frame.isFlipX() : true), flipY && (set ? !frame.isFlipY() : true)); }/*from w w w . j a v a 2s. co m*/ }
From source file:com.mygdx.game.Sprites.Player.Player.java
public void getFrame(float dt) { TextureRegion region; currentState = getState();//from w w w. j a v a2 s .c o m switch (currentState) { case STANDING: if (TimeState < 5) { region = stand; } else if (TimeState < 5 + standing.getAnimationDuration()) { region = standing.getKeyFrame(TimeState - 5); } else if (TimeState < (5 + standing.getAnimationDuration() + (6 * standingLoop1.getAnimationDuration()))) { region = standingLoop1.getKeyFrame(TimeState - 5 - standing.getAnimationDuration()); } else if (TimeState < (5 + standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration())) { region = standing2.getKeyFrame(TimeState - 5 - (standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration())); } else if (TimeState < (5 + standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration() + 5 * standingLoop2.getAnimationDuration())) { region = standingLoop2.getKeyFrame(TimeState - 5 - (standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration())); } else if (TimeState < (5 + standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration() + 5 * standingLoop2.getAnimationDuration() + standing.getAnimationDuration())) { region = standing3.getKeyFrame( TimeState - 5 - (standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration() + 5 * standingLoop2.getAnimationDuration())); } else { TimeState = 5 + standing.getAnimationDuration() + 6 * standingLoop1.getAnimationDuration() + standing2.getAnimationDuration(); region = standingLoop2.getKeyFrame(0); } break; case SHOOTING: region = shooting.getKeyFrame(TimeState); break; case CRAWLING: region = crawling.getKeyFrame(TimeState); break; case CRAWLINGMOVING: region = crawlingmoving.getKeyFrame(TimeState); break; case CRAWLSHOT: region = crawlshot.getKeyFrame(TimeState); break; case JUMPING: region = jumping.getKeyFrame(TimeState); break; case HIT: region = hitting.getKeyFrame(TimeState); if (hitting.isAnimationFinished(TimeState) && previousState == State.HIT) { hit = false; } break; case DYNAMITE: region = holding.getKeyFrame(TimeState); if (holding.getKeyFrameIndex(TimeState) == 5 && Tothrow && previousState == State.DYNAMITE) { screen.addDynamite(new Dynamite(screen, b2body.getPosition().x + (this.getWidth() / 2), b2body.getPosition().y + 15 / (AdventureGame.PPM * 2), runningRight)); Tothrow = false; } break; case FALLING: region = falling.getKeyFrame(TimeState); break; case RUNNING: default: region = running.getKeyFrame(TimeState); break; } if ((!runningRight) && !region.isFlipX()) { region.flip(true, false); } else if ((runningRight) && region.isFlipX()) { region.flip(true, false); } setRegion(region); if (currentState != previousState) { TimeState = 0; Tothrow = true; } else { TimeState += dt; } previousState = currentState; super.setSize(region.getRegionWidth() / (AdventureGame.PPM * 2), region.getRegionHeight() / (AdventureGame.PPM * 2)); }
From source file:com.mygdx.game.Sprites.SoulKeeper.java
public TextureRegion getFrame(float dt) { currentState = getState();/* w ww . j a v a2 s . c om*/ TextureRegion region; switch (currentState) { case UP: if (hitting) { region = marioHitUp; } else { region = marioRunUp.getKeyFrame(stateTimer, true /* loop */); } break; case LEFT: if (hitting) { region = marioHitLeft; } else { region = marioRunHorizontal.getKeyFrame(stateTimer, true /* loop */); } break; case RIGHT: if (hitting) { region = marioHitRight; } else { region = marioRunHorizontal.getKeyFrame(stateTimer, true /* loop */); } break; case DOWN: if (hitting) { region = marioHitDown; } else { region = marioRunDown.getKeyFrame(stateTimer, true /* loop */); } break; case STANDING: default: if (hitting) { region = marioHitDown; } else { region = marioStand; } break; } if ((b2body.getLinearVelocity().x < 0 || !runningRight) && !region.isFlipX() && !hitting) { 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.stercore.code.net.dermetfan.utils.libgdx.graphics.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(set ? flipX && !frame.isFlipX() : flipX, set ? flipY && !frame.isFlipY() : flipY); }/*from w ww.ja v a2 s . c o m*/ }
From source file:entityy.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 = (TextureRegion) animation.getKeyFrame(t); frame.flip(flipX && (set ? !frame.isFlipX() : true), flipY && (set ? !frame.isFlipY() : true)); }//from w w w.j a v a 2 s . c om }
From source file:genuini.entities.LivingBeings.java
private TextureRegion flipRegion(TextureRegion region, boolean atlasTowardsRight) { //boolean flipY = (body.getTransform().getRotation()!=0); boolean flipX = false; boolean flipY = false; if (atlasTowardsRight) { //flips the region if player walking left and the region is not towards left if ((body.getLinearVelocity().x < 0 || direction == Direction.LEFT) && !region.isFlipX()) { flipX = true;//from www .j a v a 2 s . c o m direction = Direction.LEFT; } //flips the region if player walking right and the region is not towards right else if ((body.getLinearVelocity().x > 0 || direction == Direction.RIGHT) && region.isFlipX()) { flipX = true; direction = Direction.RIGHT; } } else { //flips the region if player walking left and the region is not towards left if ((body.getLinearVelocity().x < 0 || direction == Direction.LEFT) && region.isFlipX()) { flipX = true; direction = Direction.LEFT; } //flips the region if player walking right and the region is not towards right else if ((body.getLinearVelocity().x > 0 || direction == Direction.RIGHT) && !region.isFlipX()) { flipX = true; direction = Direction.RIGHT; } } region.flip(flipX, flipY); return region; }