如何将消息从目标c中的不同类传递到实例?

发布于 2024-09-09 01:42:18 字数 706 浏览 1 评论 0原文

坚持我认为这里很简单的事情。基本上我需要将一个指向对象的指针作为参数传递到另一个类的实例方法中。换句话说:我有一个创建“事物”的类,并且我有一个我想要接收“事物”的另一个类的实例

使用 Cocos2D 框架。 Things 是 CCSprite 的自定义子类,接收它们的实例是 CCLayer。

我想我误解了关于 ivars 或这里的属性的一些基本知识。任何正确方向的指示将不胜感激。

这是 ThingLayer 的接口,它应该接收“东西”:

@interface ThingLayer: CCLayer {
 CCTextureAtlas *textureAtlas; 
 ThingLayer *thingLayer;
 NSMutableArray *ThingsArray;
}


- moveThingtoLayer:(Thing*)athing;

@end

以下是我尝试从类外部向实例发送消息的方式:

 [ThingLayer moveThingtoLayer:thing];

我意识到我在这里询问类,而不是实例......这是给我“可能不会回应...”错误。但这也不起作用(询问实例名称)...

 [thingLayer moveThingtoLayer:thing];

有任何明显的答案吗?

Stuck on what I figure is simple thing here. Basically I need to pass a pointer to an object as an argument into an instance method of another class. Said differently: I have a class that creates "Things" and I have an instance of another class that I want to receive the "Things."

Working with Cocos2D frameworks. The Things are a custom subclass of CCSprite, and the instance that receives them is a CCLayer.

I figure I'm misunderstanding something basic about ivars or maybe properties here. Any pointers in the right direction would be appreciated.

Here's the interface for ThingLayer, which should receive the "thing":

@interface ThingLayer: CCLayer {
 CCTextureAtlas *textureAtlas; 
 ThingLayer *thingLayer;
 NSMutableArray *ThingsArray;
}


- moveThingtoLayer:(Thing*)athing;

@end

And here's how I'm trying to message to the instance, from outside the class:

 [ThingLayer moveThingtoLayer:thing];

I realize I'm asking the class here, not the instance... which is giving me "may not respond to..." errors. But this isn't working either (asking name of instance)...

 [thingLayer moveThingtoLayer:thing];

Any obvious answers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2024-09-16 01:42:19

看起来你应该有

ThingLayer *thingLayer = [[ThingLayer alloc] init]; 
[thingLayer moveThingtoLayer: thing];

作为一个侧面的想法,你很可能希望在 thingLayer 中初始化一个新事物,以便该实例拥有该事物,并在调用 moveThingToLayer 后释放事物。

Looks like you should have

ThingLayer *thingLayer = [[ThingLayer alloc] init]; 
[thingLayer moveThingtoLayer: thing];

As a side thought, you most likely want to init a new thing in thingLayer so that instance owns the Thing, and release thing after calling moveThingToLayer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文