com.badlogic.gdx.graphics.g2d.Animation.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中com.badlogic.gdx.graphics.g2d.Animation.<init>()方法的一些代码示例,展示了Animation.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Animation.<init>()方法的具体详情如下:
包路径:com.badlogic.gdx.graphics.g2d.Animation
类名称:Animation
方法名:<init>

Animation.<init>介绍

[英]Constructor, storing the frame duration and key frames.
[中]构造函数,存储帧持续时间和关键帧。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  Gdx.input.setInputProcessor(this);
  texture = new Texture(Gdx.files.internal("data/animation.png"));
  TextureRegion[][] regions = TextureRegion.split(texture, 32, 48);
  TextureRegion[] downWalkReg = regions[0];
  TextureRegion[] leftWalkReg = regions[1];
  TextureRegion[] rightWalkReg = regions[2];
  TextureRegion[] upWalkReg = regions[3];
  downWalk = new Animation<TextureRegion>(ANIMATION_SPEED, downWalkReg);
  leftWalk = new Animation<TextureRegion>(ANIMATION_SPEED, leftWalkReg);
  rightWalk = new Animation<TextureRegion>(ANIMATION_SPEED, rightWalkReg);
  upWalk = new Animation<TextureRegion>(ANIMATION_SPEED, upWalkReg);
  currentWalk = leftWalk;
  currentFrameTime = 0.0f;
  spriteBatch = new SpriteBatch();
  position = new Vector2();
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  // load the koala frames, split them, and assign them to Animations
  koalaTexture = new Texture("data/maps/tiled/super-koalio/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("data/maps/tiled/super-koalio/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);
  camera.update();
  // create the Koala we want to move around the world
  koala = new Koala();
  koala.position.set(20, 20);
  debugRenderer = new ShapeRenderer();
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  texture = new Texture(Gdx.files.internal("data/walkanim.png"));
  TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0];
  Array<TextureRegion> rightWalkFrames = new Array(TextureRegion.class);
  for (int i = 0; i < leftWalkFrames.length; i++) {
    TextureRegion frame = new TextureRegion(leftWalkFrames[i]);
    frame.flip(true, false);
    rightWalkFrames.add(frame);
  }
  leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames);
  rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames);
  
  TextureRegion[] rightRegions = rightWalk.getKeyFrames(); // testing backing array type
  TextureRegion firstRightRegion = rightRegions[0];
  Gdx.app.log("AnimationTest", "First right walk region is " + firstRightRegion.getRegionWidth() + "x" + firstRightRegion.getRegionHeight());
  cavemen = new Caveman[100];
  for (int i = 0; i < 100; i++) {
    cavemen[i] = new Caveman((float)Math.random() * Gdx.graphics.getWidth(),
      (float)Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false);
  }
  batch = new SpriteBatch();
  fpsLog = new FPSLogger();
}

代码示例来源:origin: libgdx/libgdx

jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
jumpAnimation = new Animation<TextureRegion>(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));

代码示例来源:origin: libgdx/libgdx

animation = new Animation<TextureRegion>(0.33f, atlas.findRegions("badlogic-anim"), Animation.PlayMode.LOOP);

代码示例来源:origin: Mknsri/Drunk-Toss

public BumBomb(float startX, float startY) {
  x = startX;
  y = startY;
  pummiIdle = new Animation(0.5f, Art.pummiIdle);
  pummiTriggered = new Animation(1f, Art.pummiTriggered);
  this.setCollisionBoxSize(100, 50, 5);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx

public Animation add(final String identifier, int x1, int y1, int w, int h, int repeatX, int repeatY, Texture texture, float frameDuration) {
  TextureRegion[] regions = new TextureRegion[repeatX*repeatY];
  int count = 0;
  for (int y = 0; y < repeatY; y++) {
    for (int x = 0; x < repeatX; x++) {
      regions[count++] = new TextureRegion(texture, x1 + w * x, y1 + h * y, w, h);
    }
  }
  final Animation value = new Animation(frameDuration, regions);
  sprites.put(identifier, value);
  return value;
}

代码示例来源:origin: Mknsri/Drunk-Toss

public GroupThrower(float startX, float startY) {
  x = startX;
  y = startY;
  currentState = STATE.IDLE;
  
  animFighting = new Animation(0.25f, Art.groupFighting);
  this.setCollisionBoxSize(100, 100, 5);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam

public Animation add(final String identifier, int x1, int y1, int w, int h, int repeatX, int repeatY, Texture texture, float frameDuration) {
  TextureRegion[] regions = new TextureRegion[repeatX*repeatY];
  int count = 0;
  for (int y = 0; y < repeatY; y++) {
    for (int x = 0; x < repeatX; x++) {
      regions[count++] = new TextureRegion(texture, x1 + w * x, y1 + h * y, w, h);
    }
  }
  final Animation value = new Animation(frameDuration, regions);
  sprites.put(identifier, value);
  return value;
}

代码示例来源:origin: DaanVanYperen/artemis-odb-contrib

public Animation add(final String identifier, int x1, int y1, int w, int h, int repeatX, int repeatY, Texture texture, float frameDuration) {
  TextureRegion[] regions = new TextureRegion[repeatX*repeatY];
  int count = 0;
  for (int y = 0; y < repeatY; y++) {
    for (int x = 0; x < repeatX; x++) {
      regions[count++] = new TextureRegion(texture, x1 + w * x, y1 + h * y, w, h);
    }
  }
  final Animation value = new Animation(frameDuration, regions);
  sprites.put(identifier, value);
  return value;
}

代码示例来源:origin: Catacomb-Snatch/Catacomb-Snatch

public Animations(TextureRegion[][] r) {
  animations = new Animation[r.length];
  for (int i = 0; i < r.length; i++) {
    animations[i] = new Animation(0.2f, new Array<>(Art.lordLard[i]), Animation.PlayMode.LOOP);
  }
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam

private static Animation<TextureRegion> asGdxAnimation(AseFormat ase, TextureRegion[] frames, int from, int to) {
  Animation<TextureRegion> animation = new Animation<>(
      ase.shortestFrameDuration() * ASESPRITE_TO_GDX_DURATION,
      framesAsAnimationArray(ase, frames, from, to, ase.frames));
  animation.setPlayMode(Animation.PlayMode.LOOP);
  return animation;
}

代码示例来源:origin: Catacomb-Snatch/Catacomb-Snatch

public MenuScene(TextureRegion bg) {
  super();
  // Set background texture
  setBackground(bg);
  // Add animated character cursor (synchronized to the title melody, please do not change this speed!)
  ani = new Animation(0.33f / 2, new Array<>(Art.lordLard[Direction.EAST.getFace()]), Animation.PlayMode.LOOP);
}

代码示例来源:origin: Var3D/var3dframe

/**
 * @param walkFrames (TextrueRegion数组)
 *                   (播放模式Animation.NORMAL, Animation.REVERSED, Animation.LOOP,
 *                   Animation.LOOP_REVERSED, Animation.LOOP_PINGPONG,
 *                   Animation.LOOP_RANDOM )
 *                   (帧速)
 */
public ActorAnimation(TextureRegion[] walkFrames) {
  setSize(walkFrames[0].getRegionWidth(), walkFrames[0].getRegionHeight());
  animation = new Animation(frameTime, (Object[]) walkFrames);
  animation.setPlayMode(playMode);
}

代码示例来源:origin: jmrapp1/SpaceInvaders

protected Animation getAnimation(Drawable drawable, float time, int frames) {
  Array<TextureRegion> tr = new Array<TextureRegion>();
  TextureRegion textureRegion = drawable.getTextureRegion();
  int width = (int) drawable.getWidth() / frames; //Amount of frames is 3
  int height = (int) drawable.getHeight();
  for (int i = 0; i < frames; i++) {
    textureRegion.setRegion(width * i, 0, width, height);
    tr.add(textureRegion); 
    textureRegion = drawable.getTextureRegion();
  }
  return new Animation(time, tr);
}

代码示例来源:origin: udacity/ud406

public ExplosionAssets(TextureAtlas atlas) {
    Array<AtlasRegion> explosionRegions = new Array<AtlasRegion>();
    explosionRegions.add(atlas.findRegion(Constants.EXPLOSION_LARGE));
    explosionRegions.add(atlas.findRegion(Constants.EXPLOSION_MEDIUM));
    explosionRegions.add(atlas.findRegion(Constants.EXPLOSION_SMALL));
    explosion = new Animation(Constants.EXPLOSION_DURATION / explosionRegions.size,
        explosionRegions, PlayMode.NORMAL);
  }
}

代码示例来源:origin: BrentAureli/SuperMario

public Goomba(PlayScreen screen, float x, float y) {
  super(screen, x, y);
  frames = new Array<TextureRegion>();
  for(int i = 0; i < 2; i++)
    frames.add(new TextureRegion(screen.getAtlas().findRegion("goomba"), i * 16, 0, 16, 16));
  walkAnimation = new Animation(0.4f, frames);
  stateTime = 0;
  setBounds(getX(), getY(), 16 / MarioBros.PPM, 16 / MarioBros.PPM);
  setToDestroy = false;
  destroyed = false;
  angle = 0;
}

代码示例来源:origin: danialgoodwin/dev

public Enemy(Body body) {
  super(body);
  TextureAtlas textureAtlas = new TextureAtlas(Constants.CHARACTERS_ATLAS_PATH);
  TextureRegion[] runningFrames = new TextureRegion[getUserData().getTextureRegions().length];
  for (int i = 0; i < getUserData().getTextureRegions().length; i++) {
    String path = getUserData().getTextureRegions()[i];
    runningFrames[i] = textureAtlas.findRegion(path);
  }
  animation = new Animation(0.1f, runningFrames);
  stateTime = 0f;
}

代码示例来源:origin: BrentAureli/SuperMario

public FireBall(PlayScreen screen, float x, float y, boolean fireRight){
  this.fireRight = fireRight;
  this.screen = screen;
  this.world = screen.getWorld();
  frames = new Array<TextureRegion>();
  for(int i = 0; i < 4; i++){
    frames.add(new TextureRegion(screen.getAtlas().findRegion("fireball"), i * 8, 0, 8, 8));
  }
  fireAnimation = new Animation(0.2f, frames);
  setRegion(fireAnimation.getKeyFrame(0));
  setBounds(x, y, 6 / MarioBros.PPM, 6 / MarioBros.PPM);
  defineFireBall();
}

代码示例来源:origin: BrentAureli/SuperMario

public Turtle(PlayScreen screen, float x, float y) {
  super(screen, x, y);
  frames = new Array<TextureRegion>();
  frames.add(new TextureRegion(screen.getAtlas().findRegion("turtle"), 0, 0, 16, 24));
  frames.add(new TextureRegion(screen.getAtlas().findRegion("turtle"), 16, 0, 16, 24));
  shell = new TextureRegion(screen.getAtlas().findRegion("turtle"), 64, 0, 16, 24);
  walkAnimation = new Animation(0.2f, frames);
  currentState = previousState = State.WALKING;
  setBounds(getX(), getY(), 16 / MarioBros.PPM, 24 / MarioBros.PPM);
}

相关文章