大家好一點卡在這一個, 我希望通過名稱列舉通過它們添加到屏幕上的精靈(我第一次嘗試在枚舉),所以我很確定它將是簡單的,我錯過了 - 代碼低於 任何幫助表示讚賞。使用枚舉更改精靈的顏色
添加精靈層:
for(int keyCount = 0; keyCount < ammountOfSprites; ++keyCount)
//other code here....
Star01 = [SKSpriteNode spriteNodeWithImageNamed:@"Actions-rating-icon.png"];
Star01.position = CGPointMake(-30,StarHeight);
[MyLabel addChild:Star01];
**Star01.name** = [NSString stringWithFormat:@"Star01_%@",[NSString stringWithFormat:@"%@",dataFromArray]];
NSLog(@"%@", Star01.name);
///名稱登錄爲:
Star01_Owl
Star02_Owl
Star03_Owl
觸摸內部開始
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:touchLocation];
//colour to add to the
UIColor *blackColour = [UIColor greenColor];
//function takes sprite.names and enumerates them
//name match those logged however dont work.
[self changeStarScorestar01:@"Star01_Owl" star02:@"Star02_Owl" star03:@"Star03_Owl" colour:blackColour];
後來......
//function takes sprite.names and enumerates them
-(void)changeStarScorestar01:(NSString*)star01 star02:(NSString*)star02 star03:(NSString*)star03 colour:(UIColor*)Starcolour
{
[self enumerateChildNodesWithName:star01 usingBlock:^(SKNode *node, BOOL *stop)
{
NSLog(@"node.name isEqualToString:star01");
SKSpriteNode *star01Found = (SKSpriteNode*)[self childNodeWithName:star01];
star01Found.color =Starcolour;
star01Found.colorBlendFactor =1.0;
}
關於測試它無法找到精靈,所以我必須針對錯誤的對象> <什麼?
[self enumerateChildNodesWithName:star01 usingBlock:^(SKNode *node, BOOL *stop)
{
if ([node.name isEqualToString:star01])
{
NSLog(@"FOUND STAR");
}}
因此,你有一個名爲'MyLabel'的SKNode中的小精靈?是否將MyLabel添加到場景中?如果是這樣,那麼我相信你需要枚舉'MyLabel'的孩子,而不是現場 – Knight0fDragon
Knight0fDragon - 這的確是問題所在 - 謝謝:) – StackBuddy