从 Cocos2D 类访问 UIView 方法
我正在使用 Cocos2D,并且需要访问从另一个类添加到 UIViewController 的 UIView 中的父方法。我的层次结构如下:
分支 1: 窗口 > viewController.view> glView>加入MapsScene>>加入MapsLayer
分支2:窗口> viewController.view> foregroundLabelView
当我的标签类曾经是 Cocos2D 的一部分时,通过执行以下操作可以轻松访问:
JoinedMapsScene *joinedMapsScene = (JoinedMapsScene*)self.parent; [joinedMapsScene.tetraCounter incTetras:-1];
但现在我需要从joinedMapsLayer调用foregroundLabelView中的方法。这可能不是一个 cocos2D 问题,但我仍然对这类东西感到困惑。
I'm using Cocos2D, and I need to access a parent method in a UIView that is added to a UIViewController from another class. My hierarchy goes like this:
Branch 1: window > viewController.view > glView > joinedMapsScene > joinedMapsLayer
Branch 2: window > viewController.view > foregroundLabelView
When my label class used to be part of Cocos2D, accessing was easy by doing something like this:
JoinedMapsScene *joinedMapsScene = (JoinedMapsScene*)self.parent;
[joinedMapsScene.tetraCounter incTetras:-1];
But now I need to call the method in foregroundLabelView from joinedMapsLayer. It may not be so much of a cocos2D question, but I'm just really confused about this sort of stuff still.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解得很好,你想从 joinMapsLayer 检索 foregroundLabelView 实例。有办法,但不知道是否最优。
您可以在 AppDelegate.h 中实例化一个 foregroundLabelView。
然后,当您初始化foregroundLabelView时,您将其分配给AppDelegate foregroundLabelView:在您的foregroundLabelView.m中(您必须导入AppDelegate.h),在init方法的末尾,您可以执行
以下操作然后,只要您愿意,您就可以通过执行以下操作来检索它:
然后访问该方法:
我认为这应该可行。
If I had understood well you want to retrieve the foregroundLabelView instance from joinedMapsLayer. There is a way but I don't know if it's optimal.
You can in your AppDelegate.h instantiate a foregroundLabelView.
Then when you init your foregroundLabelView you assign it to the AppDelegate foregroundLabelView: in your foregroundLabelView.m (you have to import AppDelegate.h), at the end of the init method you can do
Then whenever you want you can retrieve it by doing:
and then access the method:
I think this should work.