在我的场景中,我有
//。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]);
任何线索为什么会发生这种情况?我的场景写错了吗?