2012-04-13 3 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 초기화 방법에
#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