Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Richard Rodriguez
2,687 PointsSpriteKit Game: If I had .png files for a 3rd dog, then how would i write the code since it uses if else?!
NSArray *textures;
if ( type == RRSmushBallTypeA) {
dog = [self spriteNodeWithImageNamed:@"dog_A_1"];
textures = @[[SKTexture textureWithImageNamed:@"dog_A_1"],
[SKTexturetextureWithImageNamed:@"dog_A_2"]];
} else {
dog = [self spriteNodeWithImageNamed:@"dog_B_1"];
textures = @[[SKTexture textureWithImageNamed:@"dog_B_1"],
[SKTexture textureWithImageNamed:@"dog_B_2"]];
-----Would i just do another else statement??????
1 Answer

Benjamin Bell
4,364 PointsI haven't done any SpriteKit work but from your code i'd say add an else if statement:
if ( type == RRSmushBallTypeA) {
dog = [self spriteNodeWithImageNamed:@"dog_A_1"];
textures = @[[SKTexture textureWithImageNamed:@"dog_A_1"],
[SKTexturetextureWithImageNamed:@"dog_A_2"]];
} else if (type == RRSmushBallTypeB) {
dog = [self spriteNodeWithImageNamed:@"dog_B_1"];
textures = @[[SKTexture textureWithImageNamed:@"dog_B_1"],
[SKTexture textureWithImageNamed:@"dog_B_2"]];
} else {
dog = [self spriteNodeWithImageNamed:@"dog_C_1"];
textures = @[[SKTexture textureWithImageNamed:@"dog_C_1"],
[SKTexture textureWithImageNamed:@"dog_C_2"]];
Hope this helps
And don't forget to uprate :)
Richard Rodriguez
2,687 PointsRichard Rodriguez
2,687 Pointsthanks!!