Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualstitchs

Posted 18 October 2012 - 01:03 PM

Hello community,

|------------------------------------------------------------SOLVED------------------------------------------------------------|

Language: C++, Library: Allegro 4, Game: Tic-Tac-Toe

As the title suggests I am having a small issue with Pixel-to-Grid location. I understand the whole concept whereby to find the Grid Square that you are in you divide the Pixel by the Square-size and store it in an Integer, so that the result rounds down to the Grid coordinate.

My problem is that I recently offset the start corner of my Grid by adding a UI bar at the top of the game screen. My Grid has X and Y coordinates which are 0 and 48 respectively. Due to this, when I click on a square to place a shape, if I go too far near the lower edge of the game window, I receive a 'Vector subscript out of range' error. If I click in the UI bar it counts as a valid placement for one of the top three squares.

I thought I had the solution when I adjusted the Grid2Pixel calculation to take this offset into account, but this produces the same error. I debugged and found that it would find the Grid Square that the mouse clicked in ((0,1) for arguments sake), and then add the offset of 48 making the Grid Square location (0,49) - erroneous.

My question is, how do I take this offset into account, so that if I click in the UI it does not lead to a shape being placed and, if I click on the lower edge of the window, an error is not produced.

I hope I have provided enough information, please feel free to ask if anymore is needed?

Regards,

Stitchs.

#1stitchs

Posted 16 October 2012 - 10:50 AM

Hello community,

Language: C++, Library: Allegro 4, Game: Tic-Tac-Toe

As the title suggests I am having a small issue with Pixel-to-Grid location. I understand the whole concept whereby to find the Grid Square that you are in you divide the Pixel by the Square-size and store it in an Integer, so that the result rounds down to the Grid coordinate.

My problem is that I recently offset the start corner of my Grid by adding a UI bar at the top of the game screen. My Grid has X and Y coordinates which are 0 and 48 respectively. Due to this, when I click on a square to place a shape, if I go too far near the lower edge of the game window, I receive a 'Vector subscript out of range' error. If I click in the UI bar it counts as a valid placement for one of the top three squares.

I thought I had the solution when I adjusted the Grid2Pixel calculation to take this offset into account, but this produces the same error. I debugged and found that it would find the Grid Square that the mouse clicked in ((0,1) for arguments sake), and then add the offset of 48 making the Grid Square location (0,49) - erroneous.

My question is, how do I take this offset into account, so that if I click in the UI it does not lead to a shape being placed and, if I click on the lower edge of the window, an error is not produced.

I hope I have provided enough information, please feel free to ask if anymore is needed?

Regards,

Stitchs.

PARTNERS