【发布时间】:2011-03-08 04:20:20
【问题描述】:
在我的 XNA 游戏中(顺便说一下,我对 XNA 还很陌生)我想让我的玩家精灵登陆一个平台。我有一个继承自我的常规精灵类的玩家精灵类,以及用于 基本的不可玩的精灵东西,比如盒子、背景东西和平台。但是,我不确定如何实现让我的玩家精灵登陆平台的方法。
我的玩家精灵可以跳跃和移动,但我不知道在哪里以及如何检查它是否在我的平台精灵之上。
我的玩家精灵跳转方法在这里
private void Jump()
{
if (mCurrentState != State.Jumping)
{
mCurrentState = State.Jumping;
mStartingPosition = Position;
mDirection.Y = MOVE_UP;
mSpeed = new Vector2(jumpSpeed, jumpSpeed);
}
}
mStartingPosition 是玩家精灵跳跃的起始位置,Position 是玩家精灵当前的位置。我认为我的代码用于检查我的玩家精灵是否在我的平台精灵之上。我不确定如何在 playersprite 类和 jump 方法中引用我的平台精灵。
我觉得应该是这样的
//platformSprite.CollisonBox would be the rectangle around the platform, but im not
//sure how to check to see if player.Position is touching any point
//on platformSprite.CollisionBox
if(player.Position == platformSprite.CollisionBox)
{
player.mDirection = 0;
}
我对编程和 XNA 还是很陌生,其中一些逻辑我不太了解,因此我们将不胜感激:D
谢谢
【问题讨论】: