• ### Popular Now

• 9
• 9
• 10
• 10
• 9

This topic is 729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So the last few days I've just been kind of polishing my game - the reason I haven't really focused on mechanics and stuff is because I couldn't get past a certain problem.

A few days ago, I asked a question about rendering multiple bullets to the screen and a lot of you suggested I use ArrayLists. I tried a bunch of stuff, but that didn't exactly work (Note: I DO have prior knowledge of arraylists, so I'm not completely clueless XD).

What exactly is the FORMATTING for making it work? I know there isn't a single method of doing it, but I would like some kind of sample which demonstrates an efficient technique for adding the bullet object to the arraylist, creating a rectangle at the player's coords, etc.

I promise I'm not being lazy and asking for people to do it for me XD I tried all that I could but I ended up with the bullet restarting its position at the player's position whenever I press the trigger button, rather than a NEW bullet being created. I do know for a fact that my arraylist IS being updated, because I print out the size of it whenever I press the trigger button, and it updates.

I know this is vague, but a vague answer is kind of what I need. I just need the concept, or the formatting for how I would go about doing it.

Tl;dr : ArrayList being updated, but same bullet being reused.

Thanks to whomever replies! Means a lot :D Edited by Josh Petrie
Restored post body from history.

##### Share on other sites

Don't make us guess when you can provide information which will help us answer your questions.

By the sounds of things, you almost had this working -- I would suggest showing your code where you attempted to create a new bullet upon pressing the trigger button, and potentially also show where & how the bullets are being drawn and updated.

Also, this could have been a part of your earlier thread; there's not really a reason to create a new thread to continue the topic when the previous thread is still high up on the first page.

##### Share on other sites

Don't make us guess when you can provide information which will help us answer your questions.

By the sounds of things, you almost had this working -- I would suggest showing your code where you attempted to create a new bullet upon pressing the trigger button, and potentially also show where & how the bullets are being drawn and updated.

Also, this could have been a part of your earlier thread; there's not really a reason to create a new thread to continue the topic when the previous thread is still high up on the first page.

Oops, I'll go do that. Sorry!

##### Share on other sites

I will hazard a wild guess that maybe you're doing things such that when you create the new bullet and set its position near the player, you end up setting the position of the previously fired bullet to the same location.

##### Share on other sites

I will hazard a wild guess that maybe you're doing things such that when you create the new bullet and set its position near the player, you end up setting the position of the previously fired bullet to the same location.

How would I avoid doing that? It sounds logical but I'm not sure how I would be doing that...

##### Share on other sites

First, trace through your code and verify if that's what's actually happening. If you aren't aware, you can add some code like the following somewhere near your paint routine and place a breakpoint.

if (bulletsFiredCount >= 2 && spriteToPaint == bullet)
{
int asdf = 1;    //Place a break point here.
}


You want it somewhere that you can inspect the destination of the bullet sprite about to be painted. Check the destination of both bullets and if they're the same then you want to make sure that each bullet has its own separate set of current co-ordinates and that they're each used when painting the bullets.

##### Share on other sites

It sounds like your design is flawed. I may be misunderstanding your question, but where is the confusion? When you "pull the trigger", simply add another bullet object to your draw list(how ever you manage that) at pos x,y,z and go. Where is the confusion? How could you possibly be reusing the same bullet?