We are about to switch to a new forum software. Until then we have removed the registration on this forum.
You will have to track multiple touches using the touches array. Not done it myself yet ... there is a basic example on the Android mode website
http://android.processing.org/reference/multitouch/touches.html
In addition to a minimal full code example (MCVE), could you say a bit more about the problem?
but I am not seeing the changes as expected on mobile
What does this mean? Do you mean that nothing at all happens? Or are there multitouch problems? Do events start but not stop? Be more specific.
...ok. Without knowing how you attempted to implement multitouch, it is hard to give you further advice.
What do you want to happen when touching both the left and right side?
i have faced the same problem... as this project have not been updated since 3 or 4 years ago, it's not working with processing 3. simple answers would be to : 1-use processing 2.2.1 (download it from processing website) 2-use other multitouch libraries...
Hi akenaton! Yes, i need the possibility to control more then one in the same time, actually i use mouse structure, and in android there is always only one possibility per time. How can i obtain the possibility to have multitouch?
@chanof===
sorry, i dont understand what you want: rewriting this for android touchEvent is very simple but what is the "multitouch"???
Hi there, past days with the special help of this forum i archive some tools such toggle and button, i need it for multitouch purpose on android, i understand that mouse parameter are not correct for multitouch, i already read what there is on processing android site but i phish to obtain a little help to convert this class for android multi touch purpose. Thanks a lot
class Toggle {
boolean state;
boolean ready;
boolean blink;
int x, y, w, h, delta; // x,y,w,h
Toggle(int ix, int iy, int iw, int ih) {
blink = false;
state = false;
ready = true;
x = ix;
y = iy;
w = iw;
h = ih;
}
void draw() {
if(blink == true){delta = 32;} else {delta = 0;}
if ( mousePressed ) {
if (ready && mouseX >= x && mouseX <= (x+w) && mouseY >= y && mouseY <= (y+h) ) {
ready = false;
state = !state;
}
} else {
ready = true;
}
fill(63+delta);
if (state) {
fill(127+delta);
}
rect(x, y, w, h);
}
}
Thanks for support! i understand the question about ready for to be hit! But now i which to obtain a multitouch compatibility for android, i already read what there is about on the site, but i need a help to convert my classes, but i will open a post for it into android mode, Thanks!
@xna -- to search the forum for example code and discussion relating to p5.js multitouch, search for the touches[]
array, which contains an updated list of multiple touch points.
Dunno much about multitouch. This is p5.js' event section:
https://p5js.org/reference/#group-Events
Here is my first p5.js project, it's an on-screen keyboard that plays samples: https://github.com/mxa/tinykeys
The sound is crackling on some browsers, while it plays fine in others. I have a couple of questions, but maybe it's better to ask them one at a time.
How can I make this multitouch? i am looking at the reference of touch()
, but is there an example of its usage somewhere?
(And yes, the interaction model is a core part of every version of Processing. In addition to mouse and keyboard p5.js has touches[]
for multitouch support.)
However, if your goal is to write game code once and then run it on the web, Android, and iPhone, Processing is not the best tool for you right now.
Processing is currently. "write code for the web in p5.js JavaScript, write related but different code in Android mode or deploy a JavaScript mobile app wrapper of your p5.js code using a third-party system, and write hypothetical but different (largely undocumented) code for iPhone, or just don't get it working on iPhone." If you want one build button and three targets this won't do that.
I'm a big Processing fan, but if your goal is cross-platform mobile deployment of simple 2D games then I'd recommend one of the many popular platforms designed specifically for that:
https://www.google.com/search?q=cross+platform+mobile+game+development
If your goal is to let your students edit the games they play to learn about programming then Processing and Scratch are highly relevant -- particularly in a desktop context.
The reference on the multitouch API in Processing is available online at:
http://android.processing.org/reference/multitouch/touches.html
You may find the touch events relevant as well:
http://android.processing.org/reference/multitouch/events.html
For the full reference on the Android-specific API in Processing, go to the following page:
@Ruan_fc===
The requested URL /reference/multitouch/touches.html] was not found on this server.
as for your question for multitouch you have to use the motion event class from android and pointers indexes. see here
I want to get some information about the tool called "Touches array" showed in this example: [android.processing.org/reference/multitouch/touches.html]. Other informations about the reference for Android 4.0+ are also welcome.
Well, you could convert it into p5.js, which is supports multitouch natively.
Hi, I have developed this app but would like to have it online. Apparently, SMT is not supported any more, so do you have any ideas on how to convert my Processing code int processing.js? So far, I have only read this article http://dm.ncl.ac.uk/adrianpark/2012/02/07/processing-js-multitouch-magic-finger-tips/ but I have to convert lots of lines of code. Do you think I have any other better option? Many thanks
For reference, see also past discussions of multitouch -- https://forum.processing.org/two/search?Search=MultiTouch
I have been messing with this for a few days now, and I have something that is working very close to what I want. I know the code could be structured better, but I am just trying to get the hang of the Multi touch workflow. If you run the sketch you will see that you can use as many fingers as you want and drag out multiple lines... that part works fine... I THOUGHT that would be the hard part of this. If you look at the code you will see 2 commented out sections, this is what adds the balls to the sketch. For some reason this part of the code is causing the sketch to crash randomly. It may work for a little while, but after repeated fast shots it will eventually crash (and I need it to be solid). I am testing this on a galaxy s7... if anyone could take a look at the code and test it that would be great. I cant figure out what is making it crash... its made my head hurt for the past 2 days.
import android.view.MotionEvent;
HashMap<Integer, Line> lh;
ArrayList<Ball> balls;
void setup() {
fullScreen(P2D);
lh = new HashMap<Integer, Line>(10);
balls = new ArrayList<Ball>() ;
}
void draw() {
background(255);
for (int i = 0; i <lh.size(); i++) {
Line l = lh.get(i);
if ( l != null) {
l.show();
}
}
for (int i = balls.size()-1; i>=0; i--) {
Ball tempb = balls.get(i);
if (tempb.pos.x > width || tempb.pos.x <0 || tempb.pos.y > height || tempb.pos.y< 0) {
balls.remove(i);
}
}
for (Ball b : balls) {
b.show();
}
}
public boolean surfaceTouchEvent(MotionEvent ev) {
int maskedAction = ev.getActionMasked();
switch (maskedAction) {
case MotionEvent.ACTION_DOWN:
{
Line templ = new Line((int)ev.getX(), (int)ev.getY());
lh.put(ev.getPointerId(0), templ);
break;
}
case MotionEvent.ACTION_POINTER_DOWN:
{
int pointerIndex = ev.getActionIndex();
int pointerId = ev.getPointerId(pointerIndex);
Line templ = new Line((int)ev.getX(pointerIndex), (int)ev.getY(pointerIndex));
lh.put(pointerId, templ);
break;
}
case MotionEvent.ACTION_MOVE:
{
for ( int i = 0; i < ev.getPointerCount(); i ++) {
int id = ev.getPointerId(i);
Line templ = lh.get(id);
if (templ!=null) {
templ.mx = (int)ev.getX(i);
templ.my = (int)ev.getY(i);
}
}
break;
}
case MotionEvent.ACTION_UP:
{
int pointerIndex = ev.getActionIndex();
int j = ev.getPointerId(pointerIndex);
//Line l = lh.get(j);
//PVector p = new PVector(ev.getX(pointerIndex), ev.getY(pointerIndex));
//PVector op = new PVector (l.sx, l.sy);
//PVector v = PVector.sub(op, p);
//v.normalize();
//v.setMag(20);
//balls.add(new Ball(p, v));
lh.put(j, null);
break;
}
case MotionEvent.ACTION_POINTER_UP:
{
int pointerIndex = ev.getActionIndex();
int j = ev.getPointerId(pointerIndex);
//Line l = lh.get(j);
//PVector p = new PVector(ev.getX(pointerIndex), ev.getY(pointerIndex));
//PVector op = new PVector (l.sx, l.sy);
//PVector v = PVector.sub(op, p);
//v.normalize();
//v.setMag(20);
//balls.add(new Ball(p, v));
lh.put(j, null);
break;
}
}
return super.surfaceTouchEvent(ev);
}
class Ball {
PVector pos;
PVector vel;
Ball(PVector _pos, PVector _vel) {
pos = _pos.get();
vel = _vel.get();
}
void show () {
fill(20);
noStroke();
pos.add(vel);
ellipse(pos.x, pos.y, 50, 50);
}
}
class Line {
int sx, sy, mx, my;
Line(int _x, int _y) {
sx=_x;
sy=_y;
mx=_x;
my=_y;
}
void show( ) {
stroke(0);
strokeWeight(10);
line( sx, sy, mx, my);
}
}
I'm trying to create a multitouch interface for multiple people to play a snake style game, I want them to be able to hold down the button, and then on release the snake would stop turning.
I've gotten so far as to make it turn when you tap the button, but I can't seem to get the touch Event right from the touchEnded function, because the event that gets passed through has already removed the touch from the touches[] array.
Any suggestions?
EDIT:
I managed to get it to work by comparing the 'which' in the touchStarted e to the touchEnded e.changedTouches[(whichfromtouchStarted)]