ccsprite touch 事件
请问问下,为啥我的精灵无法移动?请指教。代码上传了。程序代码:
// // GoodsSprite.m // Copyright 2012年 __MyCompanyName__. All rights reserved. // #import "GoodsSprite.h" @implementation GoodsSprite -(id)init { if(self=[super init]) { GoodsArray=[[CCArray alloc]initWithCapacity:40]; CCSprite *weapon=[CCSprite spriteWithFile:@"weapon.png"]; weapon.scale=0.46f; [GoodsArray addObject:weapon]; CCSprite *clothes=[CCSprite spriteWithFile:@"clothes.png"]; clothes.scale=0.46f; [GoodsArray addObject:clothes]; CGSize size = [[CCDirector sharedDirector] winSize]; float x=205,y=size.height-70; for(int i=0;i<2;i++) { x+=50; CCSprite *temp=[CCSprite node]; temp=[GoodsArray objectAtIndex:i]; temp.position=ccp(x, y); [self addChild:temp z:0 tag:101+i]; } } return self; } +(id)GoodsSpriteWithRect:(CGRect)rect spriteManager:(CCSprite *)manager { id rtn = [[[self alloc] initWithTexture:manager.texture rect:rect] autorelease]; return rtn; } -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if(![self containsTouchLocation:touch]) { return NO; } return YES; } -(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint touchPoint = [touch locationInView:[touch view]]; touchPoint = [[CCDirector sharedDirector] convertToUI:CGPointMake(touchPoint.x, touchPoint.y)]; self.position = CGPointMake(touchPoint.x, touchPoint.y); } -(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { } -(void)onEnter { [[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES]; [super onEnter]; } -(void)onExit { [[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES]; [super onExit]; } -(CGRect)rect { return CGRectMake(-rect_.size.width / 2, -rect_.size.height / 2, rect_.size.width, rect_.size.height); } -(BOOL)containsTouchLocation:(UITouch *)touch { return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]); } -(void)dealloc { [super dealloc]; } @end
[attach]65347[/attach]
[ 本帖最后由 qq236533067 于 2012-10-22 16:14 编辑 ]