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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:11:13+00:00 2026-06-08T07:11:13+00:00

Currently I am having static reference to all my sprites and loading and initializing

  • 0

Currently I am having static reference to all my sprites and loading and initializing them in my OnCreateResource mthod of SimpleBaseGameActivity, But now I have to override onAreaTouched listener on spirtes and the way I can override it while Initializing the Sprite. But I have a static method creating Atlas and Texture Region for every sprite. And I am using these sprites in my scene class and I want to override onAreaTouched there. I can registerTouchArea for that specific sprite in my scene so that can be done But I want to Override OnAreaTouched in a way so that Code reusability can be done.
Here is how I am currently creating and loading sprites.

defualtCageSprite = createAndLoadSimpleSprite("bg.png", this, 450, 444);

And this is my Method createAndLoadSimpleSprite.

public static Sprite createAndLoadSimpleSprite(String name,
        SimpleBaseGameActivity activity, int width, int height) {

    BitmapTextureAtlas atlasForBGSprite = new BitmapTextureAtlas(
            activity.getTextureManager(), width, height);
    TextureRegion backgroundSpriteTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(atlasForBGSprite, activity, name, 0, 0);
    Sprite sprite = new Sprite(0, 0, backgroundSpriteTextureRegion,
            activity.getVertexBufferObjectManager());
    activity.getTextureManager().loadTexture(atlasForBGSprite);

    return sprite;
}

Now How Can I override onAreaTouched for some sprites while not losing the code reusability.

  • 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-08T07:11:15+00:00Added an answer on June 8, 2026 at 7:11 am

    Is there any reason you need to load the textures at runtime? The normal way is to load the required textures all onto a single atlas while loading the application so that you can then quickly use them later.

    As for the code reusability, Todilo’s idea about enums seems to be pretty much what you need. Say for example that you have two kinds of objects – objects that disappear when you touch them and objects that fly up when you touch them. You enumerate both categories and put a piece of code into the touch event handling code that checks whether the object should disappear or fly up.

    If you don’t know what the objects should be doing on touch before running the application, there is a more dynamic way of achieving the same result. Just create two lists at runtime and put a reference to the object in one of the lists according to what the object should do when touched. Then in touch event handling do something like this:

    if (disappearList.contains(touchedObject)) {
        disappear(object)
    }
    if (flyUpList.contains(touchedObject)) {
        flyUp(object)
    }
    

    Too bad AndEngine does not allow users to set listeners on sprites, it would make things a bit easier.

    EDIT:
    Added explanation of the use of BlackPawnTextureBuilder:
    Your Atlas must be of type BuildableBitmapTextureAtlas, then you add all textures like this

    BitmapTextureAtlasTextureRegionFactory.createFromAsset(buildableAtlas, this, "image.png"));
    

    and after that

    try {
        this.buildableAtlas.build(new BlackPawnTextureBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(1));
    } catch (final TextureAtlasSourcePackingException e) {
        Debug.e(e);
    }
    

    I don’t know whether this will work for animated Sprites or not, you will have to try it.
    Also, there is no overriding onTouch, you will have to do that in the onAreaTouched method. One example of such condition is

    if (pSceneMotionEvent.getAction() == MotionEvent.ACTION_DOWN && disappearList.contains(pTouchArea)) {disappear();}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Currently I have a static class that I use as my logging module. I’ve
I am having problems in synchronising how my GUI will appear... Currently I have
Currently I have my code putting user input into a one-dimensional ArrayList, but I
I'm currently using nHibernate and having a problem where two objects loaded separately but
I currently have a solution with a couple of projects and one of them
I'm currently having a Class named SqlData, which contains all the Methods needed to
Currently I have an Array that is having 9 buttons pushed to it. This
im currently having troubles on my codes in C#. I want to split strings
I'm currently having problems to execute a command from a shell variable. In general

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.