0

仅运行以下代码 r 和 entity 会旋转,但enemyEntity 不会。我在 rotateBy 的更新方法中添加了一个调用,并仅在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];

Entity 和 EnemyEntity(Entity 的子类)的标头:

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
4

1 回答 1

0

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

谢谢!

于 2012-09-26T08:25:47.133 回答