Example usage for com.badlogic.gdx.graphics Texture getWidth

List of usage examples for com.badlogic.gdx.graphics Texture getWidth

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Texture getWidth.

Prototype

@Override
    public int getWidth() 

Source Link

Usage

From source file:awakening.view.menu.MapSelection.java

License:Apache License

/**
 * Constructor//from  w ww . jav a 2  s . c om
 * 
 * @param game Tower Awakening's Game
 * @param sound Main menu's music
 * @param effect Button's effect
 */
public MapSelection(final TAGame game, Music sound, final Sound effect) {
    this.game = game;
    this.sound = sound;
    this.effect = effect;
    stage = new Stage();

    try {
        File monsterDirectory = Gdx.files.internal("Field").file();
        for (File ft : monsterDirectory.listFiles()) {
            if (ft.isFile())
                if (ft.getName().endsWith("mta")) {
                    Field newMap = Field.loadTower(ft);
                    if (newMap != null)
                        mapListes.add(newMap);
                }
        }

        if (game.getLanguage().equals("ENGLISH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_en_EN", locales[0]);
        } else if (game.getLanguage().equals("FRENCH")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_fr_FR", locales[1]);
        } else if (game.getLanguage().equals("ITALIAN")) {
            language = ResourceBundle.getBundle("awakening.view.menu.res_it_IT", locales[2]);
        } else {
            language = ResourceBundle.getBundle("awakening.view.menu.res", locales[0]);
        }
    } catch (java.util.MissingResourceException e) {
        System.out.println("yolo");
    }

    ///Viewport
    camera = new OrthographicCamera();
    view = new StretchViewport(Gdx.app.getGraphics().getWidth(), Gdx.app.getGraphics().getWidth(), camera);

    ///Background
    background = new Texture(Gdx.files.internal("img/menu/Background-2.png"));
    batch = new SpriteBatch();

    ///Skin
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    ///Title
    title = new Label(language.getString("label_map_selection"), skin);

    ///Widgets Background
    widgetsBackground = new Image(new Texture(Gdx.files.internal("img/widget/window_selection.png")));
    widgetsBackground.setSize(Gdx.app.getGraphics().getWidth() - Gdx.app.getGraphics().getWidth() / 8,
            Gdx.app.getGraphics().getHeight() - Gdx.app.getGraphics().getHeight() / 8);

    ///Back Button
    btnBack = new TextButton(language.getString("button_back"), skin);
    btnJeu = new TextButton(language.getString("button_game"), skin);

    ///Next Button
    Texture t1 = new Texture(Gdx.files.internal("img/widget/arrow_hover_right.png"));
    Texture t2 = new Texture(Gdx.files.internal("img/widget/arrow_right.png"));
    ImageButtonStyle style1 = new ImageButtonStyle(
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t1, 0, 0, t1.getWidth(), t1.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t2, 0, 0, t2.getWidth(), t2.getHeight())));
    btnNext = new ImageButton(style1);

    ///Previous Button
    Texture t3 = new Texture(Gdx.files.internal("img/widget/arrow_hover_left.png"));
    Texture t4 = new Texture(Gdx.files.internal("img/widget/arrow_left.png"));
    ImageButtonStyle style2 = new ImageButtonStyle(
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t3, 0, 0, t3.getWidth(), t3.getHeight())),
            new TextureRegionDrawable(new TextureRegion(t4, 0, 0, t4.getWidth(), t4.getHeight())));

    btnPrevious = new ImageButton(style2);

    maps = new ArrayList<BoutonShop>();

}

From source file:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java

License:Apache License

@Override
public void renderTileLayer(TiledMapTileLayer layer) {
    final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());

    final int layerWidth = layer.getWidth();
    final int layerHeight = layer.getHeight();

    final float layerTileWidth = layer.getTileWidth() * unitScale;
    final float layerTileHeight = layer.getTileHeight() * unitScale;

    final int col1 = Math.max(0, (int) (cacheBounds.x / layerTileWidth));
    final int col2 = Math.min(layerWidth,
            (int) ((cacheBounds.x + cacheBounds.width + layerTileWidth) / layerTileWidth));

    final int row1 = Math.max(0, (int) (cacheBounds.y / layerTileHeight));
    final int row2 = Math.min(layerHeight,
            (int) ((cacheBounds.y + cacheBounds.height + layerTileHeight) / layerTileHeight));

    canCacheMoreN = row2 < layerHeight;
    canCacheMoreE = col2 < layerWidth;
    canCacheMoreW = col1 > 0;/*from w ww .j a  v  a2s.  co m*/
    canCacheMoreS = row1 > 0;

    float[] vertices = this.vertices;
    for (int row = row2; row >= row1; row--) {
        for (int col = col1; col < col2; col++) {
            final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
            if (cell == null)
                continue;

            final TiledMapTile tile = cell.getTile();
            if (tile == null)
                continue;

            count++;
            final boolean flipX = cell.getFlipHorizontally();
            final boolean flipY = cell.getFlipVertically();
            final int rotations = cell.getRotation();

            final TextureRegion region = tile.getTextureRegion();
            final Texture texture = region.getTexture();

            final float x1 = col * layerTileWidth + tile.getOffsetX() * unitScale;
            final float y1 = row * layerTileHeight + tile.getOffsetY() * unitScale;
            final float x2 = x1 + region.getRegionWidth() * unitScale;
            final float y2 = y1 + region.getRegionHeight() * unitScale;

            final float adjustX = 0.5f / texture.getWidth();
            final float adjustY = 0.5f / texture.getHeight();
            final float u1 = region.getU() + adjustX;
            final float v1 = region.getV2() - adjustY;
            final float u2 = region.getU2() - adjustX;
            final float v2 = region.getV() + adjustY;

            vertices[X1] = x1;
            vertices[Y1] = y1;
            vertices[C1] = color;
            vertices[U1] = u1;
            vertices[V1] = v1;

            vertices[X2] = x1;
            vertices[Y2] = y2;
            vertices[C2] = color;
            vertices[U2] = u1;
            vertices[V2] = v2;

            vertices[X3] = x2;
            vertices[Y3] = y2;
            vertices[C3] = color;
            vertices[U3] = u2;
            vertices[V3] = v2;

            vertices[X4] = x2;
            vertices[Y4] = y1;
            vertices[C4] = color;
            vertices[U4] = u2;
            vertices[V4] = v1;

            if (flipX) {
                float temp = vertices[U1];
                vertices[U1] = vertices[U3];
                vertices[U3] = temp;
                temp = vertices[U2];
                vertices[U2] = vertices[U4];
                vertices[U4] = temp;
            }
            if (flipY) {
                float temp = vertices[V1];
                vertices[V1] = vertices[V3];
                vertices[V3] = temp;
                temp = vertices[V2];
                vertices[V2] = vertices[V4];
                vertices[V4] = temp;
            }
            if (rotations != 0) {
                switch (rotations) {
                case Cell.ROTATE_90: {
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V2];
                    vertices[V2] = vertices[V3];
                    vertices[V3] = vertices[V4];
                    vertices[V4] = tempV;

                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U2];
                    vertices[U2] = vertices[U3];
                    vertices[U3] = vertices[U4];
                    vertices[U4] = tempU;
                    break;
                }
                case Cell.ROTATE_180: {
                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U3];
                    vertices[U3] = tempU;
                    tempU = vertices[U2];
                    vertices[U2] = vertices[U4];
                    vertices[U4] = tempU;
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V3];
                    vertices[V3] = tempV;
                    tempV = vertices[V2];
                    vertices[V2] = vertices[V4];
                    vertices[V4] = tempV;
                    break;
                }
                case Cell.ROTATE_270: {
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V4];
                    vertices[V4] = vertices[V3];
                    vertices[V3] = vertices[V2];
                    vertices[V2] = tempV;

                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U4];
                    vertices[U4] = vertices[U3];
                    vertices[U3] = vertices[U2];
                    vertices[U2] = tempU;
                    break;
                }
                }
            }
            spriteCache.add(texture, vertices, 0, 20);
        }
    }
}

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.ScreenBase.java

License:Apache License

public void onDrawEye(Eye paramEye) {

    Gdx.gl.glClearColor(BACKGROUND_COLOR.r, BACKGROUND_COLOR.g, BACKGROUND_COLOR.b, BACKGROUND_COLOR.a);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    camera.setEyeViewAdjustMatrix(new Matrix4(paramEye.getEyeView()));
    float[] perspective = paramEye.getPerspective(Z_NEAR, Z_FAR);
    camera.setEyeProjection(new Matrix4(perspective));
    camera.update();//w ww.ja  v a 2 s . c  o  m

    game.modelBatch.begin(camera);
    game.modelBatch.render(instances, environment);
    game.modelBatch.end();

    game.spriteBatch.begin();
    if (showTarget)
        game.spriteBatch.draw(target, (Gdx.graphics.getWidth() - target.getWidth()) / 2,
                (Gdx.graphics.getHeight() - target.getHeight()) / 2);
    if (visibleUI) {
        score.draw(game.spriteBatch, HudUtils.formattedScore(scoreValue),
                (Gdx.graphics.getWidth()
                        - (score.getSpaceWidth() * HudUtils.formattedScore(scoreValue).length())) / 2,
                Gdx.graphics.getHeight() - MARGIN_SCREEN);
        if (life.size() > 0) {
            int size = (life.size() * life.get(0).getWidth()) + ((life.size() - 1) * MARGIN_HEART);
            float center = (Gdx.graphics.getWidth() - size) / 2;
            for (int i = 0; i < life.size(); i++) {
                Texture item = life.get(i);
                game.spriteBatch.draw(item, center + ((item.getWidth() + MARGIN_HEART) * i), MARGIN_SCREEN);
            }
        }
    }
    renderSprite(Gdx.graphics.getDeltaTime());
    game.spriteBatch.end();
    if (endFade.isPlaying)
        endFade.shows(Gdx.graphics.getDeltaTime());
    if (laser.isPlaying)
        laser.shows(Gdx.graphics.getDeltaTime());
}

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.screen.SplashScreen.java

License:Apache License

@Override
public void renderSprite(float delta) {
    if (index < logos.size()) {
        Texture logo = logos.get(index);
        game.spriteBatch.draw(logo, (Gdx.graphics.getWidth() - logo.getWidth()) / 2,
                (Gdx.graphics.getHeight() - logo.getHeight()) / 2);
    }//from   ww w . ja va  2s  .  com
}

From source file:cmnworks.com.angrybee.Actor.java

License:Open Source License

public void ready() {
    Texture.TextureFilter linear = Texture.TextureFilter.Linear;
    Texture actor1 = new Texture(this.setFolder + "actor1.png");
    Texture actor2 = new Texture(this.setFolder + "actor2.png");
    Texture actor3 = new Texture(this.setFolder + "actor3.png");

    actor1.setFilter(linear, linear);// w w w  .j a  v  a2 s  .c o m
    actor2.setFilter(linear, linear);
    actor3.setFilter(linear, linear);
    actor = new Animation(this.setFlappingSpeed, new TextureRegion(actor1), new TextureRegion(actor2),
            new TextureRegion(actor3), new TextureRegion(actor2));
    actor.setPlayMode(Animation.PlayMode.LOOP);

    this.dimension[0] = actor1.getWidth();
    this.dimension[1] = actor1.getHeight();
    this.startingYPoint = (Gdx.graphics.getHeight() / 2) - actor1.getHeight();

    PolygonRegionLoader loader = new PolygonRegionLoader();
    PolygonRegion region = loader.load(new TextureRegion(actor1), Gdx.files.internal(this.setPsh));
    this.polygon = new Polygon(region.getVertices());
}

From source file:com.a2client.gui.GUI_Texture.java

License:Open Source License

public void setTexture(Texture t) {
    _texture = t;
    mode = "spr";
    SetSize(t.getWidth(), t.getHeight());
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified texture to the cache. */
public void add(Texture texture, float x, float y) {
    final float fx2 = x + texture.getWidth();
    final float fy2 = y + texture.getHeight();

    tempVertices[0] = x;//  w w w .  ja v a  2  s  .co  m
    tempVertices[1] = y;
    tempVertices[2] = color;
    tempVertices[3] = 0;
    tempVertices[4] = 1;

    tempVertices[5] = x;
    tempVertices[6] = fy2;
    tempVertices[7] = color;
    tempVertices[8] = 0;
    tempVertices[9] = 0;

    tempVertices[10] = fx2;
    tempVertices[11] = fy2;
    tempVertices[12] = color;
    tempVertices[13] = 1;
    tempVertices[14] = 0;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = fx2;
        tempVertices[16] = y;
        tempVertices[17] = color;
        tempVertices[18] = 1;
        tempVertices[19] = 1;
        add(texture, tempVertices, 0, 20);
    } else {
        tempVertices[15] = fx2;
        tempVertices[16] = fy2;
        tempVertices[17] = color;
        tempVertices[18] = 1;
        tempVertices[19] = 0;

        tempVertices[20] = fx2;
        tempVertices[21] = y;
        tempVertices[22] = color;
        tempVertices[23] = 1;
        tempVertices[24] = 1;

        tempVertices[25] = x;
        tempVertices[26] = y;
        tempVertices[27] = color;
        tempVertices[28] = 0;
        tempVertices[29] = 1;
        add(texture, tempVertices, 0, 30);
    }
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified texture to the cache. */
public void add(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) {
    float invTexWidth = 1.0f / texture.getWidth();
    float invTexHeight = 1.0f / texture.getHeight();
    final float u = srcX * invTexWidth;
    final float v = (srcY + srcHeight) * invTexHeight;
    final float u2 = (srcX + srcWidth) * invTexWidth;
    final float v2 = srcY * invTexHeight;
    final float fx2 = x + srcWidth;
    final float fy2 = y + srcHeight;

    tempVertices[0] = x;/*from   ww w .  j a  v  a 2  s  . c  o  m*/
    tempVertices[1] = y;
    tempVertices[2] = color;
    tempVertices[3] = u;
    tempVertices[4] = v;

    tempVertices[5] = x;
    tempVertices[6] = fy2;
    tempVertices[7] = color;
    tempVertices[8] = u;
    tempVertices[9] = v2;

    tempVertices[10] = fx2;
    tempVertices[11] = fy2;
    tempVertices[12] = color;
    tempVertices[13] = u2;
    tempVertices[14] = v2;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = fx2;
        tempVertices[16] = y;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v;
        add(texture, tempVertices, 0, 20);
    } else {
        tempVertices[15] = fx2;
        tempVertices[16] = fy2;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v2;

        tempVertices[20] = fx2;
        tempVertices[21] = y;
        tempVertices[22] = color;
        tempVertices[23] = u2;
        tempVertices[24] = v;

        tempVertices[25] = x;
        tempVertices[26] = y;
        tempVertices[27] = color;
        tempVertices[28] = u;
        tempVertices[29] = v;
        add(texture, tempVertices, 0, 30);
    }
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified texture to the cache. */
public void add(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth,
        int srcHeight, boolean flipX, boolean flipY) {

    float invTexWidth = 1.0f / texture.getWidth();
    float invTexHeight = 1.0f / texture.getHeight();
    float u = srcX * invTexWidth;
    float v = (srcY + srcHeight) * invTexHeight;
    float u2 = (srcX + srcWidth) * invTexWidth;
    float v2 = srcY * invTexHeight;
    final float fx2 = x + width;
    final float fy2 = y + height;

    if (flipX) {/*from  w  w  w  . j  av  a  2s  .  co  m*/
        float tmp = u;
        u = u2;
        u2 = tmp;
    }
    if (flipY) {
        float tmp = v;
        v = v2;
        v2 = tmp;
    }

    tempVertices[0] = x;
    tempVertices[1] = y;
    tempVertices[2] = color;
    tempVertices[3] = u;
    tempVertices[4] = v;

    tempVertices[5] = x;
    tempVertices[6] = fy2;
    tempVertices[7] = color;
    tempVertices[8] = u;
    tempVertices[9] = v2;

    tempVertices[10] = fx2;
    tempVertices[11] = fy2;
    tempVertices[12] = color;
    tempVertices[13] = u2;
    tempVertices[14] = v2;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = fx2;
        tempVertices[16] = y;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v;
        add(texture, tempVertices, 0, 20);
    } else {
        tempVertices[15] = fx2;
        tempVertices[16] = fy2;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v2;

        tempVertices[20] = fx2;
        tempVertices[21] = y;
        tempVertices[22] = color;
        tempVertices[23] = u2;
        tempVertices[24] = v;

        tempVertices[25] = x;
        tempVertices[26] = y;
        tempVertices[27] = color;
        tempVertices[28] = u;
        tempVertices[29] = v;
        add(texture, tempVertices, 0, 30);
    }
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified texture to the cache. */
public void add(Texture texture, float x, float y, float originX, float originY, float width, float height,
        float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight,
        boolean flipX, boolean flipY) {

    // bottom left and top right corner points relative to origin
    final float worldOriginX = x + originX;
    final float worldOriginY = y + originY;
    float fx = -originX;
    float fy = -originY;
    float fx2 = width - originX;
    float fy2 = height - originY;

    // scale/* w w w. ja  va2 s  .c o m*/
    if (scaleX != 1 || scaleY != 1) {
        fx *= scaleX;
        fy *= scaleY;
        fx2 *= scaleX;
        fy2 *= scaleY;
    }

    // construct corner points, start from top left and go counter clockwise
    final float p1x = fx;
    final float p1y = fy;
    final float p2x = fx;
    final float p2y = fy2;
    final float p3x = fx2;
    final float p3y = fy2;
    final float p4x = fx2;
    final float p4y = fy;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;

    // rotate
    if (rotation != 0) {
        final float cos = MathUtils.cosDeg(rotation);
        final float sin = MathUtils.sinDeg(rotation);

        x1 = cos * p1x - sin * p1y;
        y1 = sin * p1x + cos * p1y;

        x2 = cos * p2x - sin * p2y;
        y2 = sin * p2x + cos * p2y;

        x3 = cos * p3x - sin * p3y;
        y3 = sin * p3x + cos * p3y;

        x4 = x1 + (x3 - x2);
        y4 = y3 - (y2 - y1);
    } else {
        x1 = p1x;
        y1 = p1y;

        x2 = p2x;
        y2 = p2y;

        x3 = p3x;
        y3 = p3y;

        x4 = p4x;
        y4 = p4y;
    }

    x1 += worldOriginX;
    y1 += worldOriginY;
    x2 += worldOriginX;
    y2 += worldOriginY;
    x3 += worldOriginX;
    y3 += worldOriginY;
    x4 += worldOriginX;
    y4 += worldOriginY;

    float invTexWidth = 1.0f / texture.getWidth();
    float invTexHeight = 1.0f / texture.getHeight();
    float u = srcX * invTexWidth;
    float v = (srcY + srcHeight) * invTexHeight;
    float u2 = (srcX + srcWidth) * invTexWidth;
    float v2 = srcY * invTexHeight;

    if (flipX) {
        float tmp = u;
        u = u2;
        u2 = tmp;
    }

    if (flipY) {
        float tmp = v;
        v = v2;
        v2 = tmp;
    }

    tempVertices[0] = x1;
    tempVertices[1] = y1;
    tempVertices[2] = color;
    tempVertices[3] = u;
    tempVertices[4] = v;

    tempVertices[5] = x2;
    tempVertices[6] = y2;
    tempVertices[7] = color;
    tempVertices[8] = u;
    tempVertices[9] = v2;

    tempVertices[10] = x3;
    tempVertices[11] = y3;
    tempVertices[12] = color;
    tempVertices[13] = u2;
    tempVertices[14] = v2;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = x4;
        tempVertices[16] = y4;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v;
        add(texture, tempVertices, 0, 20);
    } else {
        tempVertices[15] = x3;
        tempVertices[16] = y3;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v2;

        tempVertices[20] = x4;
        tempVertices[21] = y4;
        tempVertices[22] = color;
        tempVertices[23] = u2;
        tempVertices[24] = v;

        tempVertices[25] = x1;
        tempVertices[26] = y1;
        tempVertices[27] = color;
        tempVertices[28] = u;
        tempVertices[29] = v;
        add(texture, tempVertices, 0, 30);
    }
}