Search in sources :

Example 91 with Texture

use of com.badlogic.gdx.graphics.Texture in project Eidolons by IDemiurge.

the class TextureCache method _createTexture.

public Texture _createTexture(String path, boolean putIntoCache) {
    Path p = Paths.get(imagePath, path);
    String filePath = p.toString();
    Texture t = null;
    if (checkAltTexture(filePath))
        try {
            t = new Texture(new FileHandle(getAltTexturePath(filePath)), Pixmap.Format.RGBA8888, false);
            if (putIntoCache)
                cache.put(path, t);
        } catch (Exception e) {
        }
    if (t == null)
        try {
            t = new Texture(new FileHandle(filePath), Pixmap.Format.RGBA8888, false);
            if (putIntoCache) {
                cache.put(path, t);
            }
        } catch (Exception e) {
            // main.system.ExceptionMaster.printStackTrace(e);
            if (!cache.containsKey(getEmptyPath())) {
                if (putIntoCache)
                    cache.put(getEmptyPath(), getEmptyTexture());
                return getEmptyTexture();
            }
            return cache.get(getEmptyPath());
        }
    return t;
}
Also used : Path(java.nio.file.Path) FileHandle(com.badlogic.gdx.files.FileHandle) Texture(com.badlogic.gdx.graphics.Texture)

Example 92 with Texture

use of com.badlogic.gdx.graphics.Texture in project Eidolons by IDemiurge.

the class TextureManager method getXY.

public static Pair<Integer, Integer> getXY(String origPath) {
    int x = 1;
    int y = 1;
    List<Integer> xs = new ArrayList<>();
    List<Integer> ys = new ArrayList<>();
    Texture texture = TextureCache.getOrCreate(origPath);
    for (int i = 7; i >= 1; i--) {
        if (texture.getWidth() % i == 0) {
            x = i;
            xs.add(i);
        }
        if (texture.getHeight() % i == 0) {
            y = i;
            ys.add(i);
        }
    }
    // prefer square
    {
        for (int x1 : xs) {
            if (x1 == 0) {
                continue;
            }
            final int w = texture.getWidth() / x1;
            for (int y1 : ys) {
                if (y1 == 0) {
                    continue;
                }
                int h = texture.getHeight() / y1;
                if (w == h) {
                    return new ImmutablePair<>(x1, y1);
                }
            }
        }
    }
    if (x == 0) {
        x = 1;
    }
    if (y == 0) {
        y = 1;
    }
    return new ImmutablePair<>(x, y);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ArrayList(java.util.ArrayList) Texture(com.badlogic.gdx.graphics.Texture)

Example 93 with Texture

use of com.badlogic.gdx.graphics.Texture in project Eidolons by IDemiurge.

the class TextureTransformer method mirror.

// must be a power of two size
public void mirror() {
    Texture imgTexture = new Texture(Gdx.files.internal("badlogic.jpg"));
    imgTexture.setWrap(Texture.TextureWrap.MirroredRepeat, Texture.TextureWrap.MirroredRepeat);
    TextureRegion imgTextureRegion = new TextureRegion(imgTexture);
    imgTextureRegion.setRegion(0, 0, imgTexture.getWidth() * 3, imgTexture.getHeight() * 3);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture)

Example 94 with Texture

use of com.badlogic.gdx.graphics.Texture in project Eidolons by IDemiurge.

the class Anim method draw.

@Override
public boolean draw(Batch batch) {
    // if (getX() == 0 && getY() == 0) {
    // getX();
    // }
    // switch(template){
    // }
    float delta = Gdx.graphics.getDeltaTime();
    time += delta;
    if (time < 0) {
        // delay
        return true;
    }
    checkAddFloatingText();
    Texture currentFrame = textureSupplier.get();
    if (lifecycleDuration != 0) {
        cycles = (int) (time / lifecycleDuration);
        lifecycle = time % lifecycleDuration / lifecycleDuration;
    }
    if (// || finished //  lifecycle duration for continuous?
    duration >= 0 || isContinuous()) {
        if (checkFinished()) {
            if (AnimMaster.isSmoothStop(this)) {
                if (!isEmittersWaitingDone()) {
                    emittersWaitingDone = true;
                    duration += getTimeToFinish();
                    emitterList.forEach(e -> e.getEffect().allowCompletion());
                    return true;
                }
            }
            LogMaster.log(LogMaster.ANIM_DEBUG, this + " finished; duration = " + duration);
            finished();
            dispose();
            return false;
        }
    }
    if (currentFrame != null) {
        setWidth(currentFrame.getWidth());
        setHeight(currentFrame.getHeight());
    }
    updatePosition(delta);
    emitterList.forEach(e -> {
        e.setFlipX(flipX);
        e.setFlipX(flipY);
        e.act(delta);
    });
    sprites.forEach(s -> {
    // s.setFlipX(flipX);
    // s.setFlipX(flipY);
    });
    applyAnimMods();
    if (isDrawTexture() && getActions().size == 0) {
        draw(batch, alpha);
    }
    sprites.forEach(s -> {
        s.draw(batch);
    });
    emitterList.forEach(e -> {
        e.draw(batch, 1f);
        main.system.auxiliary.log.LogMaster.log(1, e.getName() + " drawn at x " + e.getX() + " y " + e.getY());
        e.getEffect().getEmitters().forEach(em -> {
            main.system.auxiliary.log.LogMaster.log(1, em.getName() + " emitter at at x " + em.getX() + " y " + em.getY());
        });
    });
    return true;
}
Also used : Texture(com.badlogic.gdx.graphics.Texture)

Example 95 with Texture

use of com.badlogic.gdx.graphics.Texture in project Mindustry by Anuken.

the class MapEditor method resize.

public void resize(int width, int height) {
    Pixmap out = Pixmaps.resize(pixmap, width, height, ColorMapper.getColor(Blocks.stone));
    pixmap.dispose();
    pixmap = out;
    texture.dispose();
    texture = new Texture(out);
    if (filterPixmap != null) {
        filterPixmap.dispose();
        filterTexture.dispose();
        filterPixmap = null;
        filterTexture = null;
    }
    pixmap.setColor(ColorMapper.getColor(drawBlock));
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)235 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)78 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 Stage (com.badlogic.gdx.scenes.scene2d.Stage)35 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)26 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)21 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Material (com.badlogic.gdx.graphics.g3d.Material)12 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)12 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)11 FileHandle (com.badlogic.gdx.files.FileHandle)10