I'm new to android programming and have some questions. I'm trying to create a tile puzzle game where I have to move squared tiles into a grid and the tiles would automatically clip onto place. For example, I have a 3x3 squared grid with 9 position. Each position measures 100x100 pixel. If I drag a tile(also 100x100 pixel) to any of the 9 positions inside the grid, the tile would automatically clip in place inside the 100x100 pixel area even if it's a bit off. How do I do this?
0
votes
One of my ideas is for each of the 9 area in the 3x3 grid(300x300pixel), I would have 9 points in the middle of each area((50,50) for 1st area, (150,50) for 2nd, (250,50)for 3rd, (50,150) for 4th, .... , (250,250) for 9th). For my tile, I have a position of it in the center of my tile. When I drag my tile inside the grid and let go, it would calculate the distance between my tile and the 9 points inside the tile. For the closest position, set the position my tile equal to that position(which clips my tile into the 100x100 area). I think this is a bad way to do it cause it's not efficient.
– iamarnold