- [CCScene setOffsetx:]:发送到实例的无法识别的选择器

时间:2012-03-23 05:05:07

标签: iphone objective-c cocos2d-iphone selector

请帮助我,我在objective-c

中非常新

我有2个最简单的课程(第一个,第二个)

我想在第二类中设置 rolypoly 对象的 offsetx 属性,如 self.rolypoly.offsetx = 1 或运行使用 [self.rolypoly setOffx]; 做某事,但我总是有错误:

尝试[self.rolypoly setOffx];在第二课

- [CCScene setOffx:]:无法识别的选择器发送到实例0x91d0b70'

尝试self.rolypoly.offsetx = 1;在第二课

- [CCScene setOffsetx:]:无法识别的选择器发送到实例0x808bfc0'

头等舱

//************************************************************ 
       #import <Foundation/Foundation.h>
        #import "cocos2d.h"

        @interface RolyPoly : CCLayer {

            CCAction *_walkAction; 
            CCSprite *_rolypoly;
            int offsetx;
            int offsety;
        }

        @property (nonatomic, retain) CCSprite *rolypoly;
        @property (nonatomic, retain) CCAction *walkAction;
        @property (nonatomic, assign) int offsetx;
        @property (nonatomic, assign) int offsety;

        +(id) scene;
        -(void) setOffx;
        @end
//************************************************************     
        #import "GameLayer.h"
        #import "RolyPoly.h"

        @implementation RolyPoly

        @synthesize rolypoly = _rolypoly;
        @synthesize walkAction = _walkAction;
        @synthesize  offsetx = _offsetx;
        @synthesize  offsety = _offsety;

        +(id) scene
        {
            CCScene *scene = [CCScene node];

            RolyPoly *layer = [RolyPoly node];

            [scene addChild: layer];

            return scene;
        }

        -(id) init
        {
            if ((self = [super init]))
            {

                [self scheduleUpdate];
            }
            return self;
        }
        -(void) setOffx
        {

            NSLog(@"setOffx");
        }

        -(void) update:(ccTime)delta
        {

        }
        - (void) dealloc
        {
            self.rolypoly = nil;
            self.walkAction = nil;
            [super dealloc];
        }
        @end

第二课

//************************************************************ 
    #import <Foundation/Foundation.h>
    #import "cocos2d.h"
    #import "RolyPoly.h"


    @interface GameLayer : CCLayer {

        RolyPoly *_rolypoly;
    }

    // returns a CCScene that contains the HelloWorldLayer as the only child
    +(CCScene *) scene;
    @property (nonatomic, assign) RolyPoly * rolypoly;

    @end

//************************************************************   
    #import "GameLayer.h"
    #import "RolyPoly.h"

    // HelloWorldLayer implementation
    @implementation GameLayer

    @synthesize  rolypoly = _rolypoly;

    +(CCScene *) scene
    {
        CCScene *scene = [CCScene node];
        GameLayer *layer = [GameLayer node];
        [scene addChild: layer];
        return scene;
    }

    -(id) init
    {
        if( (self=[super init])) {

            CGSize screenSize = [[CCDirector sharedDirector] winSize];

            self.rolypoly = [RolyPoly scene];
            [self addChild:self.rolypoly z:1];
            [self.rolypoly setOffx];
            [self scheduleUpdate];

        }
        return self;
    }


    - (void)update:(ccTime)dt {

    }

    - (void) dealloc
    {
        [super dealloc];
    }
    @end

1 个答案:

答案 0 :(得分:0)

你的问题在于你将CCScene对象传递给你的rolyPoly变量,而不是rolyPoly对象。

    +(id) scene
    {
        CCScene *scene = [CCScene node];

        RolyPoly *layer = [RolyPoly node];

        [scene addChild: layer];

        return scene;
    }

返回场景;

删除RolyPoly类中的场景方法,并在场景中使用它

       self.rolypoly = [RolyPoly node];