Cocos2d 2.0绘制方法错误

时间:2012-08-22 15:54:58

标签: objective-c xcode cocos2d-iphone

我使用cocos2d 2.0。我收到错误:property 'world' not found on object of type 'ColoredCircleSprite *' 我在draw方法中写错了什么?

-(void) draw
{
    [super draw];
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    kmGLPushMatrix();
    self.world->DrawDebugData();
    kmGLPopMatrix();
}

我尝试按照显示的那样做:Cocos2D 2.0 OpenGL errors?

另外我看到了另一种绘制方法的方法,我必须从self.行删除self.world->DrawDebugData();,如果我这样做,我会收到另一个错误:Use undeclared identifier 'world'

那是ColoredCircleSprite.h代码:

#import "cocos2d.h"

@interface ColoredCircleSprite : CCNode <CCRGBAProtocol, CCBlendProtocol> {
    float       radius_;
    GLubyte     opacity_;
    ccColor3B   color_;

    NSUInteger numberOfSegments;
    GLfloat *circleVertices_;

    ccBlendFunc blendFunc_;
}

@property (nonatomic,readwrite) float radius;

/** Opacity: conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) GLubyte opacity;
/** Opacity: conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) ccColor3B color;
/** BlendFunction. Conforms to CCBlendProtocol protocol */
@property (nonatomic,readwrite) ccBlendFunc blendFunc;

/** creates a Circle with color and radius */
+ (id) circleWithColor: (ccColor4B)color radius:(GLfloat)r;

/** initializes a Circle with color and radius */
- (id) initWithColor:(ccColor4B)color radius:(GLfloat)r;

- (BOOL) containsPoint:(CGPoint)point;

@end

我只是从cocos2d-iphone.com论坛复制并粘贴代码。 我真的不知道应该在哪个变量,是否应该有变量。

感谢。

1 个答案:

答案 0 :(得分:0)

@interface ColoredCircleSprite : CCSprite
{
    b2World         *mWorld;
}
@property(nonatomic,assign) b2World         *world;
@end


@implementation ColoredCircleSprite
@synthesize world = mWorld;

-(void)initBox2D
{    
    //create world in right place...
    self.world = new b2World(gravity);
}
@end