1
我已经做了与我的地图碰撞工作的碰撞,但是当我的球员有碰撞时,我停止球员的运动,他不走路,因为我不知道怎么的一个方向停止播放碰撞工作,但我不知道如何知道collsiion方向
玩家和图规定的我的代码碰撞
public bool IsCollisionTile(Rectangle player)
{
foreach(Rectangle rect in this._collisionObject)
{
if (rect.Intersects(player))
{
return true;
}
}
return false;
}
它的玩家不要移动代码在Game1类
if (mapLoader.IsCollisionTile(player.getDestinationRect()))
{
player.setCantWalk(true);
}
和其在类Player.cs
private bool _cantWalk;
public void Update()
{
this._destinationRectangle.X = (int)_position.X;
this._destinationRectangle.Y = (int)_position.Y;
this._destinationRectangle.Width = _texture.Width;
this._destinationRectangle.Height = _texture.Height;
if(Keyboard.GetState().IsKeyDown(Keys.Up))
{
if (_cantWalk == false)
{
_position.Y--;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
if (_cantWalk == false)
{
_position.Y++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
if (_cantWalk == false)
{
_position.X++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
if (_cantWalk == false)
{
_position.X--;
}
}
}
public void setCantWalk(bool walk)
{
_cantWalk = walk;
}
思帮我
您可以尝试在X轴上移动您的播放器,进行碰撞检查,然后再按Y轴再次进行检查,然后将其中一个s)导致检查...似乎不理想,但它是一个选项 –
你好,但我是一个初学者,我不知道该怎么办 –