仅运行以下代码 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