1 Reply Latest reply on Mar 24, 2012 10:41 AM by john16384

    What layout will allow me to make a grid AND will let me get coordinates?

      I originally (as per my previous thread) tried to use a GridPane to make a X by Y grid of squares with borders (so that i can see the individual grid squares). But I couldn't figure out how to make my grid automatically size it's squares to fit within my window, no matter how many grid squares were used to make the grid. It always went out of bounds of the window.

      I found a workaround later to just scale my grid by X depending on how var out of bounds it was. It was a poor implementation.

      More importantly, I need to be able to also get the coordinates of a specific column. I didn't see any method in GridPane that allowed me to return the coordinates of a element or column.

      I'm thinking I need to design my implementation differently. Is there a layout that will allow me to get the coordinates of a specific column in the grid? I'm making a ConnectFour-like game for Android for fun. I want to make my grid, and be able to 'drop' a png image down a column. To animate the png dropping using javafx, I need to have the coordinates I believe.

      I invisioned it to look like this:

      Edited by: 922630 on Mar 23, 2012 3:56 PM
        • 1. Re: What layout will allow me to make a grid AND will let me get coordinates?
          I donot think you need the coordinates. I would implement it something like this:

          - Use TilePane or GridPane for the grid, and put somekind of clickable control inside it -- ImageView will work for this, but perhaps a Button is better
          - When you detect the click, you can determine which grid cell that was; using the size of the Pane divided by the number of cells it is high, you can find the height of an individual cell, let's say 100 pixels
          - Now to animate the coin being dropped in, simply put the correct picture in the cell as if it appears there instantly... but also start a Timeline. This timeline will change the TranslateY property from -100 * number_of_cells_to_drop to 0. This will make it seem that the coin is dropped in from the top.

          Good luck