Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an object that can move in any direction(user define) but as you can see, it doesn't move smoothly.
how can I improve this movement.
here is a video of this object movement.

bandicam 2022-06-12 10-43-26-451.mp4 - Google Drive[^]


 private void timer2_Tick_1(object sender, EventArgs e)
       {
           float xpos,yapos,yspos,dif;
           double atheta;
           if (aireplane1.Top >= brec.Top + 10)
           if (startmove && !airisdragging)
           {

                   Size aireplane_size =aireplane1.Size;
                   if (keynum>0 && keynum<180) {
                   atheta =  Math.Atan2(aireplane1.Location.Y , aireplane1.Location.X);
                  atheta = atheta *180 / Math.PI;
yspos = -(float)Math.Tan(Math.PI/2- keynum * (Math.PI / 180)) * aireplane1.Location.X;
                   dif = yspos-aireplane1.Location.Y;


 xpos =( aireplane1.Location.X)+2;
                   yspos = -(float)Math.Tan(Math.PI / 2-keynum * (Math.PI / 180)) * xpos;
                   yapos = yspos - dif;
                   aireplane1.SetBounds((int)xpos,(int)(yapos),aireplane_size.Width,aireplane_size.Height);
                   }
                   else if (keynum >180 && keynum < 360)
                   {
                       atheta = Math.Atan2(aireplane1.Location.Y, aireplane1.Location.X);
                       atheta = atheta * 180 / Math.PI;
                       yspos = -(float)Math.Tan(Math.PI / 2 - keynum * (Math.PI / 180)) * aireplane1.Location.X;
                       dif = yspos - aireplane1.Location.Y;


                       xpos = (aireplane1.Location.X) - 2;
                       yspos = -(float)Math.Tan(Math.PI / 2 - keynum * (Math.PI / 180)) * xpos;
                       yapos = yspos - dif;
                       aireplane1.SetBounds((int)xpos, (int)(yapos), aireplane_size.Width, aireplane_size.Height);


                   }
               }

       }


keeynum is user angle input.

by changing time intervals the movement become smoother but still the background of the path of airplane change when it across it, how can I fix this?

bandicam 2022-06-13 17-18-00-689.mp4 - Google Drive[^]

What I have tried:

I didn't do anything more than this
Posted
Updated 13-Jun-22 2:52am
v3
Comments
Richard MacCutchan 12-Jun-22 3:27am    
You need to adjust the timer interval and the distance to move in order to get smooth changes.
Ali Valizadegan 12-Jun-22 3:29am    
indeed of time intervals, as you can see, the background of airplane has small vibrations, I want to decrease them
Richard MacCutchan 12-Jun-22 3:33am    
The only way to find the optimum values is by trial and error. At the moment it appears that the aircraft moves every second. This interval is too large, and maybe the distance is also. So change the timer interval to half its current value and see what happens. Do the same with the distance moved until you get the performance you want.
Richard MacCutchan 13-Jun-22 9:32am    
You need to check your paint handler to ensure that you repaint the background each time before you paint the aircraft.
Ali Valizadegan 21-Jun-22 11:10am    
I tried this too but my problem didn't solve.

1 solution

Maybe you can use this CodeProject visual effects library: Control Animation in Winforms[^]
Or this one: Fluent and Imperative Animations[^]

For more ambitious cross-platform projects you could use a game engine like MonoGame[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900