让精灵也响应cctouch

代码如下

这里需要添加协义

CCTargetedTouchDelegate

#import <Foundation/Foundation.h>
#import "cocos2d.h"
typedef enum { 
    CardTypeHearts = 1,
    CardTypeSpades = 2,
    CardTypeBox=3,
    CardTypeFlower=4,
    CardTypeKingBig=5,
    CardTypeKingSmall=6
} CardType;

typedef enum { 
    CardSizeTypeBig = 1,
    CardSizeTypeSmall = 2,
    CardSizeTypeIn=3
} CardSizeType;
@interface Card : CCSprite <CCTargetedTouchDelegate>{
    NSInteger _size;
    CardType _type;
    ccColor3B _ccColor3B;
    CardSizeType _cardSizeType;
    
    Boolean _isTouchDray;
    
    CCSprite *cardTypeCCSprite;
    CCSprite *cardSize;
    CCSprite *cardTypeCCSprite1;
    CCSprite *cardSize1;
}
@property(assign)NSInteger size;
@property(assign)CardType type;
@property(assign)Boolean isTouchDray;
-(id)initPoker:(CardType)cardType PokerSize:(NSInteger)pokerSize CardSizeType:(CardSizeType)pokerType;
-(void)LoadSizeType :(CardType)cardType PokerSize:(NSInteger)pokerSize;
-(id)initWithBackgroundSpriteFrameNameBig;
-(id)initWithBackgroundSpriteFrameNameIn;
-(id)initWithBackgroundSpriteFrameNameSmall;
-(void)actionTouchDray;
-(void)actionTouchDrop;
@end


然后在实现在文件里

-(void)onEnter
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
	[super onEnter];
}

-(void)onExit
{
	[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
	[super onExit];
}

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
//       CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
//    touchoffset=touchLocation;
    return YES;
}
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
    NSLog(@"%f  ,%f",touchLocation.x,touchLocation.y);
}
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
    NSLog(@"%f  ,%f",touchLocation.x,touchLocation.y);
}

onEnter   运行在init  这前
onExit


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值