【Cocos2D学习】基本概念理解

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




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值