When I write my code inside touchDragged
method to allow the player dragg with any one of these following directions:
( up, down, right, left, up-right, up-left, down-right, down-left )
My code:
public void touchDragged(InputEvent event, float x, float y, int pointer) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
Image img = img[i][j];
float imgX = img[i][j].getX();
float imgY = img[i][j].getY();
float width = img[i][j].getWidth();
float height = img[i][j].getHeight();
if (x > imgX && x <= imgX + width && y > imgY && y <= imgY + height) {
img.setColor(Color.RED);
}
}
}
});
The result: (When the player draggs in up-right
direction)
But How can I prevent below squares that contains X
to listen the touch event? because I know the player want to go this direction up-right
.
Do I calculate first the slope of straight line linear equation then according to the slope I determine the direction? or what?
Any Idea ??