use of com.badlogic.gdx.InputAdapter in project libgdx by libgdx.
the class BitmapFontFlipTest method create.
@Override
public void create() {
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean touchDown(int x, int y, int pointer, int newParam) {
renderMode = (renderMode + 1) % 4;
return false;
}
});
spriteBatch = new SpriteBatch();
spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
logoSprite = new Sprite(texture);
logoSprite.flip(false, true);
logoSprite.setPosition(0, 320 - 256);
logoSprite.setColor(1, 1, 1, 0.5f);
font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true);
cache1 = font.newFontCache();
cache2 = font.newFontCache();
cache3 = font.newFontCache();
cache4 = font.newFontCache();
cache5 = font.newFontCache();
createCaches("cached", cache1, cache2, cache3, cache4, cache5);
font.getData().setScale(1.33f);
cacheScaled1 = font.newFontCache();
cacheScaled2 = font.newFontCache();
cacheScaled3 = font.newFontCache();
cacheScaled4 = font.newFontCache();
cacheScaled5 = font.newFontCache();
createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5);
}
use of com.badlogic.gdx.InputAdapter in project libgdx by libgdx.
the class ViewportTest1 method create.
public void create() {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
label = new Label("", skin);
Table root = new Table(skin);
root.setFillParent(true);
root.setBackground(skin.getDrawable("default-pane"));
root.debug().defaults().space(6);
root.add(new TextButton("Button 1", skin));
root.add(new TextButton("Button 2", skin)).row();
root.add("Press spacebar to change the viewport:").colspan(2).row();
root.add(label).colspan(2);
stage.addActor(root);
viewports = getViewports(stage.getCamera());
names = getViewportNames();
stage.setViewport(viewports.first());
label.setText(names.first());
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
label.setText(names.get(index));
Viewport viewport = viewports.get(index);
stage.setViewport(viewport);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
}, stage));
}
use of com.badlogic.gdx.InputAdapter in project libgdx by libgdx.
the class TextureAtlasTest method create.
public void create() {
batch = new SpriteBatch();
renderer = new ShapeRenderer();
atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
badlogic = atlas.createSprite("badlogicslice");
badlogic.setPosition(50, 50);
// badlogicSmall = atlas.createSprite("badlogicsmall");
badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
badlogicSmall.setPosition(10, 10);
AtlasRegion region = atlas.findRegion("badlogicsmall");
System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
star = atlas.createSprite("particle-star");
star.setPosition(10, 70);
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
Gdx.gl.glClearColor(0, 1, 0, 1);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyUp(int keycode) {
if (keycode == Keys.UP) {
badlogicSmall.flip(false, true);
} else if (keycode == Keys.RIGHT) {
badlogicSmall.flip(true, false);
} else if (keycode == Keys.LEFT) {
badlogicSmall.setSize(512, 512);
} else if (keycode == Keys.DOWN) {
badlogicSmall.rotate90(true);
}
return super.keyUp(keycode);
}
});
}
use of com.badlogic.gdx.InputAdapter in project var3dframe by Var3D.
the class VGame method setStage.
public <T> void setStage(Class<T> type, String name, HashMap<String, Object> intent) {
isLoading = false;
if (stage != null) {
if (input != null)
multiplexer.removeProcessor(input);
if (gesture != null)
multiplexer.removeProcessor(gesture);
multiplexer.addProcessor(stageTop);
prefStage = stage.getClass();
} else {
multiplexer.addProcessor(stageTop);
}
stage = null;
stage = getStage(type, name);
if (stage != null)
stage.setIntent(intent);
do {
if (stage != null) {
multiplexer.addProcessor(input = (InputAdapter) stage);
if (stage instanceof GestureDetector.GestureListener) {
gesture = new GestureDetector((GestureDetector.GestureListener) stage);
multiplexer.addProcessor(gesture);
} else {
gesture = null;
}
}
} while (stage == null);
}
use of com.badlogic.gdx.InputAdapter in project libgdx by libgdx.
the class Lwjgl3DebugStarter method main.
public static void main(String[] argv) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
GdxTest test = new GdxTest() {
float r = 0;
SpriteBatch batch;
BitmapFont font;
FPSLogger fps = new FPSLogger();
Texture texture;
@Override
public void create() {
BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
texture = new Texture("data/badlogic.jpg");
batch = new SpriteBatch();
font = new BitmapFont();
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean keyDown(int keycode) {
System.out.println("Key down: " + Keys.toString(keycode));
return false;
}
@Override
public boolean keyUp(int keycode) {
System.out.println("Key up: " + Keys.toString(keycode));
return false;
}
@Override
public boolean keyTyped(char character) {
System.out.println("Key typed: '" + character + "', " + (int) character);
if (character == 'f') {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
// DisplayMode[] modes = Gdx.graphics.getDisplayModes();
// for(DisplayMode mode: modes) {
// if(mode.width == 1920 && mode.height == 1080) {
// Gdx.graphics.setFullscreenMode(mode);
// break;
// }
// }
}
if (character == 'w') {
Gdx.graphics.setWindowedMode(MathUtils.random(400, 800), MathUtils.random(400, 800));
}
if (character == 'e') {
throw new GdxRuntimeException("derp");
}
if (character == 'c') {
Gdx.input.setCursorCatched(!Gdx.input.isCursorCatched());
}
Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
if (character == 'v') {
window.setVisible(false);
}
if (character == 's') {
window.setVisible(true);
}
if (character == 'q') {
window.closeWindow();
}
if (character == 'i') {
window.iconifyWindow();
}
if (character == 'm') {
window.maximizeWindow();
}
if (character == 'r') {
window.restoreWindow();
}
if (character == 'u') {
Gdx.net.openURI("https://google.com");
}
return false;
}
});
}
long start = System.nanoTime();
@Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.begin();
font.draw(batch, Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() + ", " + Gdx.graphics.getBackBufferWidth() + "x" + Gdx.graphics.getBackBufferHeight() + ", " + Gdx.input.getX() + ", " + Gdx.input.getY() + ", " + Gdx.input.getDeltaX() + ", " + Gdx.input.getDeltaY(), 0, 20);
batch.draw(texture, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
batch.end();
fps.log();
}
@Override
public void resize(int width, int height) {
Gdx.app.log("Test", "Resized " + width + "x" + height);
}
@Override
public void resume() {
Gdx.app.log("Test", "resuming");
}
@Override
public void pause() {
Gdx.app.log("Test", "pausing");
}
@Override
public void dispose() {
Gdx.app.log("Test", "disposing");
}
};
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setWindowedMode(640, 480);
config.setWindowListener(new Lwjgl3WindowListener() {
@Override
public void iconified(boolean isIconified) {
Gdx.app.log("Window", "iconified: " + (isIconified ? "true" : "false"));
}
@Override
public void maximized(boolean isMaximized) {
Gdx.app.log("Window", "maximized: " + (isMaximized ? "true" : "false"));
}
@Override
public void focusLost() {
Gdx.app.log("Window", "focus lost");
}
@Override
public void focusGained() {
Gdx.app.log("Window", "focus gained");
}
@Override
public boolean closeRequested() {
Gdx.app.log("Window", "closing");
return false;
}
@Override
public void filesDropped(String[] files) {
for (String file : files) {
Gdx.app.log("Window", "File dropped: " + file);
}
}
@Override
public void refreshRequested() {
Gdx.app.log("Window", "refreshRequested");
}
});
for (DisplayMode mode : Lwjgl3ApplicationConfiguration.getDisplayModes()) {
System.out.println(mode.width + "x" + mode.height);
}
System.setProperty("java.awt.headless", "true");
new Lwjgl3Application(test, config);
}
Aggregations