Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

XNA array problem

$
0
0

Hi everyone, so there is this problem I have, and I dont know why it is happening.

 

So first off I made a class called Entity and I made entites array(images) with 2 elemetns Entity entites = new Entity[2] in my game1.cs, I also made collision detection system.

So now In my Game1.cs class in Update() method I call a Collision() method, and a Collision() method goes like this:

private void Collision()
        {
            entites[0].CollisionWithPlayer(player.playerRectangle);
            entites[1].CollisionWithPlayer(player.playerRectangle);
        }

now when I run the game, Collision is not applied to entites[0], it is applied just to enitites[1], BUT

private void Collision()
{
entites[1].CollisionWithPlayer(player.playerRectangle); // now enitites[1] is first and 0 is second, reversed as in code above
entites[0].CollisionWithPlayer(player.playerRectangle);
}

Note that I have switched Array Indexes, And now when I build it and run the game, Collision is not applied to entites[1], it is applied just to enitites[0].

 

Why is that so, how can that be? How to fix this?

 

Thanks in advanced :/

 

Oh btw, here is my Coliision method in Entity Class, if it would be of any importance:

public void CollisionWithPlayer(Rectangle playerRectangle)
        {
            if (blablabla)
            {
                CanGoBot = false;
            }
            else CanGoBot = true;


            if (blablabla)
            {
                CanGoTop = false;
            }
            else CanGoTop = true;

            if (blablabla)
            {
                CanGoRight = false;
            }
            else CanGoRight = true;


            if (blablabla)
            {
                CanGoLeft = false;
            }
            else CanGoLeft = true;

        }

Viewing all articles
Browse latest Browse all 17560

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>