开发者

ObjectiveC accessing base class properties in subclass?

开发者 https://www.devze.com 2023-03-22 20:26 出处:网络
I am new to Object开发者_运维问答iveC and I have following inheritance. @interface CGameEntity : NSObject {

I am new to Object开发者_运维问答iveC and I have following inheritance.

    @interface CGameEntity : NSObject {
        b2Body *entityBody;
    }

    @property(nonatomic,retain) CCSprite *entitySprite;

   -(id)initEntity:(CCNode*)parentNode :(b2World*)world;
   @end

implementation :

@implementation CGameEntity

@synthesize entitySprite=entitySprite;
.
.
.
@end

And extended class is as follows :

@interface CPlanet : CGameEntity {

}
@end

implementation is as follows:

@implementation CPlanet

-(id)initEntity:(CCNode*)parentNode :(b2World*)world
{
    if((self = [super init]))
    {
        //cannot access "entitySprite" ????
        entitySprite=[CCSprite spriteWithFile:@"planet.png"];

    }
    return self;
}

@end

In the extended class I cannot access the property "entitySprite". How can I access properties of the base class ?

Thank you


First of all, replace ...

@synthesize entitySprite=entitySprite;

By ...

@synthesize entitySprite;

Then, replace this line ...

entitySprite=[CCSprite spriteWithFile:@"planet.png"];

By this ...

self.entitySprite = [CCSprite spriteWithFile:@"planet.png"];

This will work =)!

0

精彩评论

暂无评论...
验证码 换一张
取 消