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

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

Introduction

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

Prototype

public int getRegionX() 

Source Link

Usage

From source file:com.agateau.pixelwheels.Assets.java

License:Open Source License

private static void removeBorders(TextureRegion region) {
    region.setRegionX(region.getRegionX() + 2);
    region.setRegionY(region.getRegionY() + 2);
    region.setRegionWidth(region.getRegionWidth() - 4);
    region.setRegionHeight(region.getRegionHeight() - 4);
}

From source file:com.badlydrawngames.veryangryrobots.WorldView.java

License:Apache License

private void drawClipped(GameObject go, TextureRegion region) {
    float boundsMinX = worldMinX + World.OUTER_WALL_ADJUST + World.WALL_HEIGHT;
    float boundsMaxX = worldMaxX - World.OUTER_WALL_ADJUST - World.WALL_HEIGHT;
    float boundsMinY = worldMinY + World.OUTER_WALL_ADJUST + World.WALL_HEIGHT;
    float boundsMaxY = worldMaxY - World.OUTER_WALL_ADJUST - World.WALL_HEIGHT;

    // Don't draw if it's completely out of bounds.
    float maxX = go.x + go.width;
    if (maxX < boundsMinX)
        return;/*  w ww  .j  av a 2 s  . c o  m*/
    float minX = go.x;
    if (minX > boundsMaxX)
        return;
    float maxY = go.y + go.height;
    if (maxY < boundsMinY)
        return;
    float minY = go.y;
    if (minY > boundsMaxY)
        return;

    // Clip to the visible bounds.
    float x = go.x;
    float y = go.y;
    int srcX = region.getRegionX();
    int srcY = region.getRegionY();
    int srcWidth = region.getRegionWidth();
    int srcHeight = region.getRegionHeight();
    if (minX < boundsMinX) {
        float n = (boundsMinX - minX);
        x += n;
        n *= (srcWidth / go.width);
        srcX += n;
        srcWidth -= n;
    } else if (maxX > boundsMaxX) {
        float n = (maxX - boundsMaxX);
        srcWidth -= n * (srcWidth / go.width);
    }
    if (minY < boundsMinY) {
        float n = (boundsMinY - minY);
        y += n;
        srcHeight -= n * (srcHeight / go.height);
    } else if (maxY > boundsMaxY) {
        float n = (maxY - boundsMaxY) * (srcHeight / go.height);
        srcHeight -= n;
        srcY += n;
    }
    float width = go.width * srcWidth / region.getRegionWidth();
    float height = go.height * srcHeight / region.getRegionHeight();

    spriteBatch.draw(region.getTexture(), x, y, width, height, srcX, srcY, srcWidth, srcHeight, false, false);
}

From source file:com.blindtigergames.werescrewed.graphics.TextureAtlas.java

License:Apache License

/**
 * Adds a region to the atlas. The texture for the specified region will be
 * disposed when the atlas is disposed./*from w ww  .  j a va 2s. co m*/
 */
public AtlasRegion addRegion(String name, TextureRegion textureRegion) {
    return addRegion(name, textureRegion.getTexture(), textureRegion.getRegionX(), textureRegion.getRegionY(),
            textureRegion.getRegionWidth(), textureRegion.getRegionHeight());
}

From source file:com.ethereal.rm.game.objects.Brick.java

@Override
public void render(SpriteBatch batch) {
    TextureRegion reg = null;

    reg = redBrick;//from www  .  j  a v a  2s  . c  om
    //batch.draw(reg.getTexture(), position.x + relX, position.y +
    //relY, origin.x, origin.y, dimension.x, dimension.y,
    //scale.x, scale.y, rotation+90, reg.getRegionX(), reg.getRegionY(),
    //reg.getRegionWidth(), reg.getRegionHeight(), false, false);
    batch.draw(reg.getTexture(), // Texture
            position.x + relX, position.y + relY, // x, y
            origin.x, origin.y, // originX, originY
            dimension.x, dimension.y, // width, height
            //Constants.WORLD_TO_SCREEN,Constants.WORLD_TO_SCREEN,                            // scaleX, scaleY
            scale.x, scale.y, 90.0f, // rot (degrees)
            reg.getRegionX(), reg.getRegionY(), // srcX, srcY
            reg.getRegionWidth(), reg.getRegionHeight(), // srcWidth, srcHeight
            false, false); // flipX, flipY
}

From source file:com.kotcrab.vis.editor.ui.dialog.PolygonAutoTraceDialog.java

License:Apache License

private void tracePolygon() {
    TextureRegion region = textureCacheModule.getRegion(assetDescriptor);
    int width = region.getRegionWidth();
    int height = region.getRegionHeight();
    int[] pixelArray = new int[width * height];

    Texture texture = region.getTexture();
    if (texture.getTextureData().isPrepared() == false) {
        texture.getTextureData().prepare();
    }/*  w ww . j ava2s  . c  o m*/

    Pixmap pixmap = texture.getTextureData().consumePixmap();

    for (int x = 0; x < region.getRegionWidth(); x++) {
        for (int y = 0; y < region.getRegionHeight(); y++) {
            pixelArray[x + y * width] = pixmap.getPixel(region.getRegionX() + x, region.getRegionY() + y);
        }
    }

    Vector2[][] vertices = Tracer.trace(pixelArray, width, height, hullTolerance.getValue(),
            (int) alphaTolerance.getValue());

    if (vertices == null || vertices.length == 0) {
        Dialogs.showErrorDialog(stage, "Auto tracer could not create polygon, please create points manually.");
        Log.warn(PolygonTool.TAG, "Failed to auto trace polygon for asset descriptor: " + assetDescriptor);
        fadeOut();
        return;
    }

    if (vertices.length > 1) {
        Log.warn(PolygonTool.TAG,
                "Auto tracer found multiple parts, will be discarded. Asset descriptor: " + assetDescriptor);
    }

    resultListener.finished(vertices[0]);
}

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//from ww w  .j a va 2 s.c o m
}

From source file:com.packtpub.libgdx.canyonbunny.game.objects.BunnyHead.java

License:Apache License

@Override
public void render(SpriteBatch batch) {
    TextureRegion reg = null;

    // Draw Particles
    dustParticles.draw(batch);/*from www. j av a  2  s  .c  o m*/

    // Apply Skin Color
    batch.setColor(CharacterSkin.values()[GamePreferences.instance.charSkin].getColor());

    // Set special color when game object has a feather power-up
    if (hasFeatherPowerup) {
        batch.setColor(1.0f, 0.8f, 0.0f, 1.0f);
    }

    // Draw image
    reg = regHead;
    batch.draw(reg.getTexture(), position.x, position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x,
            scale.y, rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(),
            viewDirection == VIEW_DIRECTION.LEFT, false);

    // Reset color to white
    batch.setColor(1, 1, 1, 1);
}

From source file:com.packtpub.libgdx.canyonbunny.game.objects.Feather.java

License:Apache License

public void render(SpriteBatch batch) {
    if (collected)
        return;/*from  w ww  .  j ava 2  s  .c o  m*/

    TextureRegion reg = null;

    reg = regFeather;
    batch.draw(reg.getTexture(), position.x, position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x,
            scale.y, rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(),
            false, false);
}

From source file:com.packtpub.libgdx.canyonbunny.game.objects.GoldCoin.java

License:Apache License

public void render(SpriteBatch batch) {
    if (collected)
        return;//from w  w w .  ja v a2  s  .co m

    TextureRegion reg = null;

    reg = regGoldCoin;
    batch.draw(reg.getTexture(), position.x, position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x,
            scale.y, rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(),
            false, false);
}

From source file:com.packtpub.libgdx.canyonbunny.game.objects.Mountains.java

License:Apache License

private void drawMountain(SpriteBatch batch, float offsetX, float offsetY, float tintColor,
        float parallaxSpeedX) {
    TextureRegion reg = null;
    batch.setColor(tintColor, tintColor, tintColor, 1);
    float xRel = dimension.x * offsetX;
    float yRel = dimension.y * offsetY;

    // mountains span the whole level
    int mountainLength = 0;
    mountainLength += MathUtils.ceil(length / (2 * dimension.x) * (1 - parallaxSpeedX));
    mountainLength += MathUtils.ceil(0.5f + offsetX);
    for (int i = 0; i < mountainLength; i++) {
        // mountain left
        reg = regMountainLeft;//from w w  w . j ava  2  s . c  o m
        batch.draw(reg.getTexture(), origin.x + xRel + position.x * parallaxSpeedX,
                origin.y + yRel + position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x, scale.y,
                rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(),
                false, false);
        xRel += dimension.x;
        // mountain right
        reg = regMountainRight;
        batch.draw(reg.getTexture(), origin.x + xRel + position.x * parallaxSpeedX,
                origin.y + yRel + position.y, origin.x, origin.y, dimension.x, dimension.y, scale.x, scale.y,
                rotation, reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight(),
                false, false);
        xRel += dimension.x;
    }
    // reset color to white
    batch.setColor(1, 1, 1, 1);
}