How to make a scene camera a grid?

Anything libgdx related goes here!

How to make a scene camera a grid?

Postby TruePlayer » Thu Aug 15, 2019 11:23 pm

I started my creation path with training on obviam.net
An imaginary grid is very conveniently made there.
Code: Select all
private OrthographicCamera cam;
this.cam = new OrthographicCamera(10, 7);
this.cam.position.set(5, 3.5f, 0);
this.cam.update();


Conventional grid 10x7 is very convenient for creating a model it's just to indicate the position of the characters (models):
Code: Select all
player = new Player(new Vector2(7, 2));
blocks.add(new Block(new Vector2(9, 2)));
blocks.add(new Block(new Vector2(9, 3)));

there was also a very simple calculation of the scale, on any screens the player looked like I wanted
Code: Select all
 ppuX = (float)width / CAMERA_WIDTH;
 ppuY = (float)height / CAMERA_HEIGHT;

batch.draw(playerFrame,
                player.getPosition().x * ppuX,
                player.getPosition().y * ppuY,
                Player.SIZE*ppuX,
                Player.SIZE*ppuY);



now I need to completely switch to scene2d pattern I have big problems, I don’t understand (I tried a lot) how to present the camera looking at the scene in the form of the same grid.
I want to scale and set coordinates just as easily, I want to work with abstract units and not with pixels. tell me in what direction should I think?
TruePlayer
 
Posts: 54
Joined: Sun Jul 28, 2019 12:22 pm

Re: How to make a scene camera a grid?

Postby tomski » Fri Aug 16, 2019 7:12 am

Dont do any of that ppuX stuff. Just give the Stage the same configured camera, you can pass it in constructor for Stage.
tomski
 
Posts: 897
Joined: Wed Jun 26, 2013 6:06 pm

Re: How to make a scene camera a grid?

Postby TruePlayer » Fri Aug 16, 2019 5:52 pm

when creating a scene, it is impossible to add camera settings or the camera itself to the constructor.
Code: Select all
public class SceneState extends GameState implements Screen {

    private Stage stage;

    private static float CAMERA_WIDTH = 10f;
    private static float CAMERA_HEIGHT = 7f;
    private ParallaxForScene parallaxForScene;


    public SceneState(GameStateManager gsm){
        super(gsm);
        this.camera.setToOrtho(true, CAMERA_WIDTH, CAMERA_HEIGHT);
        this.camera.position.set(CAMERA_WIDTH/2f, CAMERA_HEIGHT/2f, 0);
        this.camera.update();
    }

    @Override
    public void show() {
        stage = new Stage();
        parallaxForScene = new ParallaxForScene();
        stage.addActor(parallaxForScene);
    }

    @Override
    public void render(float delta) {
        camera.update();
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}


the first thing when testing, I just transferred the settings as you said, but the result is a microscopic image of my actor in the lower left corner)
TruePlayer
 
Posts: 54
Joined: Sun Jul 28, 2019 12:22 pm

Re: How to make a scene camera a grid?

Postby shatterblast » Fri Aug 16, 2019 6:48 pm

TruePlayer wrote:
Code: Select all
    private static float CAMERA_WIDTH = 10f;
    private static float CAMERA_HEIGHT = 7f;


the first thing when testing, I just transferred the settings as you said, but the result is a microscopic image of my actor in the lower left corner

Those values look super small?
shatterblast
 
Posts: 368
Joined: Sun Jul 06, 2014 1:14 pm

Re: How to make a scene camera a grid?

Postby TruePlayer » Fri Aug 16, 2019 7:06 pm

but I did it before, here is my previous rendering method, in which everything worked perfectly!
Code: Select all

public class WorldRenderer {
    /** FOR DEBUG INFO **/
    private BitmapFont debugFont;

    /** Textures **/
    private TextureRegion playerIDLE;
    private Texture playerRun;
    private Texture playerUp;
    private Texture playerDown;
    private Texture playerSlid;

    private Texture enemyHumanRun;
    private Texture enemyHumanAttack;
    private Texture enemyDogRun;
    private Texture enemyDogAttack;

    private Texture firstParallaxLayer;
    private Texture secondParallaxLayer;

    /** Animations **/
    private static final float RUNNING_FRAME_DURATION = 0.03f;
    private static final float JUMPING_FRAME_DURATION = 0.1f;
    private static final int  RUN_FRAME_COLS  =  1 , RUN_FRAME_ROWS  =  17 ;
    private static final int  OTHER_FRAME_COLS  =  1 , OTHER_FRAME_ROWS  = 6 ;

    private Animation playerRunAnimation;
    private Animation playerUpAnimation;
    private Animation playerDownAnimation;
    private Animation playerSlidAnimation;

    private Animation humanRunAnimation;
    private Animation humanAttackAnimation;
    private Animation dogRunAnimation;
    private Animation dogAttackAnimation;


    private Array<TextureRegion> frames;
    private TextureRegion[][] tmp;
    private TextureRegion currFrame;

    /** Other **/
    private World world;
    private OrthographicCamera camera;
    private SpriteBatch batch;
    private static final float CAMERA_WIDTH = 10f;
    private static final float CAMERA_HEIGHT = 7f;

    /**эти переменные необходимы для правильного отображения элементов.
     * Ширина и высота содержат размер экрана в пикселях и передаются из операционной системы на шаге изменения размера.
     * PpuX и ppuY - это количество пикселей на единицу.*/
    private int width;
    private int height;
    private static float ppuX; // pixels per unit on the X axis
    private static float ppuY; // pixels per unit on the Y axis
    /** Мы будем использовать это для рисования примитивов (прямоугольников) для сущностей.**/
    private ShapeRenderer renderer = new ShapeRenderer();
    private boolean debug;

    public WorldRenderer(World world, SpriteBatch batch, boolean debug) {
        debugFont = new BitmapFont();
        debugFont.setColor(Color.WHITE);

        frames = new Array<TextureRegion>();
        this.world = world;
        this.batch = batch;
        this.debug = debug;
        /**Мы создаем камеру с областью просмотра 10 единиц в ширину и 7 единиц в высоту.
         * Это означает, что заполнение экрана единичными блоками (width = height = 1)
         * приведет к отображению 10 блоков по оси X и 7 по оси Y.**/
        this.camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
        this.camera.position.set(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f, 0);
        this.camera.update();
        loadTexture();
        loadAnimation();
    }
    public void render() {
        if (debug) {
            drawDebug();
        }else{
            drawBackground();
            drawPlayer();
            drawEnemys();
            drawScore();
        }
    }

    public void setSize (int width, int height) {
        this.width = width;
        this.height = height;
        ppuX = (float)width / CAMERA_WIDTH;
        ppuY = (float)height / CAMERA_HEIGHT;
    }
    private void loadTexture(){
        playerIDLE = new TextureRegion(new Texture(Gdx.files.internal("animation/player/idle.png")));
        playerRun = new Texture(Gdx.files.internal("animation/player/run.png"));
        playerUp = new Texture(Gdx.files.internal("animation/player/up.png"));
        playerDown = new Texture(Gdx.files.internal("animation/player/down.png"));
        playerSlid = new Texture(Gdx.files.internal("animation/player/slid.png"));
        enemyHumanRun = new Texture(Gdx.files.internal("animation/enemy/human/run.png"));
        enemyHumanAttack = new Texture(Gdx.files.internal("animation/enemy/human/attack.png"));
        enemyDogRun = new Texture(Gdx.files.internal("animation/enemy/dog/run.png"));
        enemyDogAttack = new Texture(Gdx.files.internal("animation/enemy/dog/attack.png"));
        firstParallaxLayer = new Texture(Gdx.files.internal("animation/parallax/first_layer_1920x236.png"));
        secondParallaxLayer = new Texture(Gdx.files.internal("animation/parallax/second_layer_1920x427.png"));
    }
    private void loadAnimation() {

        /*****************SET RUN ANIMATION************************/
        tmp = TextureRegion.split(playerRun,
                playerRun.getWidth() / RUN_FRAME_COLS,
                playerRun.getHeight() / RUN_FRAME_ROWS);
        for (int i = 0; i < RUN_FRAME_ROWS; i++)
            for (int j = 0; j < RUN_FRAME_COLS; j++)
                frames.add(tmp[i][j]);
        playerRunAnimation = new Animation<TextureRegion>(RUNNING_FRAME_DURATION, frames);
        frames.clear();

        /*****************SET UP ANIMATION************************/
        tmp = TextureRegion.split(playerUp,
                playerUp.getWidth() / OTHER_FRAME_COLS,
                playerUp.getHeight() / OTHER_FRAME_ROWS);
        for (int i = 0; i < OTHER_FRAME_ROWS; i++)
            for (int j = 0; j < OTHER_FRAME_COLS; j++)
                frames.add(tmp[i][j]);
        playerUpAnimation = new Animation<TextureRegion>(JUMPING_FRAME_DURATION, frames);
        frames.clear();

        /*****************SET DOWN ANIMATION************************/
        tmp = TextureRegion.split(playerDown,
                playerDown.getWidth() / OTHER_FRAME_COLS,
                playerDown.getHeight() / OTHER_FRAME_ROWS);
        for (int i = 0; i < OTHER_FRAME_ROWS; i++)
            for (int j = 0; j < OTHER_FRAME_COLS; j++)
                frames.add(tmp[i][j]);
        playerDownAnimation = new Animation<TextureRegion>(JUMPING_FRAME_DURATION, frames);
        frames.clear();

        /*****************SET SLID ANIMATION************************/
        tmp = TextureRegion.split(playerSlid,
                playerSlid.getWidth() / OTHER_FRAME_COLS,
                playerSlid.getHeight() / OTHER_FRAME_ROWS);
        for (int i = 0; i < OTHER_FRAME_ROWS; i++)
            for (int j = 0; j < OTHER_FRAME_COLS; j++)
                frames.add(tmp[i][j]);
        playerSlidAnimation = new Animation<TextureRegion>(JUMPING_FRAME_DURATION, frames);
        frames.clear();


        /*****************HUMAN RUN ANIMATION************************/
        tmp = TextureRegion.split(enemyHumanRun,
                enemyHumanRun.getWidth() / 8,
                enemyHumanRun.getHeight() / 1);
        for (int i = 0; i < 1; i++)
            for (int j = 0; j < 8; j++)
                frames.add(tmp[i][j]);
        humanRunAnimation = new Animation<TextureRegion>(RUNNING_FRAME_DURATION, frames);
        frames.clear();

        /*****************HUMAN ATTACK ANIMATION************************/
        tmp = TextureRegion.split(enemyHumanAttack,
                enemyHumanAttack.getWidth() / 8,
                enemyHumanAttack.getHeight() / 1);
        for (int i = 0; i < 1; i++)
            for (int j = 0; j < 8; j++)
                frames.add(tmp[i][j]);
        humanAttackAnimation = new Animation<TextureRegion>(JUMPING_FRAME_DURATION, frames);
        frames.clear();

        /*****************DOG RUN ANIMATION************************/
        tmp = TextureRegion.split(enemyDogRun,
                enemyDogRun.getWidth() / 1,
                enemyDogRun.getHeight() / 7);
        for (int i = 0; i < 7; i++)
            for (int j = 0; j < 1; j++)
                frames.add(tmp[i][j]);
        dogRunAnimation = new Animation<TextureRegion>(JUMPING_FRAME_DURATION, frames);
        frames.clear();

        /*****************DOG ATTACK ANIMATION************************/
        tmp = TextureRegion.split(enemyDogAttack,
                enemyDogAttack.getWidth() / 1,
                enemyDogAttack.getHeight() / 7);
        for (int i = 0; i < 7; i++)
            for (int j = 0; j < 1; j++)
                frames.add(tmp[i][j]);
        dogAttackAnimation = new Animation<TextureRegion>(0.3f, frames);
        frames.clear();
    }
    private void drawPlayer(){
        Player player = world.getPlayer();
        currFrame = playerIDLE;
        if(player.getCurrentState().equals(Player.State.RUNNING)) {
            currFrame = (TextureRegion) playerRunAnimation.getKeyFrame(player.getStateTime(), true);
        }
        if(player.getCurrentState().equals(Player.State.JUMPING)){
            if (player.getVelocity().y > 0) {
                currFrame = (TextureRegion) playerUpAnimation.getKeyFrame(player.getStateTime(), true);
            }else{
                currFrame = (TextureRegion) playerDownAnimation.getKeyFrame(player.getStateTime(), true);
            }
        }
        if(player.getCurrentState().equals(Player.State.SLIDING)){
            currFrame = (TextureRegion) playerSlidAnimation.getKeyFrame(player.getStateTime(), true);
        }

        batch.begin();
        batch.draw(currFrame,
                player.getPosition().x * ppuX,
                player.getPosition().y * ppuY,
                Player.SIZE*ppuX,
                Player.SIZE*ppuY);
        batch.end();
    }
    private void drawBackground(){
        batch.begin();
        for(ParallaxLayer layer : world.getBackground().getAllLayers()) {
            switch (layer.getCurrentLayerNumber()) {
                case (1):
                    batch.draw(firstParallaxLayer,
                            layer.getPosition().x * ppuX,
                            layer.getPosition().y * ppuY,
                            layer.getBounds().width * ppuX,
                            layer.getBounds().height * ppuY);
                    break;
                case (2):
                    batch.draw(secondParallaxLayer,
                            layer.getPosition().x * ppuX,
                            layer.getPosition().y * ppuY,
                            layer.getBounds().width * ppuX,
                            layer.getBounds().height * ppuY);
                    break;
            }
        }
        batch.end();
    }
    private void drawScore(){
        batch.begin();
        debugFont.draw(batch, "SCORE: " + world.getScore()/10, 8f*ppuX, 6f*ppuY);
        batch.end();
    }
    private void drawEnemys(){
        batch.begin();
        for(Enemy enemy : world.getEnemyGenerator().getEnemies()){
            if(enemy.getCurrentType().equals(Enemy.Type.HUMAN)) {
                if(enemy.getCurrentState().equals(Enemy.State.RUNNING)){
                    currFrame = (TextureRegion)humanRunAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
                else if(enemy.getCurrentState().equals(Enemy.State.ATTACK)){
                    currFrame = (TextureRegion)humanAttackAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
            }
            else if(enemy.getCurrentType().equals(Enemy.Type.DOG)){
                if(enemy.getCurrentState().equals(Enemy.State.RUNNING)){
                    currFrame = (TextureRegion)dogRunAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
                else if(enemy.getCurrentState().equals(Enemy.State.ATTACK)){
                    currFrame = (TextureRegion)dogAttackAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
            }

            batch.draw(currFrame,
                    enemy.getPosition().x * ppuX,
                    enemy.getPosition().y * ppuY,
                    enemy.getCurrentType().equals(Enemy.Type.DOG) ? enemy.getSIZE_X() * ppuX : enemy.getSIZE_X()*1.5f * ppuX,
                    enemy.getCurrentType().equals(Enemy.Type.DOG) ? enemy.getSIZE_Y()*1.5f * ppuY : enemy.getSIZE_Y()*2 * ppuY);
        }
        batch.end();
    }
    private void drawDebug() {
        Player player = world.getPlayer();

        batch.begin();

        /******************************************************************************************/
        /***********************************DEBUG INFO*********************************************/
        /******************************************************************************************/

        debugFont.draw(batch, "position_X: " + player.getPosition().x, 0, 720);
        debugFont.draw(batch, "position_Y: " + player.getPosition().y, 0, 700);
        debugFont.draw(batch, "acceleration_X: " + player.getAcceleration().x, 0, 660);
        debugFont.draw(batch, "acceleration_Y: " + player.getAcceleration().y, 0, 640);
        debugFont.draw(batch, "velocity_X: " + player.getVelocity().x, 0, 600);
        debugFont.draw(batch, "velocity_Y: " + player.getVelocity().y, 0, 580);

        debugFont.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 300, 720);
        debugFont.draw(batch, "PlayerCurrentState: " + player.getCurrentState(), 300, 700);
        debugFont.draw(batch, "Enemys count: " + world.getEnemyGenerator().getEnemies().size, 300, 680);

        /******************************************************************************************/
        /************************************PARALLAX BACKGROUND***********************************/
        /******************************************************************************************/

        for(ParallaxLayer layer : world.getBackground().getAllLayers()) {
            switch (layer.getCurrentLayerNumber()) {
                case (1):
                    batch.draw(firstParallaxLayer,
                            layer.getPosition().x * ppuX,
                            layer.getPosition().y * ppuY,
                            layer.getBounds().width * ppuX,
                            layer.getBounds().height * ppuY);
                    break;
                case (2):
                    batch.draw(secondParallaxLayer,
                            layer.getPosition().x * ppuX,
                            layer.getPosition().y * ppuY,
                            layer.getBounds().width * ppuX,
                            layer.getBounds().height * ppuY);
                    break;
            }
        }

        /******************************************************************************************/
        /***************************************PLAYER*********************************************/
        /******************************************************************************************/

        currFrame = playerIDLE;
        if(player.getCurrentState().equals(Player.State.RUNNING)) {
            currFrame = (TextureRegion) playerRunAnimation.getKeyFrame(player.getStateTime(), true);
        }
        if(player.getCurrentState().equals(Player.State.JUMPING)){
            if (player.getVelocity().y > 0) {
                currFrame = (TextureRegion) playerUpAnimation.getKeyFrame(player.getStateTime(), true);
            }else{
                currFrame = (TextureRegion) playerDownAnimation.getKeyFrame(player.getStateTime(), true);
            }
        }
        if(player.getCurrentState().equals(Player.State.SLIDING)){
            currFrame = (TextureRegion) playerSlidAnimation.getKeyFrame(player.getStateTime(), true);
        }

        batch.draw(currFrame,
                player.getPosition().x * ppuX,
                player.getPosition().y * ppuY,
                Player.SIZE*ppuX,
                Player.SIZE*ppuY);

        /******************************************************************************************/
        /***************************************ENEMYS*********************************************/
        /******************************************************************************************/

        for(Enemy enemy : world.getEnemyGenerator().getEnemies()){
            if(enemy.getCurrentType().equals(Enemy.Type.HUMAN)) {
                if(enemy.getCurrentState().equals(Enemy.State.RUNNING)){
                    currFrame = (TextureRegion)humanRunAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
                else if(enemy.getCurrentState().equals(Enemy.State.ATTACK)){
                    currFrame = (TextureRegion)humanAttackAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
            }
            else if(enemy.getCurrentType().equals(Enemy.Type.DOG)){
                if(enemy.getCurrentState().equals(Enemy.State.RUNNING)){
                    currFrame = (TextureRegion)dogRunAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
                else if(enemy.getCurrentState().equals(Enemy.State.ATTACK)){
                    currFrame = (TextureRegion)dogAttackAnimation.getKeyFrame(enemy.getStateTime(), true);
                }
            }

            batch.draw(currFrame,
                    enemy.getPosition().x * ppuX,
                    enemy.getPosition().y * ppuY,
                    enemy.getCurrentType().equals(Enemy.Type.DOG) ? enemy.getSIZE_X() * ppuX : enemy.getSIZE_X()*1.5f * ppuX,
                    enemy.getCurrentType().equals(Enemy.Type.DOG) ? enemy.getSIZE_Y()*1.5f * ppuY : enemy.getSIZE_Y()*2 * ppuY);
        }

        batch.end();



        renderer.setProjectionMatrix(camera.combined);
        renderer.begin(ShapeRenderer.ShapeType.Filled);

        /******************************************************************************************/
        /***************************************PLAYER HITBOX**************************************/
        /******************************************************************************************/

        renderer.setColor(new Color(0, 255, 0, 1));
        renderer.rect(
                player.getPosition().x + 0.2f,
                player.getPosition().y + 0.2f,
                player.getBounds().width,
                player.getBounds().height);

        /******************************************************************************************/
        /***************************************ENEMYS HITBOX**************************************/
        /******************************************************************************************/
        Array<Enemy> enemies = world.getEnemyGenerator().getEnemies();
        Iterator<Enemy> iterator = enemies.iterator();
        Enemy tmp;
        while(iterator.hasNext()){
            tmp = iterator.next();
            if(tmp.getPosition().x <= -1f){
                iterator.remove();
            }
            else{
                if(tmp.getCurrentType().equals(Enemy.Type.HUMAN)){
                    renderer.setColor(new Color(255, 0, 0, 1));
                    renderer.rect(
                            tmp.getPosition().x + 0.45f,
                            tmp.getPosition().y + 0.1f,
                            tmp.getBounds().width,
                            tmp.getBounds().height);
                }
                if(tmp.getCurrentType().equals(Enemy.Type.DOG)){
                    renderer.setColor(new Color(0, 0, 255, 1));
                    renderer.rect(
                            tmp.getPosition().x + 0.3f,
                            tmp.getPosition().y + 0.2f,
                            tmp.getBounds().width,
                            tmp.getBounds().height);
                }
            }
        }
        renderer.end();
    }
}
TruePlayer
 
Posts: 54
Joined: Sun Jul 28, 2019 12:22 pm

Re: How to make a scene camera a grid?

Postby shatterblast » Fri Aug 16, 2019 7:17 pm

Assuming you did so, what parts of your code did you remove? Or what parts did you add for this posting?

I think a Camera has the ability to resize itself if not attached to a Viewport of some type, which I think means your OrthographicCamera expands itself as necessary in your last message's code. I can see why you would want the tiny dimensions at least for the purpose of a grid. I believe Scene2D will not correctly behave with that sort of thing in relation to a Camera, though, because it will want something to already be X and Y large enough. I would personally set something up that will not depend on either a Camera or a Viewport. You might try using a background Image or similar for referencing size? I'm not sure what approach you would want for the grid itself.

I'm also not sure of an efficient way to store "tiles" of images or similar in a grid, but I think LibGDX's Array class might be better than Java's version for that. A single Array holding multiple rows of Actor, Image, or whatever you want might do the trick. I think it could maybe properly scale beyond the confines of an OrthographicCamera if you chose to make something like a world map, so that you could move the camera around to look at it. The issue would be figuring out first how to place an Array in an X and Y spot in relation to the Camera. Do you begin with an empty Image in the bottom left corner and replace it as it gets filled, so that you have something to reference for your initial X and Y placement?

https://libgdx.badlogicgames.com/ci/nig ... Array.html
shatterblast
 
Posts: 368
Joined: Sun Jul 06, 2014 1:14 pm

Re: How to make a scene camera a grid?

Postby tomski » Fri Aug 16, 2019 8:26 pm

Those values are fine.



Stage constructor needs a Viewport object.

Code: Select all
   stage= new Stage(new FitViewport(worldWidth, worldHeight));


Stage will then have its own camera with those settings. You can get a reference to that camera via stage.getViewport().getCamera()
tomski
 
Posts: 897
Joined: Wed Jun 26, 2013 6:06 pm

Re: How to make a scene camera a grid?

Postby TruePlayer » Sat Aug 17, 2019 1:23 am

great advice, tomski, everything really got great !! I will lay out here a working code for myself and descendants.
Code: Select all
public class SceneState extends GameState implements Screen {

    private Stage stage;
    private ParallaxForScene parallaxForScene;

    private float CAMERA_WIDTH;
    private float CAMERA_HEIGHT;
    private float ASPECT_RATIO;

    private Viewport viewPort;


    public SceneState(GameStateManager gsm){
        super(gsm);

        CAMERA_WIDTH = 10f;
        CAMERA_HEIGHT = 7f;
        ASPECT_RATIO = gsm.getWeight() / gsm.getHeight();

        this.camera.setToOrtho(true, CAMERA_WIDTH, CAMERA_WIDTH / ASPECT_RATIO);
        this.camera.position.set(new Vector3(CAMERA_WIDTH / 2f, (CAMERA_WIDTH / ASPECT_RATIO) / 2f, 0));
        this.camera.update();
    }

    @Override
    public void show() {
        viewPort = new FitViewport(CAMERA_WIDTH, CAMERA_HEIGHT);
        stage = new Stage(viewPort);
        parallaxForScene = new ParallaxForScene();
        stage.addActor(parallaxForScene);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.setProjectionMatrix(camera.combined);
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}


a new misfortune appeared - black stripes on the sides,
if I get the code above, then here is the result(BLACK COLOR TO THE TOP AND BOTTOM THE NORMAL; THE BLACK COLOR TO THE SIDE ):
Image



Of course, I tried to play with the settings, so for example, I tried to give the settings from the camera to the port:
Code: Select all
viewPort = new FitViewport(CAMERA_WIDTH, (CAMERA_WIDTH / ASPECT_RATIO));

too much does not appear on the screen:
Image


Tell me a technique that would solve this problem for me?
TruePlayer
 
Posts: 54
Joined: Sun Jul 28, 2019 12:22 pm

Re: How to make a scene camera a grid?

Postby TruePlayer » Sat Aug 17, 2019 1:40 am

I can draw a special picture where I will leave a lot of extra space on top, but how can I calculate this space for different screens?
or how to minimize this space as much as possible
Last edited by TruePlayer on Sat Aug 17, 2019 1:45 am, edited 1 time in total.
TruePlayer
 
Posts: 54
Joined: Sun Jul 28, 2019 12:22 pm

Re: How to make a scene camera a grid?

Postby tomski » Sat Aug 17, 2019 1:43 am

https://github.com/libgdx/libgdx/wiki/Viewports

Its expected behavior of the fit viewport. See others for behavior that you want.
tomski
 
Posts: 897
Joined: Wed Jun 26, 2013 6:06 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest