How to create a smooth animation using C# Windows forms?

别来无恙 提交于 2019-12-06 00:56:24

问题


due my school project I must create a game using Windows forms only..

I have decided to create a 2D racing game. So now I need to move the car image. To move it I tried to animate the car with the KeyDown event, however the animation is really Faltering.. So is there any other way to create animation? or is it possible to soomth it somehow? (For the car I use a PictureBox that Docked to the form and in its paint event im redrawing the car in the right window positions.)


回答1:


This post should solve your issues: simple-animation-using-c-windows-forms

He details how he went around coding animation in a windows form and covers some of your questions.

If that doesn't solve it, look up using some XNA libraries as Freeman said.




回答2:


From the details you provided, i can say this, if you wish to create a mini-game i would recommend you use WPF with some XNA libraries, because WinForms is not really cut out to enable a very impresive graphic experience, but rather it favours the creation simple GUI tools. Sometimes not even double buffering helps much.




回答3:


well you can make a movement-animation system

        int x = pictureBox1.Location.X;
        int y = pictureBox1.Location.Y;
        if (e.KeyCode == Keys.Right) x += 1;
        else if (e.KeyCode == Keys.Left) x -= 1;
        pictureBox1.Location = new Point(x, y);

to make it faster change the x+=1 x-=1 and y+=1 y-=1; to bigger numbers like y x-=3; so in this cod you yous the arrow keys but only the right and left because you will be driving foward reapeatedly so you only move right and left



来源:https://stackoverflow.com/questions/14499803/how-to-create-a-smooth-animation-using-c-sharp-windows-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!