Search in sources :

Example 21 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion 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();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) Animation(com.badlogic.gdx.graphics.g2d.Animation) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 22 with TextureRegion

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

the class MainShader method bindDirectionalShadows.

public void bindDirectionalShadows(final Attributes attributes) {
    final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type);
    final Array<DirectionalLight> dirs = dla == null ? null : dla.lights;
    if (dirLightsLoc >= 0) {
        for (int i = 0; i < directionalLights.length; i++) {
            if (dirs == null || dirs.size <= i) {
                continue;
            }
            int idx = dirShadowsLoc + i * dirShadowsSize;
            // Shadow
            ObjectMap<DirectionalLight, LightProperties> dirCameras = shadowSystem.getDirectionalCameras();
            DirectionalLight dl = dirs.get(i);
            if (shadowSystem.hasLight(dl)) {
                // UVTransform
                final TextureRegion tr = dirCameras.get(dl).region;
                Camera cam = dirCameras.get(dl).camera;
                if (cam != null) {
                    program.setUniformf(idx + dirShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV());
                    // ProjViewTrans
                    idx = dirShadowMapProjViewTransLoc + i * dirShadowMapProjViewTransSize;
                    program.setUniformMatrix(idx, dirCameras.get(dl).camera.combined);
                }
            }
            if (dirLightsSize <= 0)
                break;
        }
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) DirectionalLightsAttribute(com.badlogic.gdx.graphics.g3d.attributes.DirectionalLightsAttribute) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) LightProperties(com.badlogic.gdx.tests.g3d.shadows.system.BaseShadowSystem.LightProperties) Camera(com.badlogic.gdx.graphics.Camera)

Example 23 with TextureRegion

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

the class Decal method updateUVs.

/** Re-applies the uv coordinates from the material's texture region to the uv components of the vertices array */
protected void updateUVs() {
    TextureRegion tr = material.textureRegion;
    // left top
    vertices[U1] = tr.getU();
    vertices[V1] = tr.getV();
    // right top
    vertices[U2] = tr.getU2();
    vertices[V2] = tr.getV();
    // left bot
    vertices[U3] = tr.getU();
    vertices[V3] = tr.getV2();
    // right bot
    vertices[U4] = tr.getU2();
    vertices[V4] = tr.getV2();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion)

Example 24 with TextureRegion

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

the class APKExpansionTest method create.

@Override
public void create() {
    if ((((AndroidFiles) Gdx.files)).setAPKExpansion(1, 0)) {
        resolver = new ZipFileHandleResolver();
    } else {
        Gdx.app.error("libgdx", "No Expansion can be opened");
    }
    assetManager = new AssetManager();
    FileHandleResolver resolver = new InternalFileHandleResolver();
    assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
    assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
    loadFont(assetManager, "data/DroidSerif-Regular.ttf", 12);
    loadFont(assetManager, "data/" + extensionPrefix + "DroidSerif-Regular.ttf", 12);
    assetManager.load("data/" + extensionPrefix + "testpackobb", TextureAtlas.class);
    assetManager.finishLoading();
    sound = Gdx.audio.newSound(Gdx.files.internal("data/" + extensionPrefix + "chirp.ogg"));
    sound.play();
    texture = new Texture(resolver.resolve("data/" + extensionPrefix + "badlogic.jpg"));
    batch = new SpriteBatch();
    TextureAtlas atlas = assetManager.get("data/" + extensionPrefix + "testpackobb");
    atlasTextureRegion = new TextureRegion(atlas.findRegion("water"));
    sound = Gdx.audio.newSound(Gdx.files.internal("data/shotgun.ogg"));
    sound.play();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) FreeTypeFontGeneratorLoader(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader) FreetypeFontLoader(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 25 with TextureRegion

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

the class TiledDrawable method draw.

public void draw(Batch batch, float x, float y, float width, float height) {
    float batchColor = batch.getPackedColor();
    batch.setColor(batch.getColor().mul(color));
    TextureRegion region = getRegion();
    float regionWidth = region.getRegionWidth(), regionHeight = region.getRegionHeight();
    int fullX = (int) (width / regionWidth), fullY = (int) (height / regionHeight);
    float remainingX = width - regionWidth * fullX, remainingY = height - regionHeight * fullY;
    float startX = x, startY = y;
    float endX = x + width - remainingX, endY = y + height - remainingY;
    for (int i = 0; i < fullX; i++) {
        y = startY;
        for (int ii = 0; ii < fullY; ii++) {
            batch.draw(region, x, y, regionWidth, regionHeight);
            y += regionHeight;
        }
        x += regionWidth;
    }
    Texture texture = region.getTexture();
    float u = region.getU();
    float v2 = region.getV2();
    if (remainingX > 0) {
        // Right edge.
        float u2 = u + remainingX / texture.getWidth();
        float v = region.getV();
        y = startY;
        for (int ii = 0; ii < fullY; ii++) {
            batch.draw(texture, x, y, remainingX, regionHeight, u, v2, u2, v);
            y += regionHeight;
        }
        // Upper right corner.
        if (remainingY > 0) {
            v = v2 - remainingY / texture.getHeight();
            batch.draw(texture, x, y, remainingX, remainingY, u, v2, u2, v);
        }
    }
    if (remainingY > 0) {
        // Top edge.
        float u2 = region.getU2();
        float v = v2 - remainingY / texture.getHeight();
        x = startX;
        for (int i = 0; i < fullX; i++) {
            batch.draw(texture, x, y, regionWidth, remainingY, u, v2, u2, v);
            x += regionWidth;
        }
    }
    batch.setColor(batchColor);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)115 Texture (com.badlogic.gdx.graphics.Texture)57 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)22 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)18 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)13 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)13 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)11 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)11 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)10 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Color (com.badlogic.gdx.graphics.Color)7 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)7 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)7 Test (org.junit.Test)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6