나는 내 레이어에 액세스하는 데 어려움을 겪고있다. 기본적으로 내 레이어 - 장면 계층은 다음과 같습니다.CCLayer 두통에 액세스!
Compiler.m - CCLayer - + (CCScene) 메서드를 보유하고 다른 모든 CCLayer를로드합니다.
Construct.m - CCLayer - box2d 엔진과 해당 구성 요소를 보유합니다.
Background.m - CCLayer - 배경을 보유합니다.
Hud.m - CCLayer - HUD를 유지합니다. 컴파일러 구현 클래스 내에서
@implementation Compiler
+(CCScene *) scene{
Compiler *compiler = [CompileLayer node];
CCScene *scene = [CCScene node];
[scene addChild: compiler];
//Add A Background Layer.
Background *layerBackground = [Background node];
layerBackground.position = CGPointMake(100,100);
[compiler addChild: layerBackground z: -1 tag:kBackground];
//Add The Construct.
Construct *construct = [Construct node];
[compiler addChild: construct z: 1];
//Add A Foreground Layer Z: 2
//After background is working.
//Add the HUD
HudLayer *hud = [Hud node];
[compiler addChild: hud z:3];
}
모두가 잘 작동이, 내 층 컴파일러에 추가 컴파일러의 장면에서 액세스를 대표단은 예상대로
내 문제는 내 Construct 게임 영웅의 위치에 따라 이동할 수 있도록 Construct 레이어 내부에있는 배경 CCLayers - CCsprite * 배경에 액세스하려고하는 것입니다.
여러 가지 방법을 시도했지만, CCFLrite * 배경을 정의하기 위해 인스턴스 메서드가 아닌 클래스 메서드를 사용하기로 결정했습니다. 따라서 Construct Layer에서 액세스 할 수 있습니다.
@properties를 사용하여 액세스를 시도하고 클래스의 인스턴스 변수를 초기화했습니다.
@implementation Background
-(id) init
{
self = [super init];
if (self != nil)
{
CCSprite *temp = [Background bk];
[self addChild:temp z:0 tag:kBackGround];
}
return self;
}
+(CCSprite *)bk{
//load the image files
CCSprite *background = [CCSprite spriteWithFile:@"background.jpg"];
//get the current screen dimensions
//CGSize size = [[CCDirector sharedDirector] winSize];
background.anchorPoint = CGPointMake(0,0);
background.position = ccp(0,0);
return background;
}
@end
, 그것은 배경 레이어에 이미지를로드 :
여기 내 배경 CCLayer입니다.
마지막으로 Construct Layer에서 배경 이미지에 액세스하려고합니다.
@interface Construct : CCLayer{
CCSprite *tempBack;
}
@end
@implementation Construct
-(id) init{
tempBack = [Background bk]; //The background equals an instance variable
}
-(void) tick:(ccTime)dt {
tempBack.position.x ++; // To do Something here.
tempBack.opacity = 0.5; // Some more stuff here.
}
@end
이 나던 작품은, 난 전혀 적절 배경에 액세스하거나 나던 어떤 측면, tempBack에 '전무'포인터를받을 수 있습니다.
어떻게 백그라운드 CCLayers 클래스 변수 + (CCSprite) bk에 액세스하고 수정할 수 있습니까 ??
아니요. 어떻게 그 클래스 메소드 변수에 접근하여 그것을 다른 레이어에서 수정할 수 있습니까? 내 견과류 운전 : ( – Ospho
플레이어의 위치와 함께 알림을 보내고 백그라운드 레이어에서 수신 대기하는 방법은 무엇입니까? – Eimantas
Eimantas, 이것이 작동 할 수 있습니다. 어떻게해야합니까? 작은 코드 스 니펫을 게시 할 수 있습니까? – Ospho