sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Multi-touch issue #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I can't get multi touch to work.
ccTouchesBegan is only called with first touch and not the other.
event.getPointerId(event.getActionIndex()) is always returning 0.

How can i get to managed multi-touch with cocos2d android?

Thank you.

Original issue reported on code.google.com by vcarl...@gmail.com on 13 Feb 2011 at 5:32

GoogleCodeExporter commented 8 years ago
I am currently adding this feature. ccTouchesBegan would be called when 
ACTION_POINTER_DOWN and ccTouchesEnd with ACTION_POINTER_UP. I'll push this as 
soon as possible with addTargetedDelegate.

Original comment by opengen...@gmail.com on 14 Feb 2011 at 3:59

GoogleCodeExporter commented 8 years ago
Nice! And ccTouchesMoved too?
Thank you.

Original comment by vcarl...@gmail.com on 14 Feb 2011 at 4:05

GoogleCodeExporter commented 8 years ago
OK I managed to use your last version with multitouch but i had to make a 
change in your code in CCTouchDispatcher.java line 353.
It seems than due to api level7 you can not use getActionMasked (and 
getActionIndex as well), the getAction() you use returns a full action code 
that needs to be masked (action value = 261 or 262 for pointer 2):

int actionCode = event.getAction() & MotionEvent.ACTION_MASK;
switch(actionCode) {...

The code i got from GitHub swith directly on event.getAction() which cause some 
strange behavior (due to egality between some action mask ACTION_POINTER_1_UP = 
6 = ACTION_POINTER_UP), or does not manage event at all.

In order to retrieve pointer id it needs to use a mask too for bit shift:
action = event.getAction();
action >> MotionEvent.ACTION_POINTER_ID_SHIFT; // pid

Is this normal for you (i think it is due to api level)?
Is it possible to go to api 2.2 or you want to avoid to do so.

Thanks.

Original comment by vcarl...@gmail.com on 14 Feb 2011 at 10:33

GoogleCodeExporter commented 8 years ago
And mouse coordinate must be get with event.getX(pId)

Original comment by vcarl...@gmail.com on 14 Feb 2011 at 11:23

GoogleCodeExporter commented 8 years ago
Thank you for feedback) I don't have device with multitouch (Sony Ericsson has 
dissapointed me with its updates, and my X8 now has no 2.2, neither 
dual-touch). I'll include action masking.

Original comment by opengen...@gmail.com on 15 Feb 2011 at 9:49

GoogleCodeExporter commented 8 years ago
OK, for me it's working well with your last code version.

Original comment by vcarl...@gmail.com on 16 Feb 2011 at 9:29

GoogleCodeExporter commented 8 years ago

Original comment by opengen...@gmail.com on 18 Feb 2011 at 12:23

GoogleCodeExporter commented 8 years ago
Hello,

I am struggling with multi-touch functionality can you please assest me. i am 
using android os 2.2 and cocos2d 99.5 , in my code i am using two classes for 
two images like joysticks. its working only one at a time. can you please 
assest me with sameple code.
Thanks in Advance

Satish

Original comment by satish....@gmail.com on 21 May 2011 at 1:30

GoogleCodeExporter commented 8 years ago
I can't get multi touch to work in ccTouchesMoved(). It seems to work correctly 
in ccTouchesBegan(), but in ccTouchesMoved() I get only event from 
ActionIndex=0.

It's my fault or is it a bug?

Attached is the code of my Layer.

Original comment by leinardi on 14 Jul 2011 at 8:29

Attachments:

GoogleCodeExporter commented 8 years ago
Ok, solved: in the function ccTouchesMoved() you must handle an array of touch 
and not a single touch:

    @Override
    public boolean ccTouchesMoved(MotionEvent event) {
        int pointCnt = event.getPointerCount();
        for (int i = 0; i < pointCnt; i++) {
            CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(i),event.getY(i)));
            Log.d(TAG, String.format("move %d=(%f,%f)", i, location.x, location.y));
        }
        return super.ccTouchesMoved(event);
    }

Original comment by leinardi on 19 Jul 2011 at 4:10