在操作/阻止时,CCSprite不会出现在屏幕上

时间:2015-01-14 04:33:32

标签: ios objective-c cocos2d-iphone objective-c-blocks ccsprite

您好我正在尝试用cocos2d-swift制作游戏,我想要的是当用户点击屏幕然后屏幕上的两个CCSprit停止并从场景中移除它们自己。一旦他们删除相同的精确精灵再次出现,但有一个随机的机会成为3个其他精灵(所有属性相同,除了颜色和类型)。问题是我的一切正常,代码正在正确的区域执行,但精灵没有出现在iPhone上。

以下是替换现有精灵的主要代码。

- (void)resetPerimeterShape {

[baseShape removeFromParent];
[innerShape removeFromParent];

id resetAction = [CCActionCallBlock actionWithBlock:^(void){

      baseShape = [CCSprite spriteWithImageNamed:baseShapeShape];
    baseShape.position = ccp(self.contentSizeInPoints.width/2,self.contentSizeInPoints.height/2);
    baseShape.color = baseShapeColor;
    baseShape.rotation = shapeZRotation;
    [baseShape setScale:baseShapeSize];
    [self addChild:baseShape];

    innerShape = [CCSprite spriteWithImageNamed:innerShapeShape];
    innerShape.position = ccp(self.contentSize.width/2,self.contentSize.height/2);
    innerShape.color = innerShapeColor;
    innerShape.rotation = shapeZRotation;
    [innerShape setScale:baseShapeSize];
    NSLog(@"starting");
    //this is running and outputting so i am 100% sure this function is called.
    [self addChild:innerShape];
    NSLog(@"done");




}];
id reRunAction = [CCActionCallBlock actionWithBlock:^(void){
    //endsscene wip
}];



[self runAction:[CCActionSequence actionWithArray:@[resetAction,reRunAction]]];

}

这是调用它的代码片段。

 else{
                //[self runAction:self.sounds];
                NSString *A = [self randomShape];
                NSString *B = [self randomShape];

                if ([A isEqualToString:B]) {
                    baseShapeShape = A;
                    innerShapeShape = A;

                }
                else {
                    baseShapeShape = @"SQUARE (1).png";
                    innerShapeShape = B;

                }


                innerShapeColor = [self randomColor];
                baseShapeColor = [self randomColor];
                shapeZRotation = [self randomRotation];
                [self resetPerimeterShape];
                nap = true;

            }

2 个答案:

答案 0 :(得分:0)

您是否忘了执行此操作?例如:

[self runAction:resetAction];

答案 1 :(得分:0)

找到解决方案我正在将精灵缩放为0,因此它基本上没有显示