I have made a method player method (inherits from NSObject) that I initialize in the HelloWorldLayer class. I want to declare other methods of the same class in such a way that I don’t need to alloc them. For Example:
Player.mm
-(id)spritePlayer:(CCLayer *)parentLayer
inWorld:(b2World *)world
{
creation of sprite body and other stuff
}
I want to use this method in the contact Listener class, but I’ve declared it the player class:
-(void) touchingFix:(b2Fixture *)touchedFix
{
bodyTouched=TRUE;
bodyFix=touchedFix;
}
In the Contact Listener class I can only access it through:
[[Player alloc] touchingFix:fixtureA];
Can’t I access it in a way without allocating it in another method? if yes, how can I do it.
Change it to a class method: remove the ‘-‘ in front of the method and change it to a ‘+’
You can access a class method by using the class name instead of a pointer to an instance of the class: