开发者

what this line means? [closed]

开发者 https://www.devze.com 2023-03-25 03:54 出处:网络
It's difficult to tell what is being asked her开发者_如何学Goe. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked her开发者_如何学Goe. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

i found this line in the init method from an open source project :

AtlasSpriteManager *spriteManager =
    (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];

and kSpriteManager = 0;

then spriteManager used for this purpose

     AtlasSprite *bird = [AtlasSprite spriteWithRect:
                         CGRectMake(608,16,44,32) spriteManager:spriteManager];
    [spriteManager addChild:bird z:4 tag:kBird];

any idea will be great thank you.


Starting with the first line:

AtlasSpriteManager *spriteManager = 
    (AtlasSpriteManager*)[self getChildByTag:kSpriteManager]; 

This means that there is a method called -getChildByTag: which returns a generic child object. Since the returned object is generic (no specific type) it must be cast to the appropriate type before it can be used. I would guess that the method definition looks something like this:

- (id)getChildByTag:(NSInteger)tag;

Internally, the class would contain an array of generic child objects, and a specific child can be retrieved by calling getChildByTag: with the appropriate tag.

In this case, the programmer knew that the child with tag 0 is an AtlasSpriteManager, so they simply cast to that type and then used the spriteManager as they normally would.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号