Search code examples
inheritancecocos2d-iphonesubclassrotateanimation

Cocos2d: sub-subclass of CCSprite would not rotate


running the following code only r and entity would rotate but enemyEntity wouldn't. I added a call in the update method of rotateBy and run rotateBy only on enemyEntity and it would call it and changing the angle but not displaying the effect. I think is an inheritance issue. I post the code below and the headers at the bottom of this page. Any suggestions?

    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];

Headers of Entity and EnemyEntity (subclass of 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

Solution

  • I rewrote the code from scratch and now it does rotate. Was probably as suggested by @LearnCocos2D: "Check if there's any other code running that might reset rotation. You could set a breakpoint on the CCNode rotation property.".

    Thanks!