The problem is that I can not place my objects on the screen beyond the middle . When I go up it reaches a limit and they begin to overlap until it is totally hidden.
There you see how you eat part of the keypad
There it looks clearer.
Here is the code.
package ar.com.tedesafio.game.screen;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.viewport.StretchViewport;
public abstract class AbstractScreen extends Stage implements Screen {
protected final static float WIDTH = Gdx.app.getGraphics().getWidth();
protected final static float HEIGHT = Gdx.app.getGraphics().getHeight();
protected Skin skinGeneral;
private TextureAtlas textureAtlas;
protected AbstractScreen(){
super( new StretchViewport(HEIGHT, WIDTH, new OrthographicCamera()));
skinGeneral = new Skin();
textureAtlas = new TextureAtlas(Gdx.files.internal("skin/metal-ui.atlas"));
skinGeneral.addRegions(textureAtlas);
skinGeneral.load(Gdx.files.internal("skin/metal-ui.json"));
setDebugAll(true);
}
public abstract void buildStage();
@Override
public void render(float delta){
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.act(delta);
super.draw();
}
@Override
public void show(){
Gdx.input.setInputProcessor(this);
}
@Override
public void resize(int width, int height) {
getViewport().update(height, width);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
super.dispose();
skinGeneral.dispose();
textureAtlas.dispose();
}
}
The screens extend from this and the same thing happens to them all.
package ar.com.tedesafio.game.minigames.game001;
import com.badlogic.gdx.graphics.Color;
import ar.com.tedesafio.game.logic.Rectangle;
import ar.com.tedesafio.game.screen.AbstractScreen;
public class Game001 extends AbstractScreen {
@Override
public void buildStage() {
Rectangle r = new Rectangle(0,0,5000,5000, Color.WHITE);
addActor(r);
}
}
Basically all screens are handled like this.
I add the code of the Rectangle class
public class Rectangle extends Actor {
private Texture texture;
public Rectangle(float x, float y, float width, float height, Color color) {
createTexture((int)width, (int)height, color);
setX(x);
setY(y);
setWidth(width);
setHeight(height);
}
private void createTexture(int width, int height, Color color) {
Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
pixmap.fillRectangle(0, 0, width, height);
texture = new Texture(pixmap);
pixmap.dispose();
}
@Override
public void draw(Batch batch, float parentAlpha) {
Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
}
}
I also add the code of the screen with buttons of the capture
public class SelectMenu extends AbstractScreen {
private Table table;
private TextButton [] txtBtnGames;
private TextButton volverBtn;
private final static int CANTIDADGAMES = 5;
public SelectMenu() {
table = new Table();
volverBtn = new TextButton("Volver", skinGeneral);
txtBtnGames = new TextButton[CANTIDADGAMES];
for(int i=0; i<CANTIDADGAMES; i++) {
txtBtnGames[i] = new TextButton(""+(i + 1), skinGeneral);
txtBtnGames[i].getLabel().setFontScale(2);
switch (i){
case 0: txtBtnGames[0].addListener(UIfactory.createListener(ScreenEnum.GAME001_MENU));
break;
case 1: txtBtnGames[1].addListener(UIfactory.createListener(ScreenEnum.GAME002_MENU));
break;
case 2: txtBtnGames[2].addListener(UIfactory.createListener(ScreenEnum.GAME003_MENU));
break;
case 3: txtBtnGames[3].addListener(UIfactory.createListener(ScreenEnum.GAME004_MENU));
break;
case 4: txtBtnGames[4].addListener(UIfactory.createListener(ScreenEnum.GAME005_MENU));
break;
}
}
}
@Override
public void buildStage() {
volverBtn.getLabel().setFontScale(2);
volverBtn.addListener(UIfactory.createListener(ScreenEnum.MAIN_MENU));
table.setTransform(true);
table.setPosition(WIDTH / 2, HEIGHT / 2);
table.setOrigin(0, 0);
table.setScale(4);
table.setDebug(true);
for(int i=0; i<CANTIDADGAMES; i++) {
table.add(txtBtnGames[i]);
if( i % 2 != 0)
table.row();
}
//table.row();
table.add(volverBtn);
addActor(table);
}
@Override
public void dispose() {
super.dispose();
}
}