目前我正在制作一个非常简单的测试应用程序(我刚开始使用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 *) –