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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:15:05+00:00 2026-06-06T21:15:05+00:00

Hi Everyone, in the game I develop with AndEngine, there are a lot of

  • 0

Hi Everyone,

in the game I develop with AndEngine, there are a lot of sprites running around. Now every of this sprites has a TouchArea registered to the scene, because I display some informations about the sprite when it is touched. The Scene itself has a OnSceneTouchListener that I use for moving the camera around and to zoom.

My problem is, that every time the user moves the camera (by touching the display somewhere and moving his finger around) the OnAreaTouched() method of any sprite, that is accidentally under the finger, gets called, when the movement is finished (finger gets lifted). I already limited the triggering events to event.getAction()==UP (before it was a real mess of called touchAreas) but this is not enough. If the user is zooming or moving the camera, the sprites touchAreas should not be activated.

Is there any way I can distinguish between an OnAreaTouched-event and an OnSceneTouched-event? Which one is called first and can I suppress the other?

This is my OnSceneTouched() method (simplified):

public boolean onSceneTouchEvent(Scene scene, final TouchEvent event) {
    boolean isZooming = event.getMotionEvent().getPointerCount() >= 2;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // REMEMBER FIRST TOUCHPOINT, TO KNOW IN WHICH DIRECTION TO MOVE
        this.touchPoint = new Point(event.getMotionEvent().getX(), event.getMotionEvent().getY());  
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        if (isZooming) {
            // DO SOME ZOOM STUFF
        } else {
            // DO SOME MOVEMENT STUFF
        }
        return true;
    }

OK, actually this is not very interesting – but as you can see I always return true to signal that the touch event was handled. Still the OnAreaTouched() gets called

This is a typical OnAreaTouched() Method of a sprite:

public boolean onAreaTouched(final TouchEvent touchEvent, float touchAreaLocalX, float touchAreaLocalY) {
    if (touchEvent.getAction() == TouchEvent.ACTION_UP) {
          // DISPLAY INFORMATION ABOUT THE SPRITE
          return true;
    }
    return false;
}

You see, there is nothing special to it. So I hope someone can help me out here to find a solution how to suppress the OnAreaTouch-event when the OnSceneTouch-event should be used. Maybe I can somehow catch the event.getAction()==UP in the OnSceneTouched()-Method??

I hope I could explain the problem good enough for you to understand (sorry, it’s not that easy for me : ). Any help is much appreciated, and thank you for you time!

regards
Christoph

edit:

After experimenting with MahdeTo’s suggestion to tag the event somehow I found out the following:

  • the TouchEvent that triggers the OnSceneTouchEvent() Method is not the same as the one triggering the OnAreaTouched() Method.
  • OnAreaTouched() gets called 20 ms later than OnSceneTouchEvent()
  • the event calling OnAreaTouched() starts actually when the user puts his finger down on the display (than he moves it around and the OnSceneTouchEvent() gets called multiple times), when he then lifts his finger the first event stops and gets handled. (I tried it out by measuring the time)

So I came up with the solution to measure how long a touch event lasted. If the event is longer than 200 ms, I guess the user wanted not to simply click but move or zoom (because these actions usually take longer). So now the OnAreaTouched() method gets only called when someone really meant to click and not accidentally swiped over the area.

but it’s still not a good solution and I would really appreciate if anyone knows more about controlling such events.

thank you

  • 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-06T21:15:06+00:00Added an answer on June 6, 2026 at 9:15 pm

    I have recently written a fairly complicated application using touch controls – pressing buttons on the screen, pinch zooming, rotating and moving objects with two fingers and more. What I ended up doing was iteratively improving the application and adding rules controlling how to respond to different combinations of touch events. Whenever something was wrong, I recorded the sequence of TouchEvents and added rules so that the misbehaving action was handled.

    You can also create boolean switches that prevent the onAreaTouched to execute, just add a condition that, for example if you want to touch an object, checks whether doNotTouchObject is true or false.

    Another thing I found useful were touch mode switchers. I wrote several methods that completely change the behavior when user touches the screen. I believe you can switch them on the go, so it should be possible to call scene.setOnAreaTouchListener(touchListener) while you are touching the screen.

    Since un/registering touch areas is blazing fast, simply unregistering certain touch areas while you perform some action is a possibility. After the action is completed, reregister them again.

    I used a combination of all of the above and it works rather well, but it is essential to keep the code clean, otherwise debugging or implementing new features will be a pain.

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

Sidebar

Related Questions

Good day everyone, I'm an independent game developer who has, in the past, primarily
everyone. This is a piece of code from using sqlite in android tutorial: return
Everyone, every blog is talking about HTML 5 and giving solution to use HTML
everyone! new to here and been pondering about this myself for some times with
I'm working on this game titled Fortress, located at http://www.joemajewski.com/fortress . Anyways, it's one
This is about me being stressed by playing the game type a command and
I have a logical statement that says If everyone plays the game, we will
everyone, I made a shooting game just like 1942(classic shooting game),but here's the question,
So I'm working on a game and I need to draw a lot of
Hello everyone I am interested in Java game programming, but I want to do

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.