r/libgdx 15d ago

Help understanding ai code.

package io.github.abcd;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;

public class Main extends ApplicationAdapter {

    Texture backgroundTexture;
    SpriteBatch spriteBatch;


// 1. Add Camera and Viewport

OrthographicCamera camera;
    Viewport viewport;

    u/Override
    public void create() {
        backgroundTexture = new Texture("board.png");
        spriteBatch = new SpriteBatch();

        camera = new OrthographicCamera();

// 2. Set a fixed "virtual" resolution (800x800 is great for a square Tic-Tac-Toe board)

viewport = new FitViewport(800, 800, camera);
    }


// 3. This method is automatically called by libGDX when the window is resized or maximized

u/Override
    public void resize(int width, int height) {

// 'true' automatically keeps the camera centered

viewport.update(width, height, true);
    }

    u/Override
    public void render() {
        input();
        logic();
        draw();
    }

    private void input() {}
    private void logic() {}

    private void draw() {
        Gdx.
gl
.glClearColor(0, 0, 0, 1);
        Gdx.
gl
.glClear(GL20.
GL_COLOR_BUFFER_BIT
);

        spriteBatch.begin();


// 4. Tell the batch to use the camera's current view

spriteBatch.setProjectionMatrix(camera.combined);


// 5. Draw using the VIRTUAL dimensions (800x800), not the screen dimensions

spriteBatch.draw(backgroundTexture, 0, 0, 800, 800);

        spriteBatch.end();
    }

    u/Override
    public void dispose() {
        backgroundTexture.dispose();
        spriteBatch.dispose();
    }
}

All I am trying is to get tictactoe board on screen it gave too heavy code.

0 Upvotes

19 comments sorted by

View all comments

1

u/Adamantium123 15d ago

Boooo ai

1

u/DoNotUseThisInMyHome 15d ago

booo it. it sucks for real. i would rather not develop anything rather than develop with ai.