CCSprite没有响应Collision

时间:2014-08-29 09:57:26

标签: ios cocos2d-iphone spritebuilder cocos2d-iphone-3

我是Spritebuilder的新手并试图制作MARIO游戏原型。我正在做的是我有2个精灵,一个精灵有快速行走的角色,而另一个有正常的行走角色。我正在通过一个按钮更改精灵。当我点击按钮时,正常行走的精灵被快速行走的精灵所取代,再次单击该按钮会使正常的精灵出现。

问题:

  1. 在游戏开始的第一次,在跳跃时在地面和角色之间检测到碰撞。但是只要我将精灵更改为快速行走角色,就不会在跳跃时检测到碰撞。当我再次切换回正常行走角色时,跳跃时也没有检测到碰撞。

  2. 当我让精灵跳跃并开始摔倒时,观察某种活动(我宁愿说弹跳),我也不能说它是否弹回。我不知道它为什么会来,以及如何纠正它。我搜索了堆栈溢出和一些论坛。我发现的是使用

  3. CCPhysicsBody.iterations

    但我不知道如何使用它。 有关更详细的说明,您可以在此链接中查看视频,以了解完整问题。 https://www.dropbox.com/s/0fz3qehie76r60k/Game.mp4?dl=0

    请帮忙。欢迎任何建议。

    编辑:这是我改变精灵的代码:

    -(void)setCharacterAnimationFast
    {
        if (_turboButton.selected)
        {
            //changing button state;
            _turboButton.selected=NO;
    
            //changing value of background speed from screen;
            speeedParameter = 50.0;
            speedParameterOfBackgroundObjects=10.0;
    
            //loading new chracter
            _character =(RightCharacter*)[CCBReader load:@"RightCharacter"];
    
            //position the laser at helicopter origin
            CGPoint _characterPosition = _fastCharacter.position;
    
            //transform the world position to the node space to which the laser will be added (_physicsNode)
            _character.position = [_physicsNode convertToNodeSpace:_characterPosition];
    
            //defining zorder for moving it to background
            _character.zOrder= _fastCharacter.zOrder;
    
            // add the laser to the physicsNode of this scene (because it has physics enabled)
            [_physicsNode addChild:_character];
    
            //removing the existing character
            [_fastCharacter removeFromParentAndCleanup:YES];
    
    
    
            CCLOG(@"ground : %@", _ground);
            CCLOG(@"ground : %@", _ground.physicsBody);
            CCLOG(@"ground : %@", _ground.physicsNode);
    
    
    
            _ground.physicsBody.collisionMask=@[@"character"];
            _character.physicsBody.collisionMask=@[@"ground"];
            _ground.physicsBody.collisionType=@"ground";
            _ground.physicsBody.elasticity=0;
            _character.physicsBody.collisionType=@"character";
            _character.physicsBody.elasticity=0;
            _physicsNode.iterations=1000;
    
            _fastCharacter=nil;
        }
        else
        {
            //changing button state
            _turboButton.selected=YES;
    
            //changing value of background speed from screen;
            speeedParameter = 80.0;
            speedParameterOfBackgroundObjects= 20.0;
    
            //loading new fast character
            _fastCharacter =(RightCharacterFast*)[CCBReader load:@"RightCharacterFast"];
    
            //position the laser at helicopter origin
            CGPoint _fastCharacterPosition = _character.position;
    
            //transform the world position to the node space to which the laser will be added (_physicsNode)
            _fastCharacter.position = [_physicsNode convertToNodeSpace:_fastCharacterPosition];
    
            //defining zorder for moving it to background
            _fastCharacter.zOrder= _character.zOrder;
    
            // add the laser to the physicsNode of this scene (because it has physics enabled)
            [_physicsNode addChild:_fastCharacter];
    
            //removing the existing character
            [_character removeFromParentAndCleanup:YES];
    
    
    
            CCLOG(@"ground : %@", _ground);
            CCLOG(@"ground : %@", _ground.physicsBody);
            CCLOG(@"ground : %@", _ground.physicsNode);
    
    
            _ground.physicsBody.collisionMask=@[@"fastCharacter"];
            _fastCharacter.physicsBody.collisionMask=@[@"ground"];
            _ground.physicsBody.elasticity=0;
            _ground.physicsBody.collisionType=@"ground";
            _fastCharacter.physicsBody.collisionType=@"fastCharacter";
            _fastCharacter.physicsBody.elasticity=0;
            _physicsNode.iterations=1000;
    
            _character=nil;
        }
    }
    

    以下是调试绘图视频的链接:https://www.dropbox.com/s/vt557ngpyj6z9g3/DebugDraw.mp4?dl=0

1 个答案:

答案 0 :(得分:-1)

使用相同的代理主体节点进行冲突,使用较少密集的节点进行冲突非常有效:

characterNode.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];
fastWalkingCharacterNode.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];