A
A
Artem Chebotarev2015-12-14 19:32:47
Game development
Artem Chebotarev, 2015-12-14 19:32:47

What is the best way to implement a projectile in a Space Invaders clone?

Good day!
I am writing a clone of Space Invaders (learning Java) for myself. I can't think of a better way to implement projectiles on the screen so that the garbage collector handles them correctly.
From what I came up with, this is to make three arrays of the Bullets class and when one of them is full (the number of bullets is 15, for example), we clear the next one and start filling it, etc. But, as for me, it is not very rational and cumbersome.
Can you please suggest the best way to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-12-14
@Derik117

As an option, a pool of shells.
1 array of shells of the same type, size - according to the maximum number of shells on the screen (it is always limited). Create projectiles for the entire array at once, use them as needed, display the flight of the projectile, and after "working" (collision with an obstacle or exiting the screen) mark as ready for reuse. We get rid of the creation of unnecessary objects during the game. You have to kill them only between levels.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question