简体   繁体   English

C#XNA 2D Platformer跳跃问题

[英]C# XNA 2D Platformer Jumping issue

I'm currently working on a remake of Super Mario World in C# with some friends for a school project. 我目前正在与一些朋友一起在C#中翻拍《超级马里奥世界》,以进行学校项目。

We got jumping roughly working, at least it goes up and down... the thing is, well, see for yourself: 我们的工作大致上是跳跃的,至少它是上下波动的……事情是,亲眼所见:

https://gyazo.com/f49886ea48a0653b801d6c0741709fea Here is an animated gif of the problem. https://gyazo.com/f49886ea48a0653b801d6c0741709fea这是问题的动画gif。

It boosts up extremely fast, almost instantly and then slowly glides down. 它以极快的速度升压,几乎立即启动,然后缓慢下滑。 I tried changing gravity and jumpboost values but even though I partially fixed the gliding, I keep almost teleporting up. 我尝试更改重力和跳跃升力值,但是即使我部分固定了滑行,我仍保持向上移动。 I can't seem to smooth out the jumping... 我似乎无法消除跳跃...

Here is the full player class: http://pastebin.com/bCjCB2q8 这是完整的播放器类: http : //pastebin.com/bCjCB2q8

I can't find the problem, maybe one of you could help me to see where I go wrong in my way of thinking? 我找不到问题,也许你们中的一个可以帮助我看看我的思维方式出了什么问题?

I would usually implement basic newtonian movement with accelleration and velocity (Vector2). 我通常会使用加速和速度(Vector2)来实现基本的牛顿运动。

for every update, you start with Acceleration = Vecotr2.Down * Gravity; 对于每次更新,都从Acceleration = Vecotr2.Down * Gravity开始; and you end with Velocity += Acceleration * gameTime; 然后以Velocity + = Acceleration * gameTime结尾; Position += Velocity * gameTime; 位置+ =速度* gameTime;

gameTime = total elapsed seconds since last update. gameTime =自上次更新以来经过的总秒数。 This is important to let numbers for acceleration and velocity stay in a consistent frame that make sense for humans. 重要的是要使加速度和速度的数字保持对人类有意义的一致框架。 Basicly acceleration is change in velocity per second, while velocity is change in position per second. 基本上,加速度是每秒的速度变化,而速度是每秒的位置变化。

To jump, you set Acceleration.Y = JumpSpeed / gameTime; 要跳跃,请设置Acceleration.Y = JumpSpeed / gameTime; //JumpSpeed = desired upwards velocity. // JumpSpeed =所需的向上速度。 the / gameTime nulls out the * gameTime when calculating velocity. 在计算速度时,/ gameTime使* gameTime无效。

Afraid this answer might be a bit thin. 害怕这个答案可能会有点薄。 I can embelish when I get home from work... :) 我下班回家时可以点缀... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM