Note that there are some explanatory texts on larger screens.

plurals
  1. POfor-in-loop/ Condition Is only used for the first element of the a List
    text
    copied!<p>I have searched for three days and didn't find a solution, Here is the code:</p> <pre><code>if (keyboardState.IsKeyDown(Keys.Right)) { for (int i = GlobalClass.BlocksPositions.Count - 1; i &gt; 0; i--) { if (new Rectangle((int)GlobalClass.BlocksPositions[i].X, (int)GlobalClass.BlocksPositions[i].Y, bT.Width, bT.Height).Intersects(new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height))) { c = 0; } else { c = 1; } } if (c == 1) { Position.X += Speed; } } </code></pre> <p>Each Block position equals a block that I can create by clicking on the screen, the new block position is then put in the List. Basically I have a list of blocks Coordinates in my BlockPosition List. Then I pass the condition for each blockposition, the Condition Create A rectangle for each BlockPosition and one for the Player... if there's a collision, the player won't move in that direction. When I try the code, My character will Collide only with the first element of the List and not the others, if I delete the first element it will then collide with the next one but not the others. All the variables are FINE I know it because I tried to replace this code by something like this:</p> <pre><code>if (keyboardState.IsKeyDown(Keys.Right)) { for (int i = GlobalClass.BlocksPositions.Count - 1; i &gt; 0; i--) { if (new Rectangle((int)GlobalClass.BlocksPositions[i].X, (int)GlobalClass.BlocksPositions[i].Y, bT.Width, bT.Height).Intersects(new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height))) { GlobalClass.BlocksPositions.RemoveAt[i]; } } } </code></pre> <p>Same thing but here if it collides I delete the Element of the List, it's the same condition but when I try it it will detect all of the elements and delete the ones that I touch. I tried the foreach function and I get the same Results. What's wrong? I already do a lot of things with does variables So I'm sure the problem don't come from their values but with what I do with them. Help please! (:</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload