我正在尝试从 CCSprite 派生类以将精灵引用存储到其相应的 b2Body,但出现以下错误(代码中的注释)
盒子精灵.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
...
}