1. 关于Touch
http://www.cocos2d-iphone.org/wiki/doku.php/tips:touchdelegates
两种touch模式:standard touch delegate 和 targeted touch delegate, 各自的协议分别如下:
@protocol CCStandardTouchDelegate <NSObject>
@optional
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
@end
@protocol CCTargetedTouchDelegate <NSObject>
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
@optional
// touch updates:
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event;
@end
区别在于:
1. 后者的touchbegan需要返回一个BOOL;
2. 后者是单点触摸模式,而前者支持多点触摸。
3. 开启方式不同
前者启动方式为:
self.isTouchEnabled = YES;
后者启动方式为:
-(void) registerWithTouchDispatcher
{
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
当用户想在非CCLayer的类(或子类)中使用这两个接口时,有两件事情需要做:
1. 该类实现 CCTargetedTouchDelegate 或CCStandardTouchDelegate接口;
2. 在进入该类的(onEnter)的时候注册这些接口,在退出该类的时候(onExit)的时候注销这些接口。
//FOR StandardDelegate
- (void)onEnter
{
[[[CCDirector sharedDirector] touchDispatcher] addStandardDelegate:self priority:0];
[super onEnter];
}
//for targeted delegate
- (void)onEnter
{
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
退出时候:
- (void)onExit
{
[[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
[super onExit];
}
2. CCBezierBy 和 CCBezierTo
http://blog.csdn.net/we000636/article/details/8616355