0
我在HelloWorldLayer類中初始化了一個方法播放器方法(繼承自NSObject)。我想以這種方式聲明同一類的其他方法,我不需要分配它們。例如:在沒有alloc的情況下訪問另一個類中的方法
Player.mm
-(id)spritePlayer:(CCLayer *)parentLayer
inWorld:(b2World *)world
{
creation of sprite body and other stuff
}
我想在接觸監聽器類中使用這種方法,但我已經宣佈它的播放器類:
-(void) touchingFix:(b2Fixture *)touchedFix
{
bodyTouched=TRUE;
bodyFix=touchedFix;
}
在聯繫監聽器我只能通過以下方式訪問它:
[[Player alloc] touchingFix:fixtureA];
我不能以某種方式訪問它,而無需在另一個位置分配它 方法?如果是的話,我該怎麼做。
我已經改變了「 - 」到「+」,但我在'touchingFix'方法,說行收到一個錯誤'實例變量「bodyTouched」在類變量中訪問,'bodyFix'也一樣。 – oopology
對不起,我的意思是「實例變量」bodyTouched「在類方法中訪問」 – oopology
將變量設置爲靜態。 –