vip clean objective-c animation sprite-kit

objective c - clean - Joystick Spritekit



vip model swift (1)

Parece que sigues llamando tu animación una y otra vez. Esto evitaría que la animación realmente se reproduzca más allá de los primeros cuadros.

Crea un BOOL que establecerías la primera vez que se ejecute la animación. Las llamadas posteriores a la animación verificarían el estado de BOOL y determinarían si la animación ya se está ejecutando. Puede restablecer BOOL una vez que el joystick ya no esté apuntando hacia la derecha.

Crea una propiedad BOOL:

@property (nonatomic) BOOL animationRunning;

Cuando los valores de su joystick indican que desea que su reproductor se ejecute correctamente, llame al método de animación:

[self runRightAnimation];

Antes de ejecutar la animación, se verifica el BOOL para ver si ya se está ejecutando:

-(void)runRightAnimation { if(animationRunning == NO) { animationRunning = YES; // your animation code... } }

Recuerda establecer tu animationRunning = NO; y detenga la animación cuando el joystick ya no esté en la posición deseada.

Estoy tratando de ejecutar algunas animaciones de mi sprite jugador cada vez que cambio la dirección del joystick.

Estoy usando la caída de TheSneakyNarwhal en la clase Joystick que usa los siguientes métodos:

if (joystick.velocity.x > 0) { [self walkRightAnim]; } else if (joystick.x < 0) { [self walkLeftAnim]; } if (joystick.velocity.y > 0) { [self walkUpAnim]; } else if (joystick.velocity.y < 0) { [self walkDownAnim]; } if (joystick.velocity.x == 0 && joystick.velocity.y == 0) { [self idleAnim]; } My [self walkRightAnim]; - (void)walkRightAnim { NSLog(@"%f", self.joystick.velocity.x); SKTexture *run0 = [SKTexture textureWithImageNamed:@"right1.png"]; SKTexture *run1 = [SKTexture textureWithImageNamed:@"right2.png"]; SKTexture *run2 = [SKTexture textureWithImageNamed:@"right3.png"]; SKAction *spin = [SKAction animateWithTextures:@[run0,run1,run2] timePerFrame:0.2 resize:YES restore:YES]; SKAction *runForever = [SKAction repeatActionForever:run]; [self.player runAction:runForever]; }

Sin embargo, siempre que la velocidad.x del joystick esté por encima de 0 (moviéndose hacia la derecha) sigue llamando al método desde el principio y no reproducirá la animación completa.

Solo cuando dejo de usar el joystick, reproduce toda la animación.