简体   繁体   中英

C# Windows Forms Platform Game, Jumping while moving to the right/left is getting canceled and doesnt look smooth

I am working on a Jump and Run and got the Problem if I'm walking to the right/left while holding the (A/D-Key) and then press W to Jump, the moving process to the left/right is getting canceled and I have to repress the A/D Button to continue walking. Do you know any solution for it?

Another question is if somebody knows a good Website for some animated Characters as .GIF for moving right, standing still, moving left and for jumping Source-Code:

private void Tutorial_KeyDown(object sender, KeyEventArgs e){
if (e.KeyCode == Keys.W)
{
 b_Jump = true;
 Movement.Enabled = true;
}
else if (e.KeyCode == Keys.A || e.KeyCode == Keys.Left)
{
 b_Left = true;
 Movement.Enabled = true;
}
else if (e.KeyCode == Keys.D || e.KeyCode == Keys.Right)
{
 b_Right = true;
 Movement.Enabled = true;
}

}

private void Movement_Tick(object sender, EventArgs e)

{

if(b_Left == true)
{
 Spieler.Left -= i_Geschwindigkeit;
 Movement.Enabled = false;
}
else if (b_Right == true)
{
 Spieler.Left += i_Geschwindigkeit;
 Movement.Enabled = false;
}

else if (b_Jump == true)
{
 Sprunganstieg.Enabled = true;
 Sprungabfall.Enabled = true; <- Just makes the Playermodel reach the Ground 
 b_Jump = false;                 after a small delay

}

}

Windows Forms is not the right tool for game development. You can use it for purely turnbased games with single or hotseat multiplayer within limits. The old Solitaire is at or ever close to the maximum possible. Latest when you try to do complex animation, you run into issues like these.

If you want to do proper Game Development, XNA is the somewhat dated tool for the .NET Framework. Otherwise you should look wich of those options your target framework supports: https://www.microsoft.com/net/learn/apps/gaming But in the end, anything that has a game loop should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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