Ios 如何在两个对象之间连续移动精灵
我有三个精灵A、B和C A和C是对象 B是敌人的精灵。。。因此,设计如下。我需要B在A和C之间不断移动 A------------B------------C 我在更新方法中使用以下方法。这样就可以为每个帧调用方法Ios 如何在两个对象之间连续移动精灵,ios,cocos2d-iphone,boolean,box2d-iphone,Ios,Cocos2d Iphone,Boolean,Box2d Iphone,我有三个精灵A、B和C A和C是对象 B是敌人的精灵。。。因此,设计如下。我需要B在A和C之间不断移动 A------------B------------C 我在更新方法中使用以下方法。这样就可以为每个帧调用方法 ABcollision { if(Aistouched == YES) { Bvelocity.x = 5; /// moves my sprite B right side } } CBcollision { if(Cistouched == YES) { Bvelocity.
ABcollision
{
if(Aistouched == YES)
{
Bvelocity.x = 5; /// moves my sprite B right side
}
}
CBcollision
{
if(Cistouched == YES)
{
Bvelocity.x = -5; /// moves my sprite B right side
}
}
更新速度的我的更新方法:
b2Vec2 dins = dinobody->GetLinearVelocity();
dinobody->SetLinearVelocity(Bvelocity);
上面的代码使我的精灵B只向左和向右移动一次。我认为,当它只工作一次时,问题在于你从未根据我的判断重置你的布尔值
AISMothed
和CISMothed
。尝试在设置Bvelocity.x=5之后添加aisstoucted=FALSE
代码>和C相同。您还可以为您的移动方法提供代码吗?问题可能在于没有上一步。创建一个新的变量名previousStep,每次使用Bvelocity更新位置之前,使用Bvelocity更新previousStep,如果发生碰撞,则在更改速度之前将B向后移动一步。我更新了我的问题..如何在box2d中向后移动一步?