Search in sources :

Example 91 with SpriteBatch

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

the class NetAPITest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    {
        statusLabel = new Label("", skin);
        statusLabel.setWrap(true);
        statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
        statusLabel.setAlignment(Align.center);
        statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
        statusLabel.setColor(Color.CYAN);
        stage.addActor(statusLabel);
    }
    {
        ClickListener clickListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                clickedButton = event.getListenerActor();
                setButtonDisabled(true);
                if (texture != null)
                    texture.dispose();
                texture = null;
                text = null;
                String url;
                String httpMethod = Net.HttpMethods.GET;
                String requestContent = null;
                if (clickedButton == btnDownloadImage)
                    url = "http://i.imgur.com/vxomF.jpg";
                else if (clickedButton == btnDownloadText)
                    url = "http://www.apache.org/licenses/LICENSE-2.0.txt";
                else if (clickedButton == btnDownloadLarge)
                    url = "http://libgdx.badlogicgames.com/releases/libgdx-1.2.0.zip";
                else if (clickedButton == btnDownloadError)
                    url = "http://www.badlogicgames.com/doesnotexist";
                else if (clickedButton == btnOpenUri) {
                    Gdx.net.openURI("http://libgdx.badlogicgames.com/");
                    return;
                } else {
                    url = "http://posttestserver.com/post.php?dump";
                    httpMethod = Net.HttpMethods.POST;
                    requestContent = "name1=value1&name2=value2";
                }
                httpRequest = new HttpRequest(httpMethod);
                httpRequest.setUrl(url);
                httpRequest.setContent(requestContent);
                Gdx.net.sendHttpRequest(httpRequest, NetAPITest.this);
                statusLabel.setText("Downloading data from " + httpRequest.getUrl());
            }
        };
        ClickListener cancelListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if (httpRequest != null) {
                    Gdx.net.cancelHttpRequest(httpRequest);
                    Gdx.app.log("NetAPITest", "Cancelling request " + httpRequest.getUrl());
                    statusLabel.setText("Cancelling request " + httpRequest.getUrl());
                }
            }
        };
        btnCancel = new TextButton("Cancel", skin);
        btnCancel.setPosition(Gdx.graphics.getWidth() * 0.10f, 60f);
        btnCancel.addListener(cancelListener);
        stage.addActor(btnCancel);
        btnDownloadImage = new TextButton("GET Image", skin);
        btnDownloadImage.setPosition(btnCancel.getX() + btnCancel.getWidth() + 10, 60f);
        btnDownloadImage.addListener(clickListener);
        stage.addActor(btnDownloadImage);
        btnDownloadText = new TextButton("GET Text", skin);
        btnDownloadText.setPosition(btnDownloadImage.getX() + btnDownloadImage.getWidth() + 10, 60f);
        btnDownloadText.addListener(clickListener);
        stage.addActor(btnDownloadText);
        btnDownloadLarge = new TextButton("GET Large", skin);
        btnDownloadLarge.setPosition(btnDownloadText.getX() + btnDownloadText.getWidth() + 10, 60f);
        btnDownloadLarge.addListener(clickListener);
        stage.addActor(btnDownloadLarge);
        btnDownloadError = new TextButton("GET Error", skin);
        btnDownloadError.setPosition(btnDownloadLarge.getX() + btnDownloadLarge.getWidth() + 10, 60f);
        btnDownloadError.addListener(clickListener);
        stage.addActor(btnDownloadError);
        btnPost = new TextButton("POST", skin);
        btnPost.setPosition(btnDownloadError.getX() + btnDownloadError.getWidth() + 10, 60f);
        btnPost.addListener(clickListener);
        stage.addActor(btnPost);
        btnOpenUri = new TextButton("Open URI", skin);
        btnOpenUri.setPosition(btnPost.getX() + btnPost.getWidth() + 10, 60f);
        btnOpenUri.addListener(clickListener);
        stage.addActor(btnOpenUri);
    }
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 92 with SpriteBatch

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

the class IssueTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    img = new Texture("data/issue/bark.png");
    img2 = new Texture("data/issue/leaf.png");
}
Also used : SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 93 with SpriteBatch

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

the class ModelLoaderTest method create.

@Override
public void create() {
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(0, 0, 5);
    camera.near = 1;
    camera.far = 100;
    camera.update();
    assets = new AssetManager();
    assets.load("data/g3d/cube.g3dj", Model.class);
    spriteBatch = new SpriteBatch();
    modelBatch = new ModelBatch();
// assets.getLogger().setLevel(Logger.DEBUG);
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 94 with SpriteBatch

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

the class RotationTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/black_marked_0.png"));
    region = new TextureRegion(texture);
    batch = new SpriteBatch();
    batch.getTransformMatrix().setToTranslation(30.5f, 30.5f, 0);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 95 with SpriteBatch

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

the class UISimpleTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
    // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));
    // Store the default libgdx font under the name "default".
    skin.add("default", new BitmapFont());
    // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);
    // Create a table that fills the screen. Everything else will go inside this table.
    Table table = new Table();
    table.setFillParent(true);
    stage.addActor(table);
    // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default".
    final TextButton button = new TextButton("Click me!", skin);
    table.add(button);
    // Add a listener to the button. ChangeListener is fired when the button's checked state changes, eg when clicked,
    // Button#setChecked() is called, via a key press, etc. If the event.cancel() is called, the checked state will be reverted.
    // ClickListener could have been used, but would only fire when clicked. Also, canceling a ClickListener event won't
    // revert the checked state.
    button.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("Clicked! Is checked: " + button.isChecked());
            button.setText("Good job!");
        }
    });
    // Add an image actor. Have to set the size, else it would be the size of the drawable (which is the 1x1 texture).
    table.add(new Image(skin.newDrawable("white", Color.RED))).size(64);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)121 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)64 Texture (com.badlogic.gdx.graphics.Texture)59 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)32 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)22 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)16 Pixmap (com.badlogic.gdx.graphics.Pixmap)15 AssetManager (com.badlogic.gdx.assets.AssetManager)13 Stage (com.badlogic.gdx.scenes.scene2d.Stage)13 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)11 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)10 InputAdapter (com.badlogic.gdx.InputAdapter)9 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)8 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)7 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)7 Vector2 (com.badlogic.gdx.math.Vector2)7