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);
}
}
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");
}
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);
}
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);
}
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);
}
Aggregations