I am having much difficulty trying to figure out how to draw the cross in the square of where the person just touched.
I have made a class called 'CellPositions', by making 9 invisible squares around my board Texture; Example of CellOne...
public CellOne cellOne;
public CellPositions(Board board) {
load(board);
}
public void load (Board board) {
cellOne = new CellOne(board);
}
public class CellOne {
public Rectangle square = new Rectangle();
public CellOne (Board board) {
square.x = board.boardRect.x;
square.y = (board.boardRect.y + board.boardRect.height) - (board.boardRect.height / 3);
square.width = board.boardRect.width / 3;
square.height = board.boardRect.height / 3;
}
}
I have made a 'Controller' class to handle my input and a 'Renderer' class to handle rendering images to the game.
What I want to do is draw the "Cross" on the square the person touched. For eg. if he/she touches the first square - cellOne - how would i render my "cross" to that specific square.
I've tried making a class called "Cross" and made the x and y coordinates Gdx.input.getX() and Gdx.input.getY(), but the 'cross' was not in the square, but intersecting the lines.
Please help! I am trying to get used to libGdx by making a simple game like tic-tac-toe, but it's really not so simple when trying to draw your cross on a certain square.
Here is my board class for further info
private TextureRegion reg;
public Rectangle boardRect;
public Board () {
init();
}
private void init () {
reg = Assets.instance.board.boardRegion;
boardRect = new Rectangle();
boardRect.set((Constants.SCREEN_WIDTH / 2) - (340 / 2), 15,
340, 340);
}
public void render (SpriteBatch batch) {
batch.draw(reg, boardRect.x, boardRect.y,
boardRect.width, boardRect.height);
}
I have made my screen width and height be 480x480.