Mayer
Mayer

Reputation: 25

Position changing after rotation processing

I am working on a tic-tac-toe game in my computer science class using processing-java. In my program, on the far right side I have a status bar that states which player's turn it is, who won, and who lost. This status bar is also placed vertically, so in my code I am rotating it and although it is rotating properly, it is causing another problem. The status bar appears in a certain area on the game screen, but after one X or O is placed, it moves spots and I am unsure of how to fix this. After another piece is placed, it moves a second time, then a third and then finalizes its place in an area I do not want it to be. This is my code regarding the text and rotation.

void updateStatus(String status) { // function to update the status message
  fill(0);
  rect(statusX, sbh, width, height-1);
  stroke(#FFFFFF);
  strokeWeight(4);
  line(statusX, sbh, statusX, screenH); // Status line
  fill(255);

  String fullStatus = "It is player "+status+"'s turn";
  //String fullStatus = "It is player X's turn";
  float statusTxtX = width*15/16, statusTxtY = height*2.5/7;

  pushMatrix();
  translate(statusTxtX, statusTxtY);
  rotate(HALF_PI);
  textSize(55);
  textFont(mainFont);
  text(fullStatus, 0, 0);
  //textDraw(status, mainFont, height, 255, CENTER, CENTER, statusX, height*3/12, width, height*1/2);
  popMatrix();
}

Upvotes: 1

Views: 71

Answers (1)

J.D.
J.D.

Reputation: 4561

The problem is with text-aligns. There is one in the placing() function and one in the textDraw() function. When you disable those the text stays in the same location. However, this will mess up the X's and O's, so you'll need to do some work on tracing where what text-align is set.

As a more general tip (since you're learning): put your first focus on functionality. You could for example build TicTacToe using println() and the numpad as input. When the game mechanics work you can add a nice user interface. Doing both at the same time often makes messy code that is prone to errors that are hard to debug. I bumped into that wall plenty of times myself ;)

Upvotes: 2

Related Questions