Mastering Java Swing
Create The Projectiles - STEP 2
ProjectilesNow, let’s add the ability to create and store projectiles in the game. We’ll save all projectiles in an array so we can manage and draw them later.
We need a way to store all the projectiles on the screen. For this, we’ll use an ArrayList. Here’s how to do it:
Add this line at the top of your class (as a member variable) to create the
projectileslist:private ArrayList<Rectangle> projectiles = new ArrayList<>();Don’t forget to import ArrayList at the very top of your file:
import java.util.ArrayList;
Members only
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 27 more lessons in Mastering Java Swing.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.