Search in sources :

Example 11 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class IntegerBitmapFontTest method create.

public void create() {
    TextureAtlas textureAtlas = new TextureAtlas("data/pack");
    font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false);
    singleLineCache = new BitmapFontCache(font, true);
    multiLineCache = new BitmapFontCache(font, true);
    singleLineCacheNonInteger = new BitmapFontCache(font, false);
    multiLineCacheNonInteger = new BitmapFontCache(font, false);
    batch = new SpriteBatch();
    fillCaches();
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 12 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project commons-gdx by gemserk.

the class AnimationFromTextureAtlasResourceBuilder method build.

@Override
public Animation build() {
    TextureAtlas textureAtlas = resourceManager.getResourceValue(textureAtlasId);
    if (sprites == null) {
        try {
            sprites = textureAtlas.createSprites(prefix);
        } catch (GdxRuntimeException e) {
            throw new RuntimeException("Failed to create animation from texture atlas " + textureAtlasId, e);
        }
    }
    if (endFrame == -1)
        endFrame = sprites.size - 1;
    if (startFrame == -1)
        startFrame = 0;
    Sprite[] frames = new Sprite[endFrame - startFrame + 1];
    int frameNumber = startFrame;
    for (int i = 0; i < frames.length; i++) {
        Sprite sprite = sprites.get(frameNumber);
        if (sprite instanceof AtlasSprite)
            frames[i] = new AtlasSprite(((AtlasSprite) sprite).getAtlasRegion());
        else
            frames[i] = new Sprite(sprite);
        frameTransformation.transform(frames[i]);
        frameNumber++;
    }
    int framesCount = frames.length;
    float[] newTimes = new float[framesCount - 1];
    int lastTime = time;
    for (int i = 0; i < framesCount - 1; i++) {
        if (i < times.length) {
            newTimes[i] = ((float) times[i]) * 0.001f;
            lastTime = times[i];
        } else
            newTimes[i] = ((float) lastTime) * 0.001f;
    }
    FrameAnimationImpl frameAnimation = new FrameAnimationImpl(0.001f * (float) time, newTimes);
    frameAnimation.setLoop(loop);
    return new Animation(frames, frameAnimation);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FrameAnimationImpl(com.gemserk.animation4j.FrameAnimationImpl) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Animation(com.gemserk.animation4j.gdx.Animation)

Example 13 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project commons-gdx by gemserk.

the class FontResourceBuilder method build.

@Override
public BitmapFont build() {
    BitmapFont bitmapFont;
    if (imageFile != null && fontFile != null) {
        Texture texture = new Texture(imageFile);
        texture.setFilter(minFilter, magFilter);
        bitmapFont = new BitmapFont(fontFile, new Sprite(texture), false);
    } else if (textureAtlasId != null && regionId != null) {
        if (fontFile == null)
            throw new IllegalArgumentException("Can't build a font resource without specifying the fontFile.");
        TextureAtlas atlas = resourceManager.getResourceValue(textureAtlasId);
        AtlasRegion region = atlas.findRegion(regionId);
        if (region == null)
            throw new IllegalArgumentException("Can't build a font resource, region " + regionId + " not found in texture atlas");
        bitmapFont = new BitmapFont(fontFile, region, false);
    } else {
        // if image file and font file are not specified, it creates a new default bitmap font.
        bitmapFont = new BitmapFont();
        bitmapFont.getRegion().getTexture().setFilter(minFilter, magFilter);
    }
    bitmapFont.setUseIntegerPositions(useIntegerPositions);
    if (fixedWidthGlyphs != null)
        bitmapFont.setFixedWidthGlyphs(fixedWidthGlyphs);
    for (int i = 0; i < spacings.size(); i++) {
        FontSpacing fontSpacing = spacings.get(i);
        CharSequence charSequence = fontSpacing.charSequence;
        BitmapFontUtils.spacing(bitmapFont, charSequence, fontSpacing.spacing);
    }
    bitmapFont.setScale(scale);
    return bitmapFont;
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Texture(com.badlogic.gdx.graphics.Texture)

Example 14 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas 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;
}
Also used : Bounds(ilargia.egdx.logicbricks.data.Bounds) EngineGDX(ilargia.egdx.impl.EngineGDX) BodyBuilder(ilargia.egdx.util.BodyBuilder) PhysicsManagerGDX(ilargia.egdx.impl.managers.PhysicsManagerGDX) ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) GameEntity(ilargia.egdx.logicbricks.gen.game.GameEntity) Vector2(com.badlogic.gdx.math.Vector2) SensorEntity(ilargia.egdx.logicbricks.gen.sensor.SensorEntity) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Animation(com.badlogic.gdx.graphics.g2d.Animation) Body(com.badlogic.gdx.physics.box2d.Body)

Example 15 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project Catacomb-Snatch by Catacomb-Snatch.

the class Art method loadResources.

/**
     * Loads all the artwork
     *
     * @return True on success, otherwise false
     */
public static boolean loadResources() {
    try {
        // Load interface
        skin = new Skin(Gdx.files.internal("art/interface.skin"), new TextureAtlas("art/interface.atlas"));
        // Load backgrounds
        pyramid = new TextureRegion(load("screen/pyramid.png"));
        // Load characters
        lordLard = cut("player/lord_lard.png", 32, 32);
        // Load tiles
        tiles_floor = cut("tiles/floor.png", 32, 32)[0];
        tiles_sand = cut("tiles/sand.png", 32, 32)[0];
        tiles_walls = cut("tiles/walls.png", 32, 56)[0];
        tiles_shadows = cut("tiles/shadows.png", 32, 32)[0];
        tiles_hole = cut("tiles/hole.png", 32, 32)[0];
        // Load extras
        logo = new TextureRegion(load("logo.png"));
        return true;
    } catch (Exception e) {
        Gdx.app.error(TAG, "Something went wrong while loading a resource: ", e);
    }
    return false;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Aggregations

TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)33 Texture (com.badlogic.gdx.graphics.Texture)11 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)11 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)10 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)7 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 FileHandle (com.badlogic.gdx.files.FileHandle)5 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)4 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 Array (com.badlogic.gdx.utils.Array)4 Animation (com.badlogic.gdx.graphics.g2d.Animation)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)3 TexturePacker (com.badlogic.gdx.tools.texturepacker.TexturePacker)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)2 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2