现在,我的班级看起来像
@interface Character : SKNode @property (nonatomic,assign) CGFloat walkingSpeed;
@implementation Character
+(Character*)characterWithLevel:(BaseLevel *)level { return [[self alloc] initWithLevel:level]; } -(id)initWithLevel:(BaseLevel*)level { if (self = [super init]) { _sprite = [SKSpriteNode spriteNodeWithImageNamed:level.heroTexture]; _sprite.position = level.heroStartingPosition; [self addChild:_sprite]; [level addChild:self]; } return self; }
问题是,当对级别中的Character节点运行操作时,由于SpriteNode是动画的,因此它不会做任何事情.我想知道你们怎么会遇到这些问题?
行动举例:
触摸事件:
CGPoint location = [[touches anyObject] locationInNode:self]; [character moveToPosition:location];
里面的角色类
-(void)move { [self runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:[self walkFrames] timePerFrame:0.1f resize:NO restore:YES]] withKey:@"moving"]; return; }
这没有任何作用.只有我可以让它工作的方法是如果Character是SKSpriteNode的子类.对self.sprite运行操作似乎也有点hacky并且节点本身不会移动.
有什么建议?