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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:53:53+00:00 2026-06-19T01:53:53+00:00

I am working on a fantasy game in AndEngine. I have created tiles dynamically

  • 0

I am working on a fantasy game in AndEngine. I have created tiles dynamically (matrix format) and I placed a sprite on one of the tiles. I used onAreatouchlistener for identifying the sprites, I give a zvalue 0 for tiles and for sprite 1, but onAreaTouchListener does not identify the sprite, it only identifies the tiles. I want to know both values, when user touch on particular location. Please suggest a solution.

Here’s some sample code in use:

public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea,
        final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
    if (pSceneTouchEvent.isActionDown()) {
        final Sprite face = (Sprite) pTouchArea;

        String mrc = (String) face.getUserData();

        if (mrc.equals("48")) {
            selectedtlie = true;
            inittileLevel(level1);
        } else
            Toast.makeText(this, "" + mrc, Toast.LENGTH_SHORT).show();

        i++;

        if (i == 2)
            return true;
        else
            return false;
    }
    if (pSceneTouchEvent.isActionUp()) {
        i = 0;
        return true;
    }
    return true;
}
  • 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-19T01:53:55+00:00Added an answer on June 19, 2026 at 1:53 am

    There are a couple different things you might be asking. Your question is a little difficult to interpret, but I’ll try to go possible interpretation by possible interpretation.

    Checking if Sprites are at Same Location

    How do I identify if two sprites are placed in the same location when
    their zindex values are different in AndEngine?

    That’s your subject line. I think you’re asking something a little different, but if that’s all you’re asking, you can just compare the X’s and Y’s and ignore the Z’s, like this:

    if (sprite1.getX() == sprite2.getX() && sprite1.getX() == sprit2.getY()) return true;
    

    Checking if Sprites are Overlapping

    Of course, you might mean something different by “same location” than just whether the top left corner is placed at the same point. For example, you might want to know if the two sprites are overlapping at all, regardless of whether they are precisely placed at the same XY. In that case you want to get into collision detection and there is more than one way to handle collisions (e.g., do you want pixel perfect collision testing?). In any event, here’s a nice example of detecting pixel-perfect collisions. If you want to do something simpler you could just get the bounding box Rect for each sprite and use the intersect() method in android.graphics.Rect.

    Handling Touch Events

    The body of your question asks the following, where you seem to be getting at something different:

    I used onAreatouchlistener for identifying the sprites, I give a
    zvalue 0 for tiles and for sprite 1, but onAreaTouchListener does not
    identify the sprite, it only identifies the tiles. I want to know both
    values, when user touch on particular location

    Now I’m confused, because onAreaTouchListener does not “identify sprites,” it listens for touchevents. My guess is that what you’re asking for is a way to use touchEvents to both a sprite and another sprite underneath it.

    Register TouchAreas

    First: Make sure you’re registering the handlers for both sprites. I.e., something like:

    this.mScene.registerTouchArea(sprite);
    

    Use the Boolean Returned by OnTouch()

    If the touchevent isn’t being propagated through, another thing to look at is the boolean returned by onTouch(). That boolean is used to indicate whether the handler has consumed the event or if it should be passed through.

    Check Touch Traversal Order

    You might also play around with scene.setOnAreaTouchTraversalFrontToBack() and scene.setOnAreaTouchTraversalBackToFront() to see if they’re both receiving touch events and the issue is propagation through or if the issue is you haven’t registered the handler on one of the sprites.

    Check AreaBinding

    Finally, take a look at scene.setTouchAreaBindingEnabled(true). You mentioned in the comments you were having problem with the “TouchUp” event in particular. This might be the result of having touchareabinding set to false. Essentially what toucharea binding does is it allows the touch area to look at and receive touch events outside its toucharea. So if a finger goes down inside the area and goes up outside (and binding is off) it will not receive the touch up event. If binding is on, it will still receive the touch event.

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

Sidebar

Related Questions

I have a fantasy football league rails app that was working last year and
I'm currently working on a Final Fantasy like game, and I'm at the point
I am programming a fantasy pet game. Currently, I am working on a tool
I have an application I am working on for a fantasy football site. If
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working on game where plates will be falling from top to bottom. Some plates
I have a mostly-working piece of code to read a directory, output each folder
Working with SSRS and a SQL 2000 source, I have a stored procedure that
Working through more book examples- this one is a partial poker program- This segment

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.