关于cocos2dx多点触控的问题

本文档详细介绍了如何在Cocos2dx中启用多点触控功能。对于iOS平台,需要手动设置多点触控开关;而对于Android平台,多点触控默认即为开启状态。此外,还提供了iOS平台上实现多点触控的具体代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cocos2dx官网上对多点触控模式的说明

h1. How to Enable Multi-Touch 

如何开启多点触控?

Many people ask me how to enable multi-touch in cocos2d-x, so I write a document here. 

许多人询问如何开启cocos2dx的多点触控,所以我写了这篇文档。

Multi-touch feature is available in both ios & android port since the first version of cocos2d-x. But in iOS, apple turns the switcher off by default, and offers an API to enable it manually. 

从cocos2dx的第一个版本就有了多点触控特征,ios和android的设备都有多点触控。但是ios的框架中默认是关闭的。

h2. ios

苹果设备

Please refer to cocos2d-x/tests/test.ios/Classes/testsAppDelegate.mm, line 39 

请参考cocos2d-x/tests/test.ios/Classes/testsAppDelegate.mm, line 39 

 [__glView setMultipleTouchEnabled:YES] 

When you have a project created by xcode cocos2d-x templates, you can modify this file MyGame/ios/AppController.mm as below 

当你创建了一个xcode cocos2dx模板,你可以将MyGame/ios/AppController.mm 修改成一下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

// Override point for customization after application launch. 

// Add the view controller's view to the window and display. 

window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 

EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] 

pixelFormat: kEAGLColorFormatRGBA8 

depthFormat: GL_DEPTH_COMPONENT16_OES 

preserveBackbuffer: NO 

sharegroup: nil 

multiSampling: NO 

numberOfSamples: 0 ]; 

[__glView setMultipletouchEnabled:YES]; // enable multi-touch here!! It's at about line 37 

// ... 

return YES; 


"Apple Apple official document about setMultipletouchEnabled is here": 

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/setMultipleTouchEnabled: 

上面的地址是苹果关于多点触控的官方文件。

h2. Android 

安卓设备

On android, the multi-touch is open by default. You don't need to open anything before get the touch coordinates in void MyLayer::ccTouchesBegan/Moved/Ended 

安卓上,默认是开启的,你不需要任何修改。

h2. Other platforms 

People usually debug cocos2d-x games on windows desktop system. But sadly, there's no multi-touch support on windows. You had to connect your mobile phones and test multi-touch feature on them. 

window平台没有多点触控。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值