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
...
}