What am I doing wrong?
say I have a small simple map array like this… (not actual size)
map_array = [ [0,0,0], [0,0,0], [1,1,1] ]
at each 0 is empty space. At each 1, a tile is blitted.
First we find out where our player is in comparison to the map_array by doing this…
player.yToMap = Math.abs(mapHolder.y - player.y); player.xToMap = Math.abs(mapHolder.x - player.x); player.yToTiles = Math.round((mapHolder.height - player.yToMap)/25); player.xToTiles = Math.round((mapHolder.width - player.xToMap)/25);
each tile is 25×25;
now I just want to find the index of the tile hes about to collide with. So that hopefully I can plugin the x,y,width,height of that object.
I tried using getObjectUnderPoint, and using player.?toTiles + direction.
However I can’t get it to feed me an index. I tried using indexOf along with it.
I may not even be approaching this correctly altogether, I simply want to fix my collisions. They work fine… almost
while(j < ground_a.length){
solveCollision(j);
findTOC();
j++;
}
Except the obvious fact that a while statement searching through every single last tile is very redundant and since its in a loop function itself, will apply multiple collisions at once and move the player farther back than it should. (collisions are done axis-aligned bounding box style).