0
\$\begingroup\$

This question is an exact duplicate of:

Hi I am making a java game in were you can build land. At the moment you can build but not destroy. So I want to be able to destroy. I have an array of the tiles. I think I might need to do something like remove the tile that the mouse is hovering on form he arraylist so how can I do this? I don't think you need my code to explain to me because I only want to know how to remove the Tile that the mouse is hovering over. Please help me.

EDIT** MY array is a arraylist kind of arraylist and I have an arraylist for each block.

\$\endgroup\$

marked as duplicate by MichaelHouse Dec 14 '13 at 16:09

This question was marked as an exact duplicate of an existing question.

0
\$\begingroup\$

If you have an linear array which stores tiles, you can easily find the current tile by taking the mouse position and dividing it by the dimensions of your world.

So bascily like this :
int2 iTilePos = MousePos.XY / int2( TerrainWidth, TerrainHeight );
int index = iTilePos.Y * TerrainWidth + iTilePos.x;

What happens here is that you are dividing the mouse position down to the size of the world, and from there you just map it linearly. Since the amount of Y steps equals one full Width. And finaly adding the last steps in the current width. ( which in this case would be the iTilePos.X)

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.