Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:06:12+00:00 2026-05-28T03:06:12+00:00

im making a simple android game at the moment and was wondering how i

  • 0

im making a simple android game at the moment and was wondering how i can optimize my Enemy spawner, or if i dont have to.

At the moment, i just want to spawn enemies, more as the level goes on. The Game is nothin fancy, just one screen with – i would guess – max. 20 at a time on it.

So my approach is:

ArrayList<Enemy> enemies = new ArrayList(); 

I have an ArrayList where i will store all my spawned enemies (from the same class).
Now in the main update function i have the following:

  for (Enemy en : enemies){
        en.update();
    }

This would be for the position-update, now i maybe have to run a second time through the cycle to determine wich of the enemies can be deleted, because it is destroyed.

Is this the most common and effective way for a simple game?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:06:13+00:00Added an answer on May 28, 2026 at 3:06 am

    Try adding a property to the enemy called “dead” or “disposed”.
    So you can keep track of which enemies needs to be released doing:

    for (Enemy en : enemies)
    {
        if (en.isDead() == true)
        {
            // Remove en from enemies. 
            // You'll probably need to use a "for" here keeping track of the last 
            // element when deleting one. So you can continue checking/updating 
            // enemies.
            continue;
        }
        en.update();
    }
    

    You can add effects to if you don’t want it to simply “dissapear” from the screen:

    for (Enemy en : enemies)
    {
        if (en.isDead() == true)
        {
            en.startFadeOut();
        }
        else if (en.isFadeFinished())
        {
            // guessing some alpha channel property.
            en.setAlpha(en.getAlpha() - 0.1 * ticks);
            if (en.getAlpha() <= 0)
            {
                en.setFadeFinished(true);
            }
        }
        en.update();
    }
    

    of course you’ll need to put this logic inside the update of enemy class. This is just an idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple Android game written in Java. I have my activity... public
I am also new to Java and Android Development, been making a simple game
I'm making a simple 2d game for the android platform, which works perfectly from
I am making a football game for Android. I have a class Player. Player
I'm making an Android game, and I want to use a custom font for
For a project I am making a simple RPG turn based game in Android.
I am new to android development, making a simple game and using onKeyDown(.....) function
I'm making a simple fractal viewing app for Android, just for fun. I'm also
I'm making a simple drawing app on Android. I'm using the FingerPaint.java provided with
I am new to android developement. I am making a simple expense management program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.