Weird behavior with mousePressed on Android Mode

edited January 2017 in Android Mode

I have the following code in my sketch to detect swiping movement on the screen so I can move the game character accordingly:

  if(mouseXPrevious != -1) {
    xSpeed = mouseX - mouseXPrevious;
  mouseXPrevious = mouseX;
else if(mouseXPrevious != -1){
  xSpeed = 0;
  mouseXPrevious = -1;

The code works and runs just fine on my Moto X Play (android 6.0.1), but when I tested the game on my old HTC One X (running android 4.2.2) it seemed that only half of the presses go through. When it did go through though, the character kept moving along with my finger as long as I held my finger on the screen. On the next touch, again nothing. On another try: It works again.

I've never ran into this problem on my main phone(the Motorola). What could be causing this?



  • edited January 2017

    I created a new sketch just to test this. The whole code is as follows:

    void setup(){
    void draw(){
      if(mousePressed) {
        ellipse(mouseX, mouseY, 200, 200);

    This also works perfectly on my Motorola, but on the HTC it registers only half the time when i press on the screen. Is this a problem with Processing or am I missing something?

    edit. Tried to work around this by writing the following functions and using the new boolean in draw but it had no effect (this too works perfectly on my newer phone):

    void mousePressed() {
      mouseIsPressed = true;
    void mouseReleased() {
      mouseIsPressed = false;

    Seems like the app just completely misses some of the press events

  • @Sayid=== not any problem with nexus tablet (6.0) and Xperia Z (5.1) it seems that it is a problem with your "old" device Perhaps you can try to set + your screen sensitivity???

  • The device's touch screen works just fine anywhere else in the system and doesn't miss any clicks. This happens only in the Processing app.

  • Answer ✓

    @Sayid=== In the Motionevent class (android) that Processing wraps each input event (button, touch, mouse...) when it is fired retains a millis() param in order to know what it is: simple tap or click, double tap, long pressed and so on; that means that if your sensitivity settings are not those expected some events cannot be captured.

    In the doc from android you can read:::

    Consistency Guarantees Motion events are always delivered to views as a consistent stream of events. What constitutes a consistent stream varies depending on the type of device. For touch events, consistency implies that pointers go down one at a time, move around as a group and then go up one at a time or are canceled.

    While the framework tries to deliver consistent streams of motion events to views, it cannot guarantee it. Some events may be dropped or modified by containing views in the application before they are delivered thereby making the stream of events inconsistent. Views should always be prepared to handle ACTION_CANCEL and should tolerate anomalous situations such as receiving a new ACTION_DOWN without first having received an ACTION_UP for the prior gesture.

  • Okay that must be it. Thank you akenaton!

Sign In or Register to comment.