• Create Account

### #ActualFantasyVII

Posted 31 July 2012 - 08:31 AM

Hello

collision=false;
for(int i = 0; i< Map.CollisionPosition.Count; i++)
if (MousePosition * 32 == Map.CollisionPosition[i])
{
collision = true;
break;
}

Isn'it what you're trying to do ?

sir you are a genius .

just one last question. can you tell me why my for loop didn't work and yours did?

thank you so much

The second loop works because of the "break" statement. In your loop, you kept resetting collision to false when it found the next tile to check against. It will not return true unless the collision happened in the very last tile. The break statement tells the program to exit the loop, basically saying "we found a collision, looping further isn't necessary."

My idea is "I assume at first there is no collision, and then if I find any positive case in the loop, there is collision (and I can exit now the loop)"
The problem is that you set collision to false in your loop when you encounter a negative case, but it must be set to false once before the loop only.

thank you so much guys.

now I understand

### #1FantasyVII

Posted 31 July 2012 - 08:30 AM

Hello

collision=false;
for(int i = 0; i< Map.CollisionPosition.Count; i++)
if (MousePosition * 32 == Map.CollisionPosition[i])
{
collision = true;
break;
}

Isn'it what you're trying to do ?

sir you are a genius .

just one last question. can you tell me why my for loop didn't work and yours did?

thank you so much

The second loop works because of the "break" statement. In your loop, you kept resetting collision to false when it found the next tile to check against. It will not return true unless the collision happened in the very last tile. The break statement tells the program to exit the loop, basically saying "we found a collision, looping further isn't necessary."

thank you.

now I understand

PARTNERS