Determining Click Position of 2D perspective board

Started by
0 comments, last by clb 12 years, 6 months ago
Hey all,

I'm messing around with Flash and making a little chess game. I need to determine which box on the board the user has clicked on so that I can move pieces around. I've thought of two possible solutions to this.

1) Treat each box on the board as an individual sprite and add a click event listener to each box.

2) Based on the dimensions of the board and the mouse coordinates, use a bit of math to determine what box the mouse is over.

I'm thinking number 2 is a better solution then to have 64 (8X8) individual sprites with individual event listeners. The problem I'm facing is that the board is a perspective board, meaning to achieve the illusion of depth the dimensions of the board are warped.

It seems like the perspective illusion is accomplished by each column of the board having a unique slope to it, the leftmost column has the steepest negative slope while the center column has a slope of 1 and the rightmost column has the highest positive slope.

Anyone have any suggestions on how to tackle this problem?
Thanks!
Advertisement

It seems like the perspective illusion is accomplished by each column of the board having a unique slope to it, the leftmost column has the steepest negative slope while the center column has a slope of 1 and the rightmost column has the highest positive slope.


To me this sounds like you are using some "hand-created" algorithm that mimics proper 3D perspective projection.

I would try to represent that 3D->2D mapping as perspective projection. Perhaps something similar to this. After you have written down the perspective projection mapping, you can invert that mapping to produce the point on the original perspective-skewed rectangle.

This topic is closed to new replies.

Advertisement