0
在我的場景我有的Cocos2D:無法調用父類
//.h
#import "cocos2d.h"
#import "FixedBackground.h"
@class FixedBackground;
#import "JoinedMapsLayer.h"
@class JoinedMapsLayer;
@interface JoinedMapsScene : CCScene {
FixedBackground *fixedBackground;
JoinedMapsLayer *joinedMapsLayer;
}
@property(nonatomic, retain) FixedBackground *fixedBackground;
@property(nonatomic, retain) CCNode *joinedMapsLayer;
+(id) scene;
- (void) moveBG:(float)x andY:(float)y;
- (int) getInt;
@end
//.m
#import "JoinedMapsScene.h"
@implementation JoinedMapsScene
@synthesize fixedBackground;
@synthesize joinedMapsLayer;
+(id) scene {
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layers' are an autorelease object.
JoinedMapsScene *layer1 = [JoinedMapsScene node];
// add layers as a childs to scene
[scene addChild: layer1];
return scene;
}
-(id) init {
if((self=[super init])) {
fixedBackground = [FixedBackground node];
joinedMapsLayer = [JoinedMapsLayer node];
// add layers as a children of the scene
[self addChild:fixedBackground];
[self addChild:joinedMapsLayer];
}
return self;
}
- (int)getInt {
return 100;
}
- (void) dealloc{
[super dealloc];
}
@end
在joinedMapsLayer init方法我嘗試調用getInt並返回它的值爲100,但它返回0:
NSLog(@「%d」,[(JoinedMapsScene *)self.parent getInt]);
任何線索爲什麼發生這種情況?我的場景寫錯了嗎?
你也可以寫.h文件嗎?我認爲問題在於結構化... – 2012-04-14 06:29:17
更新.h – VagueExplanation 2012-04-16 15:46:19