屏蔽多点触摸

前端之家收集整理的这篇文章主要介绍了屏蔽多点触摸前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

环境 cocos2d-x-3.1.1


ios版本

找到 AppController.mm

修改方法 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中


[eaglView setMultipleTouchEnabled: YES] 改成[eaglView setMultipleTouchEnabled: false]



android版本

找到

cocos2d-x\cocos\platform\android\java\src\org\cocos2dx\lib\Cocos2dxGLSurfaceView.java

方法 public boolean onTouchEvent(final MotionEvent pMotionEvent) 中添加两句

switch (pMotionEvent.getAction() & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_POINTER_DOWN:
				if (pointerNumber>1) return false;//add 屏蔽多点触摸
				final int indexPointerDown = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
				final int idPointerDown = pMotionEvent.getPointerId(indexPointerDown);
				final float xPointerDown = pMotionEvent.getX(indexPointerDown);
				final float yPointerDown = pMotionEvent.getY(indexPointerDown);

				this.queueEvent(new Runnable() {
					@Override
					public void run() {
						Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(idPointerDown,xPointerDown,yPointerDown);
					}
				});
				break;

			case MotionEvent.ACTION_DOWN:
				if (pointerNumber>1) return false;//add 屏蔽多点触摸
				// there are only one finger on the screen
				final int idDown = pMotionEvent.getPointerId(0);
				final float xDown = xs[0];
				final float yDown = ys[0];

				this.queueEvent(new Runnable() {
					@Override
					public void run() {
						Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(idDown,xDown,yDown);
					}
				});
				break;
原文链接:https://www.f2er.com/cocos2dx/342810.html

猜你在找的Cocos2d-x相关文章