Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat best represents a character SKNode or SKSpriteNode?
    text
    copied!<p><img src="https://i.stack.imgur.com/Y3tjm.png" alt="enter image description here">Currenty, my class looks something like</p> <pre><code>@interface Character : SKNode @property (nonatomic, assign) CGFloat walkingSpeed; </code></pre> <p>@implementation Character</p> <pre><code>+(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; } </code></pre> <p>Problem is, when running actions against a Character node in the level, it simple won't do anything due to the fact that the SpriteNode is the one being animated. I'm wondering how would you guys approach these kind of problems?</p> <p>Example of action:</p> <p>On touch event:</p> <pre><code>CGPoint location = [[touches anyObject] locationInNode:self]; [character moveToPosition:location]; </code></pre> <p>Inside Character class</p> <pre><code>-(void)move { [self runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:[self walkFrames] timePerFrame:0.1f resize:NO restore:YES]] withKey:@"moving"]; return; } </code></pre> <p>This doesn't do anything. Only way I can get it to work is if Character was a subclass of SKSpriteNode. Running the action against self.sprite also seems kind of hacky and the node itself won't move.</p> <p>Any suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload