Objective c 运行操作在CCNode内不工作

Objective c 运行操作在CCNode内不工作,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,我有一个从CCNode继承的类。这个类有两个ccsprite。当CCNode初始化时,我希望在两个ccsprite上运行两个操作,但是这些操作被跳过 两个CCSprite变量是infoPanel和bg 标题: //THIS IS NOT WORKING #import "cocos2d.h" @interface GamePopUp : CCSprite <CCTargetedTouchDelegate> @property (strong,rea

我有一个从CCNode继承的类。这个类有两个ccsprite。当CCNode初始化时,我希望在两个ccsprite上运行两个操作,但是这些操作被跳过

两个CCSprite变量是infoPanel和bg

标题:

      //THIS IS NOT WORKING

#import "cocos2d.h"

    @interface GamePopUp : CCSprite <CCTargetedTouchDelegate> 

    @property (strong,readwrite) CCSprite* infoPanel;
    @property (strong,readwrite) CCSprite* bg;

 +(id)PopupInfo;
 -(id)initForInfoPopup;
 -(void)onEnter;
 -(void)onExit;
 -(void) rotate;

 @end
  //THIS IS WORKING
  #import "cocos2d.h"

@interface PopUp : CCSprite {
  CCSprite *window,*bg;
  CCNode *container;
}

+(id)popUpWithTitle: (NSString *)titleText description:(NSString *)description sprite:(CCNode *)sprite;
- (id)initWithTitle: (NSString *)titleText description:(NSString *)description sprite:(CCNode *)sprite;

-(void)closePopUp;

@end
有趣的是,我在一个教程中找到的另一个类也适用同样的方法。那门课是从雪碧那里继承来的

标题:

      //THIS IS NOT WORKING

#import "cocos2d.h"

    @interface GamePopUp : CCSprite <CCTargetedTouchDelegate> 

    @property (strong,readwrite) CCSprite* infoPanel;
    @property (strong,readwrite) CCSprite* bg;

 +(id)PopupInfo;
 -(id)initForInfoPopup;
 -(void)onEnter;
 -(void)onExit;
 -(void) rotate;

 @end
  //THIS IS WORKING
  #import "cocos2d.h"

@interface PopUp : CCSprite {
  CCSprite *window,*bg;
  CCNode *container;
}

+(id)popUpWithTitle: (NSString *)titleText description:(NSString *)description sprite:(CCNode *)sprite;
- (id)initWithTitle: (NSString *)titleText description:(NSString *)description sprite:(CCNode *)sprite;

-(void)closePopUp;

@end
实施:

    - (id)initWithTitle: (NSString *)titleText description:(NSString *)description sprite:(CCNode *)sprite {
    self = [super init];
    if (self) {

     _ourDevice = [[DimensionManager SharedDimensionManager]OurDevice];

    CGSize s = [[CCDirector sharedDirector] winSize];
    container = sprite;
    CCLabelTTF *desc;
      int fSize = 36;

    if (_ourDevice == iPhone)
    {
    window = [CCSprite spriteWithFile:@"uglyPopup.png"];


         desc = [CCLabelTTF labelWithString:description fontName:@"TOONISH" fontSize:fSize/2];
    }else {
        window = [CCSprite spriteWithFile:@"uglyPopup-hd.png"];   
          desc = [CCLabelTTF labelWithString:description fontName:@"TOONISH" fontSize:fSize];
    }

    window.opacity = 160;
    bg = [CCSprite node];
    bg.color = ccBLACK;
    bg.opacity = 0;
    [bg setTextureRect:CGRectMake(0, 0, s.width, s.height)];
    bg.anchorPoint = ccp(0,0);
    [bg disableTouch];
    window.position = ccp(s.width/2, s.height/2);
    window.scale = 1;


    desc.position = ccp(window.position.x, window.position.y + window.contentSize.height / 2.2);
    desc.opacity = (float)255 * .75f;

    [window addChild:desc];
    [self addChild:bg z:-1 tag:tBG];
    [self addChild:window];
    [window addChild:container z:2];

    //THESE ACTIONS RUN:
    [bg runAction:[CCFadeTo actionWithDuration:ANIM_SPEED / 2 opacity:150]];
    [window runAction:[CCSequence actions:
                           [CCScaleTo actionWithDuration:ANIM_SPEED /2 scale:.9],
                           [CCScaleTo actionWithDuration:ANIM_SPEED /2 scale:.8],
                           nil]];


    }

    return self;
}

尝试在OneNet函数中运行操作,如果对象的isRunning布尔值为否,则操作将不会运行

- (void) onEnter
{
    [super onEnter];
    //These actions do not take place:
    [bg runAction:[CCFadeTo actionWithDuration:4 opacity:250]];
    [infoPanel runAction:[CCSequence actions:
                          [CCScaleTo actionWithDuration:4 scale:3],
                          [CCScaleTo actionWithDuration:4 scale:1],
                          nil]];
}

我也有同样的问题,但结果不是
onEnter
问题。我的问题是在我的
CCNode
中嵌套了三个
ccsprite
,并且正在向顶级节点发送runAction。我的问题的解决方案很简单:

在顶级
CCNode
上将
cascadepacityenabled
标志设置为
YES

buyBuildingDialog.cascadeOpacityEnabled = YES;
[buyBuildingDialog runAction:[CCActionFadeIn actionWithDuration:0.25]];

嗯,我的isRunning是否定的。即使当onEnter被激活。它不可能是,在[super onEnter]之后;调用isRunning为YES,检查ccNode类中的onEnter函数,最后一条语句为isRunning_u2;=YES;只添加[super-oneter]就足以让init中的操作正常工作。剩下的在Onener中是不需要的。