Need Help About ArrayList of Sprites ?

Reply

Join Date: Apr 2009
Posts: 6
Reputation: jaypaul is an unknown quantity at this point 
Solved Threads: 0
jaypaul jaypaul is offline Offline
Newbie Poster

Need Help About ArrayList of Sprites ?

 
0
  #1
May 18th, 2009
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

array[i].move();

However, when calling the same function from an ArrayList,

arraylist.get(i).move();

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?

Thanks
Jay
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,445
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Need Help About ArrayList of Sprites ?

 
0
  #2
May 18th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC