@synthesize loadingSprite
- (id)init
{
loadingSprite = [CCSprite spriteWithSpriteFrameName:@"loading-icon1.png"];
[loadingSprite setTag:111];
[self addChild:loadingSprite];
}
- (void)getTag
{
NSLog(@"%@ tag %d",[loadingSprite getChildByTag:111] , [loadingSprite getChildByTag:111].tag)
}
을 ccsprite 오전 액세스, 비엠 제가
A *a = [[A alloc] init];
[a getTag];
방법 GetTag의 액세스에 쓸 하지만 유감스럽게도 getTag의 NSLog는 다음을 보여줍니다.
(null) tag 0
다른 클래스에서 ccsprite에 액세스하는 적절한 방법은 무엇입니까? 감사합니다
가장 좋은 방법은 일반적인 스프라이트에 대해 싱글 톤 클래스를 만드는 것입니다. 다시 말하면 다시 초기화 할 필요가 없으며 원하는 곳에서 스프라이트에 할당 된 모든 속성을 가져 오거나 설정할 수도 있습니다 . – spider1983
예, 결국 싱글 톤을 사용합니다. 그것은 너무 많이하지만 싱글 톤으로 스프라이트를 사용하는 것 외에 어떤 단서도 가지고 있지 않다. – user1606616