目前我正在製作一個非常簡單的測試應用程序(我剛開始使用sprite工具包,而且我感覺非常好!)和我會發出警告。該應用程序在我的終端上運行得很好,但黃色線條讓我非常討厭,我想最好是憎恨某些東西並理解它,而不是討厭某些東西而不理解它。所以這是我的代碼,我會解釋一下我想要做的事情。不兼容的指針類型用'SKNode *'類型的表達式初始化'SKSpriteNode *'
-(void)selectNodeForTouch:(CGPoint)touchlLocation {
// Checks if a cloud was touched
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchlLocation];
if ([[touchedNode name] isEqualToString:@"Cloud"]) {
// NSLog(@"You touched a cloud!");
// Allows me to interact with a label that was defined elsewhere
/* Figure out what is causing this stupid error! It runs fine, but it's an annoying yellow line */
SKLabelNode *scoreLabel = [self childNodeWithName:@"scoreLabel"];
score++;
scoreLabel.text = [NSString stringWithFormat:@"%d", score];
// Allows me to interact with a cloud that was defined elsewhere
SKSpriteNode *cloud = [self childNodeWithName:@"Cloud"];
// Remove the node with an action (animated of course)
SKAction *grow = [SKAction scaleTo:1.2 duration:0.1];
SKAction *shrink = [SKAction scaleTo:0 duration:0.07];
SKAction *removeNode = [SKAction removeFromParent];
SKAction *seq = [SKAction sequence:@[grow,shrink,removeNode]];
[cloud runAction:seq];
}
}
基本上我想在我的代碼申報供以後使用這些「對象」這樣我就可以改變他們(爲scoreLabel我希望能夠以更新得分,併爲雲我想能夠在其上使用SKAction序列)
警告消息:不兼容的指針類型初始化「SKSpriteNode *」有型「SKNode *」
如果你有興趣,這裏是我的「原始」的聲明的表達的物品
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
// Create Score Label
self.backgroundColor = [SKColor colorWithRed:0.204 green:0.596 blue:0.859 alpha:1.0];
SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"ArialRoundedMTBold"];
label.fontSize = 48;
label.text = @"0";
label.position = CGPointMake(CGRectGetMidX(self.frame), 40);
label.fontColor = [SKColor colorWithRed:1 green:1 blue:1 alpha:1.0];
label.zPosition = 9999999;
label.name = @"scoreLabel";
[self addChild:label];
// Create Cloud
SKSpriteNode *cloud = [SKSpriteNode spriteNodeWithImageNamed:@"Cloud"];
cloud.position = CGPointMake(50, 50);
int random = arc4random();
NSLog([NSString stringWithFormat:@"%d", random]);
cloud.size = CGSizeMake(80, 56);
cloud.name = @"Cloud";
[self addChild:cloud];
}
return self;
}
什麼行是警告? – connor
涉及 的行數SKSpriteNode * cloud = [self childNodeWithName:@「Cloud」];''和'SKLabelNode * scoreLabel = [self childNodeWithName:@「scoreLabel」];' – Interprep
SKLabelNode * scoreLabel = [self childNodeWithName:@「 scoreLabel「];將其轉換爲(SKLabelNode *) –