请咨询: Cocos2d。我有一个数组CCSprite:
movableSprites = [[NSMutableArray alloc] init];
NSArray *images = [NSArray arrayWithObjects:@"bird.png", @"cat.png", @"dog.png", @"turtle.png", nil];
for(int i = 0; i < images.count; ++i) {
NSString *image = [images objectAtIndex:i];
CCSprite *sprite = [CCSprite spriteWithFile:image];
float offsetFraction = ((float)(i+1))/(images.count+1);
sprite.position = ccp(winSize.width*offsetFraction, winSize.height/2);
[self addChild:sprite];
[movableSprites addObject:sprite];
}创建数组的克隆: MovableSprites2。第二个数组被添加到场景中。我有一个方法: selectSpriteForTouch:
- (Void) selectSpriteForTouch: (CGPoint) touchLocation {
CCSprite * newSprite = nil;
for (CCSprite * sprite in movableSprites) {
if (CGRectContainsPoint (sprite.boundingBox, touchLocation)) {
newSprite = sprite;
break;
}
}
if (newSprite! = selSprite) {
[selSprite stopAllActions];
[selSprite runAction: [CCRotateTo actionWithDuration: 0.1 angle: 0 ]] ;
CCRotateTo * rotLeft = [CCRotateBy actionWithDuration: 0.1 angle: -4.0];
CCRotateTo * rotCenter = [CCRotateBy actionWithDuration: 0.1 angle: 0.0];
CCRotateTo * rotRight = [CCRotateBy actionWithDuration: 0.1 angle: 4.0];
CCSequence * rotSeq = [CCSequence actions: rotLeft, rotCenter, rotRight, rotCenter, nil];
[newSprite runAction: [CCRepeatForever actionWithAction: rotSeq]];
selSprite = newSprite;
}
}因此,当您单击任何CCSprite时,CCSprite开始旋转。请告诉我,通过单击CCSprite的第一个数组之一,出现了与第二个数组完全相同的CCSprite,他开始旋转CCSprite,而不是从第一个数组和第二个出现的数组中旋转)
发布于 2013-11-29 15:48:07
若要创建使用与已存在的sprite相同的纹理(图片)的sprite,请执行以下操作:
CCSprite* newSprite = [CCSprite spriteWithTexture:existingSprite.texture
rect:existingSprite.textureRect];https://stackoverflow.com/questions/20289177
复制相似问题