Reputation: 137
i need to check if my sprite node texture is equal to name @"GoldDot". i try the code
if ([red.texture isEqual:@"GoldDot"]) {
NSLog(@"gold!!!!");
}else{
}
please help
Upvotes: 1
Views: 489
Reputation: 20274
To compare SKTextures, have a look at this answer.
A cleaner alternative would be to set the name of the SKSpriteNode as the image you are setting.
NSString *textureName = @"GoldDot";
SKSpriteNode *node =[SKSpriteNode spriteNodeWithImageNamed: textureName];
node.name = textureName;
Afterwards, just compare the name
if ([red.name isEqual:@"GoldDot"]) {
NSLog(@"gold!!!!");
}
Upvotes: 3
Reputation: 154
For this you would be better testing to see if your texture is equal to another texture, not a string. The test you might want to try is,
if([red.texture isEqual:[SKTexture textureWithImageNamed:@"GoldDot.png"]]){
NSLog(@"gold!!!");
else{
}
Then simply give the name of the texture you are looking for.
Upvotes: 3