我是 Spritebuilder 的新手,正在尝试制作 MARIO 游戏原型。我正在做的是我有 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);
_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