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! While you're at it, check out some resources Treehouse students have shared here.

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

iOS

In Sprite Kit tutorial why are the Sprite classes written without over-ridden init methods?

In the Sprite Kit tutorial, Amit creates instances of sprite nodes using class methods. Eg:

+(instancetype) hudAtPosition:(CGPoint)position inFrame:(CGRect)frame {...

Ever since I first learned Obj-C, I've always used custom init methods to create objects:

-(id)initHudAtPosition:(CGPoint)position inFrame:(CGRect)frame {
       if (self = [super initWithImageNamed:...

I'm currently working on a game of my own and tried using Amit's method with my PC sprite but ran into problems. For example, the following seemed to have no effect on the instance property:

hero.UpTexture = [SKTexture textureWithImageNamed:@"HeroUp"];

hero.UpTexture would point to null. However, if I created my objected using a custom init method, the property would be set properly.

Why is Amit creating objects in his way? What is the benefit of not using a custom init method? Why couldn't I set the instance properties properly without using an init method?