“b2Body 之前的预期说明符量词列表” XCode 中的错误
我试图从 CCSprite 派生类来存储对其相应 b2Body 的精灵引用,但我收到以下错误(代码中的注释)
BoxSprite.h
#import <Foundation/Foundation.h>
#import "Box2D.h"
#import "cocos2d.h"
@interface BoxSprite : CCSprite {
b2Body* bod; // Expected specifier-quantifier-list before b2Body
}
@property (nonatomic, retain) b2Body* bod; // Expected specifier-quantifier-list before b2Body
@end // Property 'bod' with 'retain' attribute must be of object type
BoxSprite.m
#import "BoxSprite.h"
@implementation BoxSprite
@synthesize bod; // No declaration of property 'bod' found in the interface
- (void) dealloc
{
[bod release]; // 'bod' undeclared
[super dealloc];
}
@end
我希望创建精灵并分配主体:
BoxSprite *sprite = [BoxSprite spriteWithBatchNode:batch rect:CGRectMake(32 * idx,32 * idy,32,32)];
...
sprite->bod = body; // Instance variable 'bod' is declared protected
然后通过以下方式访问b2Body:
if ([node isKindOfClass:[BoxSprite class]]) {
BoxSprite *spr = (BoxSprite*)node;
b2Body *body = spr->bod; // Instance variable 'bod' is declared protected
...
}
I'm trying to derive class from CCSprite to store the sprites reference to its corresponding b2Body, but I've get the following errors (comments in Code)
BoxSprite.h
#import <Foundation/Foundation.h>
#import "Box2D.h"
#import "cocos2d.h"
@interface BoxSprite : CCSprite {
b2Body* bod; // Expected specifier-quantifier-list before b2Body
}
@property (nonatomic, retain) b2Body* bod; // Expected specifier-quantifier-list before b2Body
@end // Property 'bod' with 'retain' attribute must be of object type
BoxSprite.m
#import "BoxSprite.h"
@implementation BoxSprite
@synthesize bod; // No declaration of property 'bod' found in the interface
- (void) dealloc
{
[bod release]; // 'bod' undeclared
[super dealloc];
}
@end
I was hoping to create the sprite and assign the body with:
BoxSprite *sprite = [BoxSprite spriteWithBatchNode:batch rect:CGRectMake(32 * idx,32 * idy,32,32)];
...
sprite->bod = body; // Instance variable 'bod' is declared protected
Then access the b2Body by:
if ([node isKindOfClass:[BoxSprite class]]) {
BoxSprite *spr = (BoxSprite*)node;
b2Body *body = spr->bod; // Instance variable 'bod' is declared protected
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是
使用
,因为您没有传递 Objective-C 对象。
@synthesize 指令也可以工作,因此您不需要创建自己的 getter 和 setter 方法,除非您想同时执行其他操作。
Instead of
use
since you're not passing an objective-c object.
The @synthesize directive will work too so you do not need to create your own getter and setter methods unless you want to do something else at the same time.
b2Body 是一个 C++ 对象,因此我必须创建自己的 getter 和 setter,并将 BoxSprite.m 重命名为 .mm 文件。
BoxSprite.h
BoxSprite.mm
创建:
访问:
b2Body is a C++ object, and so I have to make my own getters and setters, and rename BoxSprite.m to a .mm file.
BoxSprite.h
BoxSprite.mm
Create:
Access: