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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:49+00:00 2026-06-18T03:16:49+00:00

I’m using a class that extends GenericPool to handle getting and recycling of sprites.

  • 0

I’m using a class that extends GenericPool to handle getting and recycling of sprites. What I’d like to do is have a method in that class to recycle after a certain duration. Something like:

public void recyleIn(Sprite sprite, float durationSeconds) {}

And there’s a handy/dandy DelayModifier that seems like the proper way to implement it. So we’d have something like the following:

public void recyleIn(MySprite mySprite, float durationSeconds) {
    mySprite.registerEntityModifier(
            new DelayModifier(
                    durationSeconds,

    new IEntityModifierListener() {

        @Override
        public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {

        }

        @Override
        public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
            recycle(mySprite);
        }
    }

    ));
}

Now here’s the problem: I can’t call the recycle() method or do the recycling right there unless the Sprite is “final”. Ordinarily that wouldn’t be a problem, I’d just make a “final” deepcopy and use that. But in this case, making a copy defeats the original purpose of recycling in a pool. (E.g., if I’m just going to make a copy anyway, why bother to recycle and use pooling in the first place?)

Any ideas on the proper approach/model for this sort of thing? Thanks in advance.


UPDATE:

Umm.. I just realized I could just use the IEntity parameter in the onModifierFinished() method. (I’m used to ignoring those parameters for some reason.) So I could do something like this within the onModifierFinished():

recycle((MySprite) pItem);

I’d still be curious on anyone’s thoughts on the best approach, but I think I may have just missed the obvious here.

  • 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-18T03:16:50+00:00Added an answer on June 18, 2026 at 3:16 am

    I’m going to go ahead and answer my own question to help those in this situation. The short answer is that it’s proper to use the IEntity parameter rather than an object outside it. The second issue I ran into when doing this is that I wanted to detach the IEntity from the scene in this method but, in AndEngine, it’s important that when an IEntity is detached from the scene it must happen in the UpdateThread–otherwise you have a chance of errors as the scene is drawing while something is being removed from it. The end result looks like this:

            @Override
            public void onModifierFinished(IModifier<IEntity> pModifier, final IEntity pItem) {
                pool.getContext().runOnUpdateThread(new Runnable() {
                    @Override
                    public void run() {
                        pItem.detachSelf();
                    }
                });
    
            }
    

    One other small but important point is the “final” modifier on the Ientity parameter–necessary so that it can be called within the run() thread.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I have thousands of HTML files to process using Groovy/Java and I need to

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.