I’m using Java2D for a small basic game I started a while ago. I have an enemy class that draws and moves a rectangle. The thing is, I don’t want to make a ton of enemies using:
Enemy e1 = new Enemy; Enemy e2 = new Enemy;
and so on. I’m not too good with ArrayLists so bare with me. I used:
private ArrayList <Enemy> e;
to create the arraylist of enemies. In my
init()
or initialization method I used:
ArrayList <Enemy> e = new ArrayList();
e.add(0, null);
e.add(1, null);
to initialize and add enemies. null is the type of enemy that is never defined. The problem may lay with that but in rendering method I used:
e.draw(g);
which obviously gave an error. How do I call a method from an arraylist’s class.
I tried researching some arraylists help which was good but not what I needed