it still returns true and thinks that it's on the same tile as the player was on (400, 300).
How do you know it thinks that? How are you testing to see if it's still true?
I'm using the same information you have given me regarding this collision.
The information I gave you was to detect which tile the origin of the sprite was in (so you could work out whether it was supposed to collide or not). For the actual collision detection, you would need to test the boundary boxes for the sprite against the tiles' boundary boxes.
The only way for it to return true is through the if statement provided; I have run the program and even though the player is not at the tile BUT is on the same horizontal axis as the tile, it returns true.
This is what I've concluded from testing, using the coordinates of the player:
Test 1: Where x = 168, y = 228 --> NO collision;
Test 2: Where x = 100, y = 332 --> collision; (this co-ordinate is located to the LEFT of the tile, outside thereof)
Test 3: Where x = 374, y = 320 --> collision; (this co-ordinate is located within the tile)
Test 4: Where x = 740, y = 308 --> collision; (this co-ordinate is located to the RIGHT of the tile, outside thereof)
As you can see, the outlier y value concludes that there is something wrong with the y value in collision detection. I have used the information you gave me to work out which tile the sprite was in, but what's interesting is that in all those three collision detections, REGARDLESS of what's being shown on screen; the tileNumber returns 2. In collision tests 2, 3 and 4: tileNumber returns 2, even though in collision tests 2 and 4 were OUTSIDE the tile. I don't think this is a problem with the actual collisions detection, but rather in how the program is interpreting which tile is which. So far, it only happens to tile numbers 2 and 3 and a collision test on both tiles returns true regardless of where we are on the horizontal axis.
I think a problem lies in this line of code:
float tileNo = (gridPosition.y * gridSize.x) + gridPosition.x;