Анимация CCSprite останавливается при запуске другого действия в iOS Cocos2D v3.x

Я оживляю спрайт в своей игре (с помощью листов спрайтов и т. Д.). Это простая анимация, которую я хочу реализовать на протяжении всей игры. Спрайт также является физическим телом. И когда касаюсь экрана, я хочу, чтобы спрайт выполнил некоторые действия.

Я добавил анимацию и действия, и все в порядке. Но проблема в том, что анимация останавливается, когда спрайт выполняет другие действия (при касании).

Вот мой спрайт-код в init метод:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"plane1.plist"];

NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i)
{
    [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"planee%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.1]; //Speed in which the frames will go at

//Adding png to sprite
plane = [CCSprite spriteWithImageNamed:@"plane1.png"];

//Positioning the sprite
plane.position  = ccp(self.contentSize.width/2,self.contentSize.height/2);

//Repeating the sprite animation
CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:walkAnim];
CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction];

//Animation continuously repeating
[plane runAction:repeatingAnimation];

//Adding the Sprite to the Scene
CGRect aRectangle = (CGRect){ccp(0,-10), plane.contentSize};
CGRect smallerRectangle = CGRectInset(aRectangle, 30, 20);
plane.physicsBody = [CCPhysicsBody bodyWithRect:smallerRectangle  cornerRadius:0];
plane.physicsBody.collisionGroup = @"playerGroup";
plane.physicsBody.collisionType  = @"planeCollision";
[_physicsWorld addChild:plane];

Вот мой touchBegan метод (где другие действия выполняются при касании экрана:

/*The following code makes the Plane go up when touched anywhere on the screen and then starts downward movement*/

[plane stopAllActions];

float currentRotation = plane.rotation;

if (currentRotation==10) {
   [plane runAction:[CCActionSequence actions:
                      [CCActionRotateBy actionWithDuration:.1 angle:-30],
                      [CCActionMoveBy actionWithDuration:.1 position:ccp(0,30)],
                      [CCActionRotateBy actionWithDuration:.2 angle:30],
                      [CCActionCallBlock actionWithBlock:
                       ^{
                           [self startDownMovement];


                       }],nil]
     ];
}

else {
    [plane runAction:[CCActionSequence actions:
                      [CCActionMoveBy actionWithDuration:.1 position:ccp(0,30)],
                      [CCActionRotateTo actionWithDuration:.1 angle:10],
                      [CCActionCallBlock actionWithBlock:
                       ^{
                           [self startDownMovement];


                       }],nil]
     ];

}

А вот и startDownMovement код:

float currentRotation = plane.rotation;

if (currentRotation!=10) {

    [plane runAction:[CCActionSequence actions:[CCActionRotateBy actionWithDuration:0.1 angle:30],
                      [CCActionMoveBy actionWithDuration:1 position:ccp(0,-plane.position.y)],
                      nil]];

}

else {
    plane.rotation = 10;
    [plane runAction:[CCActionMoveBy actionWithDuration:1 position:ccp(0,-plane.position.y)]];
}

Пожалуйста, помогите мне. Я понятия не имею, почему моя анимация останавливается, когда я касаюсь экрана, чтобы взлететь на самолет.

Спасибо в ожидании!

0 ответов

Другие вопросы по тегам