# Canvas Collision Map Problem

## Recommended Posts

I have two arrays, one of them is to display the tiles on a map and the other is to detect collision. At the moment I can't move my player at all and the colArray doesn't seem to be working properly. Would anyone mind taking a look at my code?

My colArray is the following (I've also included a fiddle below):

```
var colArray = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
];
var posiX = 0;
var posiY = 0;
for (var x = 0; x < colArray.length; x++) {
for (var y = 0; y < colArray[x].length; y++) {
if (colArray[i][j] === 0) {
}
if (colArray[i][j] == 1) {
\$('#player').stop(); // stop player from moving
}
posiX += 32;
}
posiX = 0;
posiY += 32;
}
}```

Thanks!

##### Share on other sites

You are using x-y in your for, and i-j to access the array.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.