Ryan

Ryan

  • NA
  • 2
  • 0

All objects created in a class referance the same object?

Sep 9 2009 2:11 PM

I have a class (star) that I have tried every possibly way to store. I've used lists, arrays, naming individual items, but no matter what it seems whenever I use the collection of stars to draw them they all end up the exact same.

I'm not actually sure if they are all referencing the same object, or they all reference different objects with the exact same properties

The funny thing is that if I make a breaker as the items are being created and the list is being populated, they actually do end up different and seperate in the end... but if I just let it run normal then... well yeah

Has anyone had a problem similar? Or maybe my star class has an error?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing;
namespace Field
{
public class Star
{
public int twinkleUpDown { get; set; }
public int twinkleWait { get; set; }
public int twinkleAlpha { get; set; }
public int alpha { get; set; }
public bool isBig { get; set; }
public Point location { get; set; }
public fieldForm FieldForm { get; set; }
public int twinkleCount { get; set; }

public Star(fieldForm hold, Random random)
{
twinkleCount = 0;
FieldForm = hold;
random = new Random();
if (random.Next(3) == 1)
isBig = true;
twinkleUpDown = random.Next(10, 50);
twinkleWait = random.Next(20, 100);
alpha = random.Next(100, 255);
location = new Point(random.Next( 0 ,FieldForm.ClientSize.Width), random.Next(0, (FieldForm.ClientSize.Height / 2) - 2));
twinkleAlpha = alpha - 50;
}
}
}

Answers (1)