Arrays in objects

edited February 2018 in How To...

So I am making somekind of game that you have airplanes shooting meteorites. But I need some help with Array in objects to add and remove that meteorite object in my array. And i'm using the "class" function.

Answers

  • Well, does each plane need to keep track of it's own set of meteorites?

    Or would it just be best to have some planes and some meteorites?

    The difference is this:

    class Plane {
      Meteorite[] my_meteorites;
      // ...
    }
    
    class Meteorite {
      // ...
    }
    
    Plane[] planes;
    

    vs this:

    class Plane {
      // ...
    }
    
    class Meteorite {
      // ...
    }
    
    Plane[] planes;
    Meteorite[] meteorites;
    
  • Also, since you will be adding and removing things from your Array of objects, I wouldn't use an Array at all! Instead, I suggest you use and ArrayList!

  • edited February 2018

    Let's end this discussion, as there is actual code in your other discussion.

    https://forum.processing.org/two/discussion/26464/objects-in-arrays

This discussion has been closed.