0
@interface Player()
@property (nonatomic) SKTextureAtlas *atlas;
@end
@implementation Player{
DecorativeBall *decorativeBall;
GolfBall *golfBall;
}
- (id) initWithBallName :(NSString *) name{
if(self = [super init]){
_atlas = [SKTextureAtlas atlasNamed:@"Balls"];
[self removeAllChildren];
if ([name isEqualToString:@"DecorativeBall"]) // if it is a decorative ball{
if (debug){
printf("\n\n It's a Decorative ball");
}
if (!decorativeBall){
decorativeBall = [[DecorativeBall alloc] initWithTexture:[_atlas textureNamed:@"DecorativeBall"]];
golfBall = nil;
}
[self addChild:decorativeBall];
}
if ([name isEqualToString:@"GolfBall"]) // if it is a golf ball{
if (debug){
printf("\n\n It's a Golf ball");
}
if (!golfBall){
golfBall = [[GolfBall alloc] initWithTexture:[_atlas textureNamed:@"GolfBall"]];
decorativeBall = nil;
}
[self addChild:golfBall];
}
}
return self;
}
@end
위의 코드 decorativeBall = nil과 golfBall = nil에서 메모리를 확보하는 데 도움이되는지, 아니면 어떤 의미를 가지나요? 내가하려는 것은, 골프 공이 이미 선택되어 있고, 플레이어가 장식 공으로 바꾸었다면, 그렇게하는 것입니다. 현장에서 골프 공을 제거하고 싶습니다. 올바른 방법입니까?스프 라이트 노드에 nil을 지정하면 어떻게됩니까?