use of com.badlogic.gdx.graphics.g2d.Animation in project libgdx by libgdx.
the class TextureAtlasTest method create.
public void create() {
batch = new SpriteBatch();
renderer = new ShapeRenderer();
atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
badlogic = atlas.createSprite("badlogicslice");
badlogic.setPosition(50, 50);
// badlogicSmall = atlas.createSprite("badlogicsmall");
badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
badlogicSmall.setPosition(10, 10);
AtlasRegion region = atlas.findRegion("badlogicsmall");
System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
star = atlas.createSprite("particle-star");
star.setPosition(10, 70);
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
Gdx.gl.glClearColor(0, 1, 0, 1);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyUp(int keycode) {
if (keycode == Keys.UP) {
badlogicSmall.flip(false, true);
} else if (keycode == Keys.RIGHT) {
badlogicSmall.flip(true, false);
} else if (keycode == Keys.LEFT) {
badlogicSmall.setSize(512, 512);
} else if (keycode == Keys.DOWN) {
badlogicSmall.rotate90(true);
}
return super.keyUp(keycode);
}
});
}
use of com.badlogic.gdx.graphics.g2d.Animation in project libgdx by libgdx.
the class SuperKoalio method create.
@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();
}
use of com.badlogic.gdx.graphics.g2d.Animation in project Entitas-Java by Rubentxu.
the class GameSceneState method initialize.
@Override
public void initialize() {
atlas = assetsManager.getTextureAtlas(SPRITE_ATLAS);
Array<TextureAtlas.AtlasRegion> heroWalking = atlas.findRegions("Andando");
Array<TextureAtlas.AtlasRegion> heroJump = atlas.findRegions("Saltando");
Array<TextureAtlas.AtlasRegion> heroFall = atlas.findRegions("Cayendo");
Array<TextureAtlas.AtlasRegion> heroIdle = atlas.findRegions("Parado");
Animation walking = new Animation(RUNNING_FRAME_DURATION, heroWalking, Animation.PlayMode.LOOP);
Animation jump = new Animation(RUNNING_FRAME_DURATION * 7, heroJump, Animation.PlayMode.NORMAL);
Animation fall = new Animation(RUNNING_FRAME_DURATION * 5, heroFall, Animation.PlayMode.NORMAL);
Animation idle = new Animation(RUNNING_FRAME_DURATION * 4, heroIdle, Animation.PlayMode.LOOP);
Map animationHero = Collections.createMap(String.class, Animation.class);
animationHero.put("WALKING", walking);
animationHero.put("JUMPING", jump);
animationHero.put("FALL", fall);
animationHero.put("HURT", fall);
animationHero.put("IDLE", idle);
animationHero.put("HIT", fall);
Body body = bodyBuilder.fixture(new FixtureDefBuilder().boxShape(0.5f, 0.5f)).type(BodyDef.BodyType.KinematicBody).build();
systems.add(new InputsControllerSystem(entitas.input, guiFactory)).add(new AnimationSystem(entitas)).add(new TextureRendererSystem(entitas, engine.batch));
entitas.game.getPlayerEntity().addTextureView(null, new Bounds(0.8f, 1.2f), false, false, 1, 1, Color.WHITE).addAnimations(animationHero, walking, 0.02f).addRigidBody(body);
}
use of com.badlogic.gdx.graphics.g2d.Animation in project Entitas-Java by Rubentxu.
the class Mariano method create.
@Override
public GameEntity create(Engine engine, Entitas entitas) {
PhysicsManagerGDX physics = engine.getManager(PhysicsManagerGDX.class);
BodyBuilder bodyBuilder = physics.getBodyBuilder();
TextureAtlas textureAtlas = assetsManager.getTextureAtlas(atlas);
ParticleEffect dustEffect = assetsManager.get(effect, ParticleEffect.class);
Array<TextureAtlas.AtlasRegion> heroWalking = textureAtlas.findRegions("Andando");
Array<TextureAtlas.AtlasRegion> heroJump = textureAtlas.findRegions("Saltando");
Array<TextureAtlas.AtlasRegion> heroFall = textureAtlas.findRegions("Cayendo");
Array<TextureAtlas.AtlasRegion> heroIdle = textureAtlas.findRegions("Parado");
Map<String, Animation<TextureRegion>> animationStates = EntitasCollections.createMap(String.class, Animation.class);
animationStates.put("walking", new Animation(0.02f, heroWalking, Animation.PlayMode.LOOP));
animationStates.put("jump", new Animation(0.02f * 7, heroJump, Animation.PlayMode.NORMAL));
animationStates.put("fall", new Animation(0.02f * 5, heroFall, Animation.PlayMode.NORMAL));
animationStates.put("idle", new Animation(0.02f * 4, heroIdle, Animation.PlayMode.LOOP));
Body bodyPlayer = bodyBuilder.fixture(bodyBuilder.fixtureDefBuilder().boxShape(0.35f, 1).density(1)).type(BodyDef.BodyType.DynamicBody).fixedRotation().position(0, 5).mass(1).build();
GameEntity entity = entitas.game.createEntity();
entity.addRigidBody(bodyPlayer).addAnimations(animationStates, animationStates.get("idle"), 0).addTags("Mariano").setInteractive(true).addTextureView(null, new Bounds(0.9f, 1.15f), false, false, 1, 1, Color.WHITE).addInputController((inputManager, context) -> {
boolean isGround = false;
SensorEntity sensor = Indexed.getSensorsEntity(entity, "CollisionGround");
if (sensor.getCollisionSensor().collisionSignal)
isGround = true;
Vector2 impulse = new Vector2();
if (inputManager.isKeyDown(Input.Keys.D)) {
impulse.x = 2;
if (isGround)
entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
entity.getTextureView().flipX = false;
} else if (inputManager.isKeyDown(Input.Keys.A)) {
impulse.x = -2;
if (isGround)
entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("walking");
entity.getTextureView().flipX = true;
}
if (inputManager.isKeyDown(Input.Keys.W)) {
if (isGround)
impulse.y = 4;
entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("jump");
}
Vector2 vel = bodyPlayer.getLinearVelocity();
if (!inputManager.isKeyDown(Input.Keys.A) && !inputManager.isKeyDown(Input.Keys.D) && isGround) {
bodyPlayer.setLinearVelocity(new Vector2(0, vel.y));
entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("idle");
}
if (Math.abs(vel.x) > 7) {
vel.x = Math.signum(vel.x) * 7;
bodyPlayer.setLinearVelocity(new Vector2(vel.x, vel.y));
}
if (!isGround && vel.y < 0) {
entity.getAnimations().currentAnimation = entity.getAnimations().animationStates.get("fall");
}
bodyPlayer.applyLinearImpulse(impulse, bodyPlayer.getWorldCenter(), false);
});
entitas.sensor.createEntity().addCollisionSensor("Ground").addLink(entity.getCreationIndex(), "CollisionGround");
entitas.actuator.createEntity().addCameraActuator(((EngineGDX) engine).getCamera(), (short) 0.3f, 0.08f, 6, 1, "Mariano").addLink(entity.getCreationIndex(), "CameraActuator", true);
entitas.actuator.createEntity().addParticleEffectActuator(dustEffect, true, -1, -1).addLink(entity.getCreationIndex(), "EffectActuator", true);
return entity;
}
use of com.badlogic.gdx.graphics.g2d.Animation in project Alkahest-Coffee by AlkahestDev.
the class GifDecoder method getAnimation.
public Animation getAnimation(Animation.PlayMode playType) {
int nrFrames = getFrameCount();
Pixmap frame = getFrame(0);
int width = frame.getWidth();
int height = frame.getHeight();
int vzones = (int) Math.sqrt((double) nrFrames);
int hzones = vzones;
while (vzones * hzones < nrFrames) vzones++;
int v, h;
Pixmap target = new Pixmap(width * hzones, height * vzones, Pixmap.Format.RGBA8888);
for (h = 0; h < hzones; h++) {
for (v = 0; v < vzones; v++) {
int frameID = v + h * vzones;
if (frameID < nrFrames) {
frame = getFrame(frameID);
target.drawPixmap(frame, h * width, v * height);
}
}
}
Texture texture = new Texture(target);
Array<TextureRegion> texReg = new Array<TextureRegion>();
for (h = 0; h < hzones; h++) {
for (v = 0; v < vzones; v++) {
int frameID = v + h * vzones;
if (frameID < nrFrames) {
TextureRegion tr = new TextureRegion(texture, h * width, v * height, width, height);
texReg.add(tr);
}
}
}
float frameDuration = (float) getDelay(0);
// convert milliseconds into seconds
frameDuration /= 1000;
return new Animation<TextureRegion>(frameDuration, texReg, playType);
}
Aggregations