Search in sources :

Example 1 with Texture

use of com.badlogic.gdx.graphics.Texture in project Entitas-Java by Rubentxu.

the class SplashState method initialize.

@Override
public void initialize() {
    // Input
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
    BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
    systems.add(new DelaySystem(context.core)).add(new RendererSystem(context.core, engine.sr, camera, batch, font));
    Texture texture = assetsManager.getTexture(splash);
    context.core.createEntity().addTextureView("Pong", new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()), new Vector2(), 0, Pong.SCREEN_HEIGHT, Pong.SCREEN_WIDTH).addDelay(3);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch) Vector2(com.badlogic.gdx.math.Vector2) BaseSceneManager(com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager) BaseGUIManager(com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager) RendererSystem(com.ilargia.games.entitas.systems.RendererSystem) Camera(com.badlogic.gdx.graphics.Camera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) DelaySystem(com.ilargia.games.entitas.systems.DelaySystem)

Example 2 with Texture

use of com.badlogic.gdx.graphics.Texture in project Entitas-Java by Rubentxu.

the class SMGUIManager method createSkin.

public Skin createSkin(BaseAssetsManager assetsManager) {
    defaultFont = assetsManager.getFont(DEFAULT_FONT);
    defaultFont.getData().setScale(ScaleUtil.getSizeRatio());
    defaultFont.setUseIntegerPositions(false);
    font2 = assetsManager.getFont(HEADER_FONT);
    font2.getData().setScale(ScaleUtil.getSizeRatio());
    font2.setUseIntegerPositions(false);
    skin.add("default", defaultFont);
    skin.add("header", font2);
    skin.add("lt-blue", new Color(.62f, .76f, .99f, 1f));
    skin.add("lt-green", new Color(.39f, .9f, .6f, 1f));
    skin.add("dark-blue", new Color(.79f, .95f, 91f, 1f));
    skin.addRegions(assetsManager.getTextureAtlas(GUI_ATLAS));
    skin.addRegions(assetsManager.getTextureAtlas(GUI_PACK_ATLAS));
    TextureRegionDrawable touchpad_background = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(GUI_ATLAS)).findRegion("touchpad_background"));
    TextureRegionDrawable touchpad_thumb = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(GUI_ATLAS)).findRegion("touchpad_thumb"));
    TextureRegionDrawable checkox_true = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("check-on"));
    TextureRegionDrawable checkox_false = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("check-off"));
    TextureRegionDrawable slider_knob = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("default-slider-knob"));
    TextureRegionDrawable slider = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("default-slider"));
    CheckBox.CheckBoxStyle checkBoxStyle = new CheckBox.CheckBoxStyle(checkox_false, checkox_true, defaultFont, Color.WHITE);
    SpriteDrawable stats = new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(STATS_BACKGROUND)));
    Slider.SliderStyle sliderStyle = new Slider.SliderStyle(slider, slider_knob);
    skin.add("default", new Window.WindowStyle(font2, Color.ORANGE, skin.getDrawable("debug")));
    skin.add("stats", stats);
    Label.LabelStyle lbs = new Label.LabelStyle();
    lbs.font = defaultFont;
    lbs.fontColor = Color.WHITE;
    skin.add("default", lbs);
    Label.LabelStyle lbsHeader = new Label.LabelStyle();
    lbsHeader.font = font2;
    lbsHeader.fontColor = Color.WHITE;
    skin.add("header", lbsHeader);
    TextButton.TextButtonStyle tbs = new TextButton.TextButtonStyle(skin.getDrawable("btnMenu"), skin.getDrawable("btnMenuPress"), skin.getDrawable("btnMenu"), defaultFont);
    tbs.fontColor = skin.getColor("dark-blue");
    tbs.pressedOffsetX = Math.round(1f * Gdx.graphics.getDensity());
    tbs.pressedOffsetY = tbs.pressedOffsetX * -1f;
    ImageButton.ImageButtonStyle ImageButtonLeft = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonLeft"), skin.getDrawable("buttonLeftPress"), skin.getDrawable("buttonLeft"), null, null, null);
    ImageButton.ImageButtonStyle ImageButtonRight = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonRight"), skin.getDrawable("buttonRightPress"), skin.getDrawable("buttonRight"), null, null, null);
    ImageButton.ImageButtonStyle ImageButtonUp = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonUp"), skin.getDrawable("buttonUpPress"), skin.getDrawable("buttonUp"), null, null, null);
    Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
    touchpadStyle.background = touchpad_background;
    touchpadStyle.knob = touchpad_thumb;
    skin.add("default", tbs);
    skin.add("buttonLeft", ImageButtonLeft);
    skin.add("buttonRight", ImageButtonRight);
    skin.add("buttonUp", ImageButtonUp);
    skin.add("default", touchpadStyle);
    skin.add("default", checkBoxStyle);
    skin.add("default-horizontal", sliderStyle);
    return skin;
}
Also used : TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Color(com.badlogic.gdx.graphics.Color)

Example 3 with Texture

use of com.badlogic.gdx.graphics.Texture in project RubeLoader by tescott.

the class RubeLoaderTest method createPolySpatialsFromRubeFixtures.

/**
    * Creates an array of PolySpatials based on fixture information from the scene. Note that
    * fixtures create aligned textures.
    * 
    * @param scene
    */
private void createPolySpatialsFromRubeFixtures(RubeScene scene) {
    Array<Body> bodies = scene.getBodies();
    EarClippingTriangulator ect = new EarClippingTriangulator();
    if ((bodies != null) && (bodies.size > 0)) {
        polySpatials = new Array<PolySpatial>();
        Vector2 bodyPos = new Vector2();
        // for each body in the scene...
        for (int i = 0; i < bodies.size; i++) {
            Body body = bodies.get(i);
            bodyPos.set(body.getPosition());
            Array<Fixture> fixtures = body.getFixtureList();
            if ((fixtures != null) && (fixtures.size > 0)) {
                // for each fixture on the body...
                for (int j = 0; j < fixtures.size; j++) {
                    Fixture fixture = fixtures.get(j);
                    String textureName = (String) scene.getCustom(fixture, "TextureMask", null);
                    if (textureName != null) {
                        String textureFileName = "data/" + textureName;
                        Texture texture = textureMap.get(textureFileName);
                        TextureRegion textureRegion = null;
                        if (texture == null) {
                            texture = new Texture(textureFileName);
                            texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
                            textureMap.put(textureFileName, texture);
                            textureRegion = new TextureRegion(texture);
                            textureRegionMap.put(texture, textureRegion);
                        } else {
                            textureRegion = textureRegionMap.get(texture);
                        }
                        // only handle polygons at this point -- no chain, edge, or circle fixtures.
                        if (fixture.getType() == Shape.Type.Polygon) {
                            PolygonShape shape = (PolygonShape) fixture.getShape();
                            int vertexCount = shape.getVertexCount();
                            float[] vertices = new float[vertexCount * 2];
                            // static bodies are texture aligned and do not get drawn based off of the related body.
                            if (body.getType() == BodyType.StaticBody) {
                                for (int k = 0; k < vertexCount; k++) {
                                    shape.getVertex(k, mTmp);
                                    mTmp.rotate(body.getAngle() * MathUtils.radiansToDegrees);
                                    // convert local coordinates to world coordinates to that textures are
                                    mTmp.add(bodyPos);
                                    // aligned
                                    vertices[k * 2] = mTmp.x * PolySpatial.PIXELS_PER_METER;
                                    vertices[k * 2 + 1] = mTmp.y * PolySpatial.PIXELS_PER_METER;
                                }
                                short[] triangleIndices = ect.computeTriangles(vertices).toArray();
                                PolygonRegion region = new PolygonRegion(textureRegion, vertices, triangleIndices);
                                PolySpatial spatial = new PolySpatial(region, Color.WHITE);
                                polySpatials.add(spatial);
                            } else {
                                // all other fixtures are aligned based on their associated body.
                                for (int k = 0; k < vertexCount; k++) {
                                    shape.getVertex(k, mTmp);
                                    vertices[k * 2] = mTmp.x * PolySpatial.PIXELS_PER_METER;
                                    vertices[k * 2 + 1] = mTmp.y * PolySpatial.PIXELS_PER_METER;
                                }
                                short[] triangleIndices = ect.computeTriangles(vertices).toArray();
                                PolygonRegion region = new PolygonRegion(textureRegion, vertices, triangleIndices);
                                PolySpatial spatial = new PolySpatial(region, body, Color.WHITE);
                                polySpatials.add(spatial);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) EarClippingTriangulator(com.badlogic.gdx.math.EarClippingTriangulator) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Vector2(com.badlogic.gdx.math.Vector2) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body) PolygonRegion(com.badlogic.gdx.graphics.g2d.PolygonRegion)

Example 4 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class TextureLoader method loadSync.

@Override
public Texture loadSync(AssetManager manager, String fileName, FileHandle file, TextureParameter parameter) {
    if (info == null)
        return null;
    Texture texture = info.texture;
    if (texture != null) {
        texture.load(info.data);
    } else {
        texture = new Texture(info.data);
    }
    if (parameter != null) {
        texture.setFilter(parameter.minFilter, parameter.magFilter);
        texture.setWrap(parameter.wrapU, parameter.wrapV);
    }
    return texture;
}
Also used : Texture(com.badlogic.gdx.graphics.Texture) GLTexture(com.badlogic.gdx.graphics.GLTexture)

Example 5 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class ScreenUtils method getFrameBufferTexture.

/** Returns a portion of the default framebuffer contents specified by x, y, width and height as a {@link TextureRegion} with
	 * the same dimensions. The base {@link Texture} always has {@link MathUtils#nextPowerOfTwo} dimensions and RGBA8888
	 * {@link Format}. It can be accessed via {@link TextureRegion#getTexture}. This texture is not managed and has to be reloaded
	 * manually on a context loss. If the width and height specified are larger than the framebuffer dimensions, the Texture will
	 * be padded accordingly. Pixels that fall outside of the current screen will have RGBA values of 0.
	 * 
	 * @param x the x position of the framebuffer contents to capture
	 * @param y the y position of the framebuffer contents to capture
	 * @param w the width of the framebuffer contents to capture
	 * @param h the height of the framebuffer contents to capture */
public static TextureRegion getFrameBufferTexture(int x, int y, int w, int h) {
    final int potW = MathUtils.nextPowerOfTwo(w);
    final int potH = MathUtils.nextPowerOfTwo(h);
    final Pixmap pixmap = getFrameBufferPixmap(x, y, w, h);
    final Pixmap potPixmap = new Pixmap(potW, potH, Format.RGBA8888);
    potPixmap.drawPixmap(pixmap, 0, 0);
    Texture texture = new Texture(potPixmap);
    TextureRegion textureRegion = new TextureRegion(texture, 0, h, w, -h);
    potPixmap.dispose();
    pixmap.dispose();
    return textureRegion;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)252 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)89 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)57 Stage (com.badlogic.gdx.scenes.scene2d.Stage)50 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)41 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)32 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)29 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)27 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)26 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)18 Actor (com.badlogic.gdx.scenes.scene2d.Actor)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)16 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)14 Material (com.badlogic.gdx.graphics.g3d.Material)12