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 9320793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:43:28+00:00 2026-06-19T03:43:28+00:00

I am trying to make a simple game using libgdx. One thing that I

  • 0

I am trying to make a simple game using libgdx. One thing that I am stuck with is making enemies spawn at specific times. If I do something like

if (t == 10) 
    new Enemy();

I might miss this specific time or maybe spawn the same enemy twice. What I have right now is something like

float t = 0
float timeElapsed = 0;

update (float delta) {
    timeElapsed += getDeltaTime();
    if (timeElapsed > 0.1) {
        t++;
        timeElapsed = 0;
    }
}

This gives me the approximate elapsed time in tenths of seconds for t, but it really doesn’t feel like the way I should be doing this.

  • 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-06-19T03:43:30+00:00Added an answer on June 19, 2026 at 3:43 am

    I have a solution I use in my games that might be useful. I actually created a Timer class:

    public class Timer
    {
        protected float remaining;
        protected float interval;
    
        public Timer(float interval)
        {
            this.interval = interval;
            this.remaining = interval;
        }
    
        public boolean hasTimeElapsed() { return (remaining < 0.0F); }
    
        public void reset() { remaining = interval; }
    
        public void reset(float interval) {
            this.interval = interval;
            this.remaining = interval;
        }
    
        public void update(float delta) { remaining -= delta; }
    }
    

    You initialize the Timer to a certain time period, then in your update(delta) method you call Timer.update(delta) on all your Timers, then check if any of the timers have elapsed by calling Timer.hasTimeElapsed().

    In your case, you only need one Timer object, since the enemies are spawned in sequence. Once you spawn an enemy, you reset the Timer (changing the spawn period if you want) and wait for it to go off again.

    You can also modify the Timer object to use the subject-observer pattern in order to trigger callbacks when a timer goes off. This is useful if you have logic that needs to know when a timed event occurs, but the logic does not have direct access to the delta time.

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

Sidebar

Related Questions

Trying to make simple minesweeper game in python, but have one problem. I have
I'm trying to make a simple 2D game using SFML and this tutorial. Here's
I am trying to make a simple pong game using opengl-es. I have checked
I am trying to make a simple item database using MySQL for a game.
I'm trying to make a simple windows 8 metro game using c# and xaml.
I'm trying to make a simple 2d game in OpenGL ES 2 using marmalde
I am trying to make a simple game using HTML 5, CSS, and JQuery.
I am trying to make a simple skateboarding game using AndEngine and the Box2D
I'm trying to make a simple multiplayer game using canvas, socket.io and node.js. Everything's
I am trying to make a simple game engine but I got stuck at

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.