【发布时间】:2011-04-20 09:28:33
【问题描述】:
嘿,再次,
基本上,我有两个课程:
HudLayer 和 ConstructLayer。
我想从 ConstructLayer 访问 HudLayer 内的一个方法,以关闭/打开在 HudLayer 内分配的 CCSprite 的可见性属性。
HudLayer 接口和实现:
HudLayer : CCLayer
@interface{
CCSprite *leftArrow;
CCSprite *rightArrow;
}
-(void)switcher:(BOOL)isVisible;
@end
@implementation
-(id)init{
//Create the Hud Sprites and add them at an arbitrary location
leftArrow = [[[CCSprite alloc]init]retain];
leftArrow = [CCSprite imageWithFile:@"file.png"];
rightArrow = [[[CCSprite alloc]init]retain];
rightArrow = [CCSprite imageWithFile:@"file.png"];
leftArrow.visible = NO;
rightArrow.visible = NO;
[self addChild: leftArrow];
[self addChild: rightArrow];
}
-(void)switcher:(BOOL)isVisible{
NSLog (@"Accessed the visibility switcher");
if (isVisible == NO){
leftArrow.visible = NO;
rightArrow.visible = NO;
}
if (isVisible == YES){
leftArrow.visible = YES;
rightArrow.visible = YES;
}
@end
构造层实现:
#import "HudLayer"
@implementation ConstructLayer
-(void)someFunction{
//Attempt to change the visibility of leftArrow and rightArrow
HudLayer *hud = [[HudLayer alloc]init];
[hud switcher: NO];
[hud release];
}
这应该工作不应该吗?但事实并非如此!
我访问了 [hud switcher:] 方法,但由于某种原因,它不会正确设置属性 CCSprite.visibility。
我在我的控制台中放置了一个打印的 NSLog 语句,证明它正在访问它。
真的很奇怪,不知道怎么回事。
我什至在这个函数中定义了变量并用 NSLog 打印它们,它工作了......
【问题讨论】:
标签: objective-c class methods cocos2d-iphone accessibility