Inheritance Cocos2d:CCSprite的子类不会旋转

Inheritance Cocos2d:CCSprite的子类不会旋转,inheritance,cocos2d-iphone,subclass,rotateanimation,Inheritance,Cocos2d Iphone,Subclass,Rotateanimation,运行以下代码时,只有r和entity会旋转,但enemyEntity不会。我在rotateBy的update方法中添加了一个调用,并仅在enemyEntity上运行rotateBy,它将调用它并更改角度,但不显示效果。我认为这是一个继承问题。我将下面的代码和标题张贴在本页底部。有什么建议吗 CCSprite *r = [CCSprite spriteWithFile:@"redRingRight.png"]; r.anchorPoint = CGPointMake(0.5f, 0

运行以下代码时,只有r和entity会旋转,但enemyEntity不会。我在rotateBy的update方法中添加了一个调用,并仅在enemyEntity上运行rotateBy,它将调用它并更改角度,但不显示效果。我认为这是一个继承问题。我将下面的代码和标题张贴在本页底部。有什么建议吗

    CCSprite *r = [CCSprite spriteWithFile:@"redRingRight.png"];
    r.anchorPoint = CGPointMake(0.5f, 0.5f);
    r.position = CGPointMake(160.0f, 60.0f);         
    [r runAction:[CCRotateBy actionWithDuration:2.0f angle:100]];
    [self addChild:r z:0 tag:77];


    Entity * entity = [Entity spriteWithFile:@"redRingRight.png"];
    entity.anchorPoint = CGPointMake(0.5f, 0.5f);
    entity.position = CGPointMake(160.0f, 200.0f); 

    [entity runAction: [CCRotateBy actionWithDuration:2.0f angle:100]];

    [self addChild:entity];

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"game-art-hd.plist"];

    EnemyEntity * enemyEntity = [EnemyEntity enemyWithType:Boss];
    enemyEntity.visible = TRUE;
    enemyEntity.anchorPoint = CGPointMake(0.5f, 0.5f);
    enemyEntity.position = CGPointMake(160.0f, 300.0f);
    [enemyEntity runAction: [CCRotateBy actionWithDuration:2.0f angle:100]];        

    [self addChild:enemyEntity];
    //[self scheduleUpdate];
实体和EneMeyEntity的标题(实体的子类):

Entity.h
#进口
#导入“cocos2d.h”
@类组件;
@接口实体:CCSprite
{
}
@结束
灌肠性
#进口
#导入“实体.h”
类型定义枚举
{
...,
老板,
..    
}灌肠类型;
@接口EnemyEntity:实体
{
灌肠类型;
}
+(id)enemyWithType:(EnemyTypes)enemyType;
-(空)产卵;
@结束

我从头重写了代码,现在它确实在旋转。可能正如@learncos2D:所建议的那样:“检查是否有任何其他正在运行的代码可能会重置旋转。您可以在CCNode旋转属性上设置断点。”


谢谢

我能看到的唯一区别是,在作为子对象添加它之前,您设置了enemyEntity.visible,尽管我无法理解这会如何影响旋转!检查是否有任何其他正在运行的代码可能会重置旋转。你可以在CCNode rotation属性上设置一个断点。我今晚快速查看了一下,但找不到太多,我现在太累了。明天我会正确地检查代码。我运行了其他动作,比如CCBlink,它们似乎很有效。我希望LearnCos2D是正确的:)。同时谢谢你
Entity.h


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

@class Component;

@interface Entity : CCSprite 
{
}


@end


EnemyEntity.h

#import <Foundation/Foundation.h>
#import "Entity.h" 

typedef enum
{
  ...,
  Boss,
  ..    
} EnemyTypes;

@interface EnemyEntity : Entity
{
    EnemyTypes type;

}
+(id) enemyWithType :(EnemyTypes)enemyType ;
-(void) spawn;

@end