Author Topic: Problem with Collision in a list  (Read 1879 times)

0 Members and 1 Guest are viewing this topic.

Offline clckwrks666

  • Visitor
  • Join Date: Jul 2012
  • Posts: 1
  • Karma: 0
Problem with Collision in a list
« on: July 22, 2012, 06:52:17 PM »
Hi there,


Im trying to make a collision rectangle work with a list.

The specific chapter i am talking about is the one about angles and rotation with sprites.

I think its hour 7.

So here is the code :



 
Code: [Select]
planets = new List<Planet>();


           

            Planet planet = new Planet(Content, Batch);
            planet.Load("planet0");
            planet.velocity = 0.04f;
            planet.radius = 80;
            planet.angle = MathHelper.ToRadians(90);
            planets.Add(planet);

            planet = new Planet(Content, Batch);
            planet.Load("planet2");
            planet.velocity = 0.02f;
            planet.radius = 135;
            planet.angle = MathHelper.ToRadians(120);
            planets.Add(planet);

            planet = new Planet(Content, Batch);
            planet.Load("planet3");
            planet.velocity = 0.009f;
            planet.radius = 180;
            planet.angle = MathHelper.ToRadians(160);
            planets.Add(planet);


Every time i try to create a rectangle and pass in the planets.position values as well as the image width and height it throws back an error and wont let me


so i declare : Rectangle planetRectangle;


and then when i initalise i do planetRectangle = new Rectangle ( planet.position.X, planet.Position.Y, planet.image.Width, planet.image.Height);

it just does not want to pass the values onto the rectangle, how do i do collision with a list of objectS? Should i somehow create it in the base class or maybe in the sprite class?


Thank you




           

         



Offline twobitcoder

  • Administrator
  • -[ EPIC MEMBER ]-
  • *****
  • Join Date: Mar 2007
  • Posts: 4,926
  • Karma: 69
    • jharbour.com
  • Game: Adventure
  • Genre: RPG
  • Platform: Atari
  • Studio: Activision
Re: Problem with Collision in a list
« Reply #1 on: July 23, 2012, 05:35:57 PM »
If you're getting an exception error while trying to create a Rectangle, then I would guess the most likely cause is that the planet object is null (the object used to pass the dimensions of the rectangle).