Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia | |||
|
libgdx_stage [2025/02/17 18:17] enric_mieza_sanchez |
libgdx_stage [2026/04/07 23:30] (actual) enric_mieza_sanchez |
||
|---|---|---|---|
| Línia 21: | Línia 21: | ||
| <file java Main.java> | <file java Main.java> | ||
| - | package com.myuser.myapp; | + | package com.myuser.scenegdx; |
| - | import com.badlogic.gdx.ApplicationAdapter; | ||
| - | import com.badlogic.gdx.Gdx; | ||
| - | import com.badlogic.gdx.graphics.GL20; | ||
| - | import com.badlogic.gdx.graphics.Texture; | ||
| - | import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
| - | import com.badlogic.gdx.utils.ScreenUtils; | ||
| import com.badlogic.gdx.ApplicationAdapter; | import com.badlogic.gdx.ApplicationAdapter; | ||
| import com.badlogic.gdx.Gdx; | import com.badlogic.gdx.Gdx; | ||
| import com.badlogic.gdx.graphics.GL20; | import com.badlogic.gdx.graphics.GL20; | ||
| import com.badlogic.gdx.graphics.g2d.BitmapFont; | import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
| + | import com.badlogic.gdx.scenes.scene2d.InputEvent; | ||
| import com.badlogic.gdx.scenes.scene2d.Stage; | import com.badlogic.gdx.scenes.scene2d.Stage; | ||
| - | import com.badlogic.gdx.scenes.scene2d.ui.Button; | ||
| import com.badlogic.gdx.scenes.scene2d.ui.Label; | import com.badlogic.gdx.scenes.scene2d.ui.Label; | ||
| import com.badlogic.gdx.scenes.scene2d.ui.Skin; | import com.badlogic.gdx.scenes.scene2d.ui.Skin; | ||
| import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||
| - | import com.badlogic.gdx.utils.viewport.ScreenViewport; | + | import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; |
| + | import com.badlogic.gdx.utils.viewport.FitViewport; | ||
| public class Main extends ApplicationAdapter { | public class Main extends ApplicationAdapter { | ||
| private Stage stage; | private Stage stage; | ||
| private Skin skin; | private Skin skin; | ||
| + | public FitViewport viewport; | ||
| @Override | @Override | ||
| public void create() { | public void create() { | ||
| // Crear un Stage i un Skin | // Crear un Stage i un Skin | ||
| - | stage = new Stage(new ScreenViewport()); | + | |
| + | | ||
| skin = new Skin(Gdx.files.internal(" | skin = new Skin(Gdx.files.internal(" | ||
| + | float escala = viewport.getWorldHeight() / Gdx.graphics.getHeight(); | ||
| - | // Crear un Label (TextView) | + | // Ajustem paràmetres per a la font |
| Label.LabelStyle labelStyle = new Label.LabelStyle(); | Label.LabelStyle labelStyle = new Label.LabelStyle(); | ||
| labelStyle.font = new BitmapFont(); | labelStyle.font = new BitmapFont(); | ||
| + | labelStyle.font.setUseIntegerPositions(false); | ||
| + | labelStyle.font.getData().setScale( escala ); | ||
| + | |||
| + | // Creem label (TextView) | ||
| Label label = new Label(" | Label label = new Label(" | ||
| - | label.setPosition(100, 400); // Posició del Label | + | label.setPosition(1, 1); // Posició del Label |
| // Crear un Button | // Crear un Button | ||
| - | | + | |
| - | button.setPosition(100, 300); // Posició del Button | + | button.setPosition(2, 2); // Posició del Button |
| - | button.setSize(200, 50); // Mida del Button | + | button.setTransform(true); |
| + | button.setScale( 2*escala ); | ||
| + | button.addListener(new ClickListener() { | ||
| + | @Override | ||
| + | public void clicked(InputEvent event, float x, float y) { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | }); | ||
| // Afegir els actors al Stage | // Afegir els actors al Stage | ||
| Línia 86: | Línia 94: | ||
| } | } | ||
| } | } | ||
| - | |||
| </ | </ | ||