这行是什么意思?
我在开源项目的 init
方法中找到了这一行:
AtlasSpriteManager *spriteManager =
(AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
和 kSpriteManager = 0;
然后用于此目的的 spriteManager
AtlasSprite *bird = [AtlasSprite spriteWithRect:
CGRectMake(608,16,44,32) spriteManager:spriteManager];
[spriteManager addChild:bird z:4 tag:kBird];
任何想法都会是非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从第一行开始:
这意味着有一个名为
-getChildByTag:
的方法,它返回一个通用子对象。由于返回的对象是通用的(没有特定类型),因此必须先将其转换为适当的类型,然后才能使用。我猜测该方法定义如下所示:在内部,该类将包含通用子对象的数组,并且可以通过使用适当的标记调用
getChildByTag:
来检索特定的子对象。在本例中,程序员知道标记为 0 的子级是一个
AtlasSpriteManager
,因此他们只需转换为该类型,然后像平常一样使用spriteManager
。Starting with the first line:
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: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 thespriteManager
as they normally would.