简单方法返回 Objective C
我目前是 Objective C 的新手,在制作游戏时遇到了一个问题,我有一个名为 BattleEngine 的定制对象,它是 cocos2d 中我的 helloWorld 场景中的一个实例变量。该对象有一个名为 plyController 的对象作为实例变量,它是一个 PlayerController 对象。我希望 BattleEngine 有一个返回 plyController 对象的 getter 方法,但此代码不起作用:
-(PlayerController*)getPlayerController
{
return plyController;
}
I am currently new to objective c and have came across a problem while making a game I have a custom made object called battleEngine which is an instance variable in my helloWorld scene in cocos2d. That object has an object as an instance variable called plyController which is a PlayerController object. I want battleEngine to have a getter method that returns the plyController object and this code doesn't work:
-(PlayerController*)getPlayerController
{
return plyController;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有任何原因不将玩家控制器对象声明为属性?在这种情况下,您可以只使用合成的 getter 来获取玩家控制器。
查看文档 属性。
另外,我担心我必须这么说,否则他们会夺走我的 Cocoa 程序员徽章,
getPlayerController
不是一个好的方法名称。其中包含get
的方法通常用于返回通过引用传入的参数中的值。 Cocoa 编码指南告诉我们这一点,以及更多。Is there any reason you haven't just declared your player controller object as a property? You could just use the synthesised getter in that case to get the player controller.
Have a look at the documentation on properties.
Also, and I'm afraid I have to say this or they will take my Cocoa-programmer badge away from me,
getPlayerController
is not a good method name. Methods withget
in them are conventionally used to return values in the parameters passed in by reference. The Cocoa Coding Guidelines tells us this, and much more.