Example usage for com.badlogic.gdx.graphics.g2d TextureRegion setRegion

List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion setRegion

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d TextureRegion setRegion.

Prototype

public void setRegion(float u, float v, float u2, float v2) 

Source Link

Usage

From source file:com.badlogic.gdx.tests.g3d.shadows.system.BaseShadowSystem.java

License:Apache License

/** Set viewport according to allocator.
 * @param lp LightProperties to process.
 * @param cameraViewport Set camera viewport if true. */
protected void processViewport(LightProperties lp, boolean cameraViewport) {
    Camera camera = lp.camera;/*  w  w  w .j  a  v a2s  . c  o  m*/
    ShadowMapRegion r = allocator.nextResult(currentLight);

    if (r == null)
        return;

    TextureRegion region = lp.region;
    region.setTexture(frameBuffers[currentPass].getColorBufferTexture());

    // We don't use HdpiUtils
    // gl commands related to shadow map size and not to screen size
    Gdx.gl.glViewport(r.x, r.y, r.width, r.height);
    Gdx.gl.glScissor(r.x + 1, r.y + 1, r.width - 2, r.height - 2);
    region.setRegion(r.x, r.y, r.width, r.height);

    if (cameraViewport) {
        camera.viewportHeight = r.height;
        camera.viewportWidth = r.width;
        camera.update();
    }
}

From source file:com.mygdx.game.MyOrthogonalTiledMapRenderer.java

License:Apache License

public static void fixBleeding(TextureRegion region) {
    float fix = 0.01f;

    float x = region.getRegionX();
    float y = region.getRegionY();
    float width = region.getRegionWidth();
    float height = region.getRegionHeight();
    float invTexWidth = 1f / region.getTexture().getWidth();
    float invTexHeight = 1f / region.getTexture().getHeight();
    region.setRegion((x + fix) * invTexWidth, (y + fix) * invTexHeight, (x + width - fix) * invTexWidth,
            (y + height - fix) * invTexHeight); // Trims
    // region/*  w  ww.j a  v  a  2  s  .  com*/
}

From source file:com.mygdx.java.utils.ImageUtils.java

License:Apache License

public static void setScreenTextureRegion(TextureRegion textureRegion, byte[] bytes) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }// w  w w .jav  a  2s  . co  m
    Texture tempTexture = textureRegion.getTexture();
    if (tempTexture != null) {
        tempTexture.dispose();
        tempTexture = null;
    }

    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    int width = pixmap.getWidth();
    int height = pixmap.getHeight();

    Texture texture = new Texture(width, height, pixmap.getFormat());
    texture.draw(pixmap, 0, 0);
    textureRegion.setTexture(texture);
    textureRegion.setRegion(0, 0, width, height);
    pixmap.dispose();

}

From source file:com.mygdx.java.utils.ImageUtils.java

License:Apache License

public static void setScreenTextureRegionInThread(final TextureRegion textureRegion, final byte[] bytes) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }// w  ww . j ava2  s.c o  m

    Gdx.app.postRunnable(new Runnable() {

        @Override
        public void run() {

            Texture tempTexture = textureRegion.getTexture();
            if (tempTexture != null) {
                tempTexture.dispose();
                textureRegion.setTexture(null);
            }

            Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
            int width = pixmap.getWidth();
            int height = pixmap.getHeight();
            // pixmap.setBlending(Blending.None);
            // Texture texture = new Texture(width, height,
            // pixmap.getFormat());
            Texture texture = new Texture(pixmap, true);
            texture.draw(pixmap, 0, 0);
            textureRegion.setTexture(texture);
            textureRegion.setRegion(0, 0, width, height);
            pixmap.dispose();

        }
    });

}

From source file:de.cubicvoxel.openspacebox.ingame.controller.UniverseBuilder.java

License:Open Source License

private Sector buildSector(SectorDefinition definition, List<SectorConnection> allSectorConnections) {
    // Find the template
    val template = definitionFinder.findSectorTemplate(definition.getTemplate()).get();

    // Create all ingameObjects
    ArrayList<AbstractIngameObject<?>> ingameObjects = new ArrayList<>();
    ingameObjects.addAll(stream(template.getShips()).map(this::buildShip).collect(Collectors.toList()));
    ingameObjects.addAll(stream(template.getStations()).map(this::buildStation).collect(Collectors.toList()));
    ingameObjects.addAll(stream(template.getAsteroidRegions()).map(this::buildAsteroidRegion)
            .flatMap(StreamSupport::stream).collect(Collectors.toList()));
    ingameObjects.addAll(//  www .j a  va2 s. co  m
            stream(template.getSectorBeacons()).map(this::buildSectorBeacon).collect(Collectors.toList()));

    // Create the background
    Texture backgroundTexture = OpenSpaceBox.getAsset(template.getBackground().getTextureAsset());
    backgroundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
    TextureRegion background = new TextureRegion(backgroundTexture);
    background.setRegion(0, 0, 25600, 25600);

    // Determine sectorConnections
    ArrayList<String> connectedSectorIds = determineConnectedSectorIds(definition, allSectorConnections);

    // Create the sector
    Sector sector = new Sector(highPriorityChunksProvider, drawableChunksProvider,
            new Sector.SectorProperties(definition, connectedSectorIds));
    sector.setBackground(background);
    sector.addObjects(ingameObjects);

    return sector;
}

From source file:es.eucm.ead.editor.control.transitions.parallel.ParallelTransition.java

License:Open Source License

public void render(Batch batch, TextureRegion currScreen, Region currScreenRegion, TextureRegion nextScreen,
        Region nextScreenRegion, float percentageCompletion) {
    for (TransitionInfo transition : transitions) {
        Region currRegion = transition.currentScreenRegion;
        if (currRegion != null) {
            currScreen.setRegion(currRegion.x, currRegion.y, currRegion.w, currRegion.h);
            currScreen.flip(false, true);
        } else {/* ww  w.jav  a2  s . co  m*/
            currRegion = currScreenRegion;
        }

        Region nextRegion = transition.nextScreenRegion;
        if (nextRegion != null) {
            nextScreen.setRegion(nextRegion.x, nextRegion.y, nextRegion.w, nextRegion.h);
            nextScreen.flip(false, true);
        } else {
            nextRegion = nextScreenRegion;
        }
        transition.transition.render(batch, currScreen, currRegion, nextScreen, nextRegion,
                percentageCompletion);
    }
}

From source file:group04.core.Renderer.java

public void makeAnimation(String animationName, Texture spriteSheet, int spriteSizeX, int spriteSizeY) {
    ArrayList<Sprite> keyFrames = new ArrayList<>();
    int numberOfSprites = (int) (spriteSheet.getWidth() / spriteSizeX);
    for (int i = 0; i < numberOfSprites; i++) {
        TextureRegion sprite = new TextureRegion(spriteSheet);
        sprite.setRegion(i * spriteSizeX, 0, spriteSizeX, spriteSizeY);
        keyFrames.add(new Sprite(sprite));
    }/*from w  w w . ja  v  a2  s  . c  o m*/
    animations.put(animationName, keyFrames);
}

From source file:me.scarlet.undertailor.gfx.SpriteSheet.java

License:Open Source License

public SpriteSheet(String sheetName, Texture texture, SpriteSheetMeta meta) throws TextureTilingException {
    this.texture = texture;
    this.sheetName = sheetName;
    checkTexture(texture, meta.gridX, meta.gridY);
    sprites = new Sprite[meta.gridX * meta.gridY];
    int spriteHeight = texture.getHeight() / meta.gridY;
    int spriteWidth = texture.getWidth() / meta.gridX;
    for (int iY = 0; iY < meta.gridY; iY++) {
        for (int iX = 0; iX < meta.gridX; iX++) {
            int pos = (iY * meta.gridX) + iX;
            SpriteMeta smeta = null;/*from ww  w  . j ava 2s.  c o  m*/
            if (meta.spriteMeta != null && pos < meta.spriteMeta.length && meta.spriteMeta[pos] != null) {
                smeta = meta.spriteMeta[pos];
            }

            TextureRegion region = new TextureRegion(texture);
            int height = spriteHeight;
            int width = spriteWidth;
            int wrapY = 0;
            if (smeta != null) {
                width -= smeta.wrapX;
                height -= smeta.wrapY;
                wrapY = smeta.wrapY;
            }

            region.setRegion(iX * spriteWidth, (iY * spriteHeight) + wrapY, width, height);
            sprites[pos] = new Sprite(region, smeta);
        }
    }
}

From source file:net.sleepystudios.bankvault.FixedTiledMapRenderer.java

License:Apache License

public void fixBleeding(TextureRegion region) {
    float fix = 0.01f;
    float x = region.getRegionX();
    float y = region.getRegionY();
    float width = region.getRegionWidth();
    float height = region.getRegionHeight();
    float invTexWidth = 1f / region.getTexture().getWidth();
    float invTexHeight = 1f / region.getTexture().getHeight();
    region.setRegion((x + fix) * invTexWidth, (y + fix) * invTexHeight, (x + width - fix) * invTexWidth,
            (y + height - fix) * invTexHeight); // Trims Region
}

From source file:test.ImageUtils.java

License:Apache License

public static void setScreenTextureRegion(final TextureRegion textureRegion) {

    if (textureRegion == null) {
        throw new IllegalArgumentException("Input the TextureRegion is null.");
    }/*from w  w  w . ja  v a2s  . c  o  m*/
    Texture tempTexture = textureRegion.getTexture();
    if (tempTexture != null) {
        tempTexture.dispose();
    }
    BufferedImage bufferedImage = ImageUtils.getScreenBufferedImage();
    byte[] bytes = ImageUtils.getBufferedImageBytes(bufferedImage);
    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    int width = pixmap.getWidth();
    int height = pixmap.getHeight();

    Texture texture = new Texture(width, height, pixmap.getFormat());
    texture.draw(pixmap, 0, 0);
    textureRegion.setTexture(texture);
    textureRegion.setRegion(0, 0, width, height);
    pixmap.dispose();

}