2014-08-29 63 views
0

我是Spritebuilder的新手,并试图制作MARIO游戏原型。我正在做的是我有2个精灵,一个精灵拥有快速走路的角色,另一个拥有正常的走路角色。我正在通过一个按钮更改精灵。当我点击按钮时,正常步行精灵将被快速步行精灵所替代,并再次点击该按钮时会出现正常精灵。CCSprite没有响应碰撞

问题:

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

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

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); 



     [email protected][@"character"]; 
     [email protected][@"ground"]; 
     [email protected]"ground"; 
     _ground.physicsBody.elasticity=0; 
     [email protected]"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); 


     [email protected][@"fastCharacter"]; 
     [email protected][@"ground"]; 
     _ground.physicsBody.elasticity=0; 
     [email protected]"ground"; 
     [email protected]"fastCharacter"; 
     _fastCharacter.physicsBody.elasticity=0; 
     _physicsNode.iterations=1000; 

     _character=nil; 
    } 
} 

这里是链接到调试平局的视频:https://www.dropbox.com/s/vt557ngpyj6z9g3/DebugDraw.mp4?dl=0

+0

请发布与问题相关的代码。此外,您可能需要录制该视频,但启用了物理调试绘图功能,以便更好地了解碰撞形状以及它们在玩家击中地面时重叠的原因。 – LearnCocos2D 2014-08-29 10:13:06

回答

-1

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

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