i use an iterator for the food2 because i had an error when i use the same template
well i dont initialize the position because i dont know how (i was thinking thats what i do when i add them with grow.
I was thinking the return position was fine, its work when my creatures eat it on the ground randomly.
what do you mean by ArrayList<PVector> ? and yes i surely mix some thing
Its not that it is wrong, it’s just that you don’t really need it. You need “getter” and “setter” function when your variables are private; and they should be to be compliant with the idea of encapsulation. In your case, the variable is public so you can access it directly without using a function.
You are not setting the position variable, you are adding a new PVector to your food2 arrayList. So your position variable stays undetermined.
I meant ArrayList<PVector> food2;. Something went wrong with the copy/pasting. I ask that because you have a class Food2 that should represent your food and that have a position. But there is also that list that seems to also be food but that is just PVector object and not Food2 object.
It seems odd but as long as it works for you. I would maybe try to rethink the design a bit though.
It seems that what you want is an array of Food2 in your word and the grow function should add Food to that array and not inside the Food2 object.