TouchScreens and mousereleased()


#1

When using a mouse and keyboard this code works fine and draws like it is supposed to, but when using a touchscreen and taking my finger off of the screen, the mouseReleased() function never seems to get called.

color c=color(252,41,41);
int x, y, xp, yp;
int strokeW=1,flag=0;
void setup()
{
  //size(1280, 720);
  fullScreen();
  background(0);
}
void draw()
{
  noStroke();
  fill(c);
  rect(0, 0, 30, 30);
  stroke(c);
  strokeWeight(strokeW);
  if(flag==1){
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}
 
void mouseDragged() {
  flag=1;
}
void mouseReleased(){
  flag=0;
}
 
 
void keyPressed() {
  if (key == 'c')  
    background(0);
    flag = 0;
  if (key == CODED) {
    if (keyCode == UP) strokeW++; 
    if (keyCode == DOWN) strokeW--;
  }
  if (strokeW<0)strokeW=1;
  if(key== ' ') c = color(random(0,255),random(0,255),random(0,255));
}

I don’t know if this is Processing or my touchscreen, but I need help resolving this issue.


#2

I mostly fixed the problem by setting the flag to 0 if the mouse’s position 6 frames ago is the same as its position on this frame, as I intend to only use this personally, it shouldn’t be a big deal.

color c=color(252,41,41);
int x, y, xp, yp;
int strokeW=1,flag=0;
int px;
int pmx2,pmx3,pmx4,pmx5,pmx6;
void setup()
{
  //size(1280, 720);
  fullScreen();
  background(0);
}
void draw() {
  if(pmx6 == pmouseX) {
    flag=0;
  }
  pmx6 = pmx5;
  pmx5 = pmx4;
  pmx4 = pmx3;
  pmx3 = pmx2;
pmx2 = pmouseX;
  noStroke();
  fill(c);
  rect(0, 0, 30, 30);
  stroke(c);
  strokeWeight(strokeW);
  if(flag==1 && pmouseX > 0){
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}
 
void mouseDragged() {
  flag=1;
}
void mouseReleased(){
  flag=0;
}
 
 
void keyPressed() {
  if (key == 'c')  
    background(0);
    flag = 0;
  if (key == CODED) {
    if (keyCode == UP) strokeW++; 
    if (keyCode == DOWN) strokeW--;
  }
  if (strokeW<0)strokeW=1;
  if(key== ' ') c = color(random(0,255),random(0,255),random(0,255));
}

#3