So I am trying to generate a 5x5 grid with 2d array, but when I try to call render method that is responsible for size it does not work. Furthermore, I using rectangle boxes as my images in grid. They render really small.
package ksmd.tiles.Screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import ksmd.tiles.Tiles;
import ksmd.tiles.UI.Tile;
public class PlayScreen implements Screen {
private Tiles game;
//Texture texture;
private Tile[][] tile;
private float boardOffset;
private OrthographicCamera orthographicCamera;
public PlayScreen(Tiles game) {
this.game = game;
//texture = new Texture("badlogic.jpg");
tile = new Tile[5][5];
int tileSize = Tiles.WIDTH / tile[0].length;
boardOffset = (Tiles.HEIGHT - (tileSize * tile.length)) / 2;
for (int row = 0; row < tile.length; row++) {
for (int col = 0; col < tile[0].length; col++) {
tile[row][col] = new Tile(col * tileSize / 2, row * tileSize + boardOffset + tileSize / 2, tileSize, tileSize);
}
}
// orthographicCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
@Override
public void show() {
}
@Override
public void render(float delta) {
//game.batch.setProjectionMatrix(orthographicCamera.combined);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
for (int row = 0; row < tile.length; row++) {
for (int col = 0; col < tile[0].length; col++) {
tile[row][col].render(delta);
}
}
game.batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
package ksmd.tiles.UI;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import ksmd.tiles.Tiles;
public class Tile extends Box implements Screen {
private Tiles game;
private TextureRegion lit;
private TextureRegion dark;
private Sprite sprite;
private boolean selected;
public Tile(float x, float y, float width, float height) {
this.x = x;
this.y = y;
this.height = height -8;
this.width = width - 8;
lit = Tiles.res.getAtlas("pack").findRegion("lit");
dark = Tiles.res.getAtlas("pack").findRegion("dark");
}
@Override
public void show() {
}
@Override
public void render(float delta) {
game.batch.begin();
game.batch.draw(lit, x- width/ 2, y- height/ 2, width, height);
game.batch.end();
}
public TextureRegion getTextureRegion(){
return lit;
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
Basically I am new and not sure how to use render method to make the atlases bigger in grid. Sorry for bad english.