Hi Friends,

I seem to be having problems with some sprites in my game. The number of them isn't the same from level to level, so I have created an ArrayList of these sprites to get a variable number of them.

Now, simply for some testing purposes (I'm not yet at the point that I am going to program their behavior) I am trying to get one to move on a keypress. However, it keeps freezing the program, and I realized that you don't access ArrayList members the same way that you do an Array.

I mean, if it were an Array, it would be no problem to make one move with


However, when calling the same function from an ArrayList,


I'm actually creating another intstance of that sprite. Which is what I believe it the source of the problem.

So, how can I get a member of an ArrayList to do something, without copying said member?


9 Years
Discussion Span
Last Post by Ezzaral

You don't mention the language, but if it's Java then using arraylist.get(i).move(); as you have it there will move that instance in the list. It will not create a copy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.