基于碰撞的动画变化

时间:2014-04-15 08:41:24

标签: sprite-kit

大家好我正在做一个精灵套装游戏,我希望一旦我的子弹击中对手/敌人在这种情况下,我想要敌人垂死的动画播放,但我在朋友的帮助下写的代码,给了我麻烦。它运行着垂死的动画而根本没有子弹击中它。

@implementation MyScene {
///////// PLAYER VARIABLES ///////////////////
SKSpriteNode *_Player;
NSArray *_PlayerAnimation;
SKSpriteNode *MyBackground;
SKLabelNode  *MyScoreLabel;
SKSpriteNode *cannonbullet;
SKSpriteNode *bullet;
BOOL fireCannon;
CGPoint destination;
NSArray *_enemy;
BOOL EnemyHit;
}



- (id) initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        Enemyhit = false;
    if (Enemyhit == true) {
        [self CollisionWithEnemy];
    }
  }
return self;
}

- (void) EnemyDyingAnimation {
    /////////// This section is only for enemy's dying animation //////////
    NSMutableArray *EnemyBlowingFrames = [NSMutableArray array];
    SKTextureAtlas *EnemyAnimatedAtlas = [SKTextureAtlas atlasNamed:@“enemyFolder"];
    int numFrames = EnemyAnimatedAtlas.textureNames.count;
    for (int i=1; i <= numFrames/2; i++) {
       NSString *textureName = [NSString stringWithFormat:@“enemy%d", i];
       SKTexture *temp = [EnemyAnimatedAtlas textureNamed:textureName];
       [EnemyBlowingFrames addObject:temp];
    }
    _enemy = EnemyBlowingFrames;
    SKTexture *temp2 = _enemy[0];
    Enemy = [SKSpriteNode spriteNodeWithTexture:temp2];
    Enemy.position = CGPointMake(self.size.width/2, self.size.height/2);
    Enemy.name = @"ForEnemy";
    [self addChild:Enemy];
}
- (void) CollisionWithEnemy {
    [self enumerateChildNodesWithName:@"ForEnemy" usingBlock:^(SKNode *node, BOOL *stop){
    bullet = (SKSpriteNode *)node;
    if (CGRectIntersectsRect(bullet.frame, Enemy.frame)) {
        Enemyhit = true;
        [Enemy runAction:[SKAction animateWithTextures:_enemy timePerFrame:0.1f   resize:NO restore:NO] withKey:@“Ehit"]; return;
    }
}];
}

0 个答案:

没有答案