cocoa-touch – 在数组cocos2d`中获取精灵的位置
发布时间:2020-12-14 18:58:25 所属栏目:百科 来源:网络整理
导读:我需要能够触摸数组中的特定移动精灵并对其执行操作.但是,当我执行MoveTo操作时,精灵位置不会更新.救命! 阵: int numbreds = 7;redBirds = [[CCArray alloc] initWithCapacity: numbreds];for( int i = 1; i=numbreds; i++){ int xvalue = ((-50*i) + 320)
我需要能够触摸数组中的特定移动精灵并对其执行操作.但是,当我执行MoveTo操作时,精灵位置不会更新.救命!
阵: int numbreds = 7; redBirds = [[CCArray alloc] initWithCapacity: numbreds]; for( int i = 1; i<=numbreds; i++){ int xvalue = ((-50*i) + 320); int yvalue= 160; if (i==4) { CCSprite *parrot = [CCSprite spriteWithFile:@"taco.png"]; [birdLayer addChild:parrot]; [self movement]; //the action that moves the array horizontally parrot.position = ccp(xvalue,yvalue); parrot.tag=100; 触摸 -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:[touch view]]; location = [[CCDirector sharedDirector] convertToGL:location]; CCSprite *mark = (CCSprite *)[birdLayer getChildByTag:100]; if (CGRectContainsPoint([mark boundingBox],location)) { CCLOG(@"YAY!"); } 问题是CCSprite的位置实际上没有更新或移动.好极了!仅在精灵的原点位置生成. 解决方法
试试这个:
CCSprite *temp = [CCSprite spriteWithFile:@"taco.png"]; temp = [birdLayer getChildByTag:100]; if (temp.position.x == location.x) { // do stuff... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |