2012-04-13 12 views
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

私が呼び出そうとjoinedMapsLayerのinitメソッドで
#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 

getIntを返し、値100を返しますが、0を返します。

NSLog(@ "%d"、[(JoinedMapsScene *)self.parent getInt]);

これはなぜ起こっているのか?私のシーンが正しく書かれていないのですか?

+0

.hファイルも記述できますか?私は問題が構造化していると思います... –

+0

答えて

2

[JoinedMapsLayer node]に電話をかけた時点で、JoinedMapsSceneというインスタンスの子としてjoinedMapsLayerをまだ追加していないため、親はありません。

+0

で更新ありがとう私は今理解しています。私はこれを行うために他の何かを考え出します。 – VagueExplanation

関連する問題