Search in sources :

Example 6 with Animation

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);
}
Also used : FixtureDefBuilder(ilargia.egdx.util.FixtureDefBuilder) AnimationSystem(com.ilargia.games.logicbrick.system.game.AnimationSystem) Bounds(com.ilargia.games.logicbrick.data.Bounds) Animation(com.badlogic.gdx.graphics.g2d.Animation) Map(java.util.Map) Body(com.badlogic.gdx.physics.box2d.Body) TextureRendererSystem(com.ilargia.games.logicbrick.system.render.TextureRendererSystem) InputsControllerSystem(com.ilargia.games.logicbrick.system.InputsControllerSystem)

Example 7 with Animation

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, Context<GameEntity> context) {
    BasePhysicsManager physics = engine.getManager(BasePhysicsManager.class);
    BodyBuilder bodyBuilder = physics.getBodyBuilder();
    TextureAtlas textureAtlas = assetsManager.getTextureAtlas(atlas);
    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 = Collections.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 = ((GameContext) context).getPlayerEntity().addRigidBody(bodyPlayer).addAnimations(animationStates, animationStates.get("idle"), 0).addCharacter("Mariano", StateCharacter.IDLE, false).addMovable(7, 8).addTextureView(null, new Bounds(0.9f, 1.15f), false, false, 1, 1, Color.WHITE);
    return entity;
}
Also used : GameEntity(com.indignado.games.states.game.gen.GameEntity) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Bounds(com.ilargia.games.logicbrick.data.Bounds) Animation(com.badlogic.gdx.graphics.g2d.Animation) BasePhysicsManager(com.ilargia.games.entitas.egdx.base.managers.BasePhysicsManager) BodyBuilder(ilargia.egdx.util.BodyBuilder) Body(com.badlogic.gdx.physics.box2d.Body)

Aggregations

Animation (com.badlogic.gdx.graphics.g2d.Animation)7 Body (com.badlogic.gdx.physics.box2d.Body)4 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)3 Texture (com.badlogic.gdx.graphics.Texture)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)2 Bounds (com.ilargia.games.logicbrick.data.Bounds)2 BodyBuilder (ilargia.egdx.util.BodyBuilder)2 FixtureDefBuilder (ilargia.egdx.util.FixtureDefBuilder)2 Map (java.util.Map)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)1 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)1 Vector2 (com.badlogic.gdx.math.Vector2)1