Separate objects in an ArrayList

i find it a little difficult to see through your code. apparently there is a class lurking in the back that takes care of when the first object has been moved. So you leave out the important part: what does you code actually do when its time to create a new object and thus a new entry in your list.

i assume that you will probably need to store the position of each object somewhere.
if it is a class, you will store the x,y coordinates in that object itself.

so the process would look something like this:

  1. create a new object at 100, 100.

  2. move the object to a new location
    -> when the object is placed (mouseRelease)
    a) update the coordinates of THIS object to the new coordinates
    b) create a new instance of the object at 100,100 by adding it to the ArrayList
    c) object count += 1

  3. repeat from step 2

Maybe you’re not updating each objects x,y values ?

As you seem to use the reference example for ArrayList I also notice that you do not declare the list by specifying its intended content:

ArrayList tegenstanders; should maybe be: ArrayList '<'Tegenstander> tegenstanders
(the ‘<’ is there so the editor here doesn’t think its a code :wink: its of course <)
same goes for saying tegenstanders = new ArrayList(); in setup():

personally I would not name the arrayList so similar to your class name, its confusing…

2 Likes