smooth motion
-
hi all genius people! my app has picture boxes or labels moving through the whole form in various directions. to do this i am placing the code below to a timer of interval = 1 ms pic1.left += some constant pic1.top += some constant when this constant is 1 the motion is quite smooth but when this constant has a larger value say 5 then the motion is rough i tried using loops like this and placing it in the same timer for x = 1 to 5 pic1.left += 1 pic1.top += 1 next x but as my app has many pic boxes and this timer runs for about 2 mins (=2*60*60*1000 ms) this takes a lot of cpu any ideas?? my sole intention is to make the motion smooth thankx
TheMrProgrammer
-
hi all genius people! my app has picture boxes or labels moving through the whole form in various directions. to do this i am placing the code below to a timer of interval = 1 ms pic1.left += some constant pic1.top += some constant when this constant is 1 the motion is quite smooth but when this constant has a larger value say 5 then the motion is rough i tried using loops like this and placing it in the same timer for x = 1 to 5 pic1.left += 1 pic1.top += 1 next x but as my app has many pic boxes and this timer runs for about 2 mins (=2*60*60*1000 ms) this takes a lot of cpu any ideas?? my sole intention is to make the motion smooth thankx
TheMrProgrammer
The only way you're going to get smooth motion is to stop using controls to render all of your content, and even then, you might not get what you want, but it'll be a VAST improvement. You have to handle the Paint event of your form and draw all of your content yourself. Controls are too expensive to redraw and, from what I see if your small code snippet, you're not giving the form any time to redraw the controls in a timely fashion.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
The only way you're going to get smooth motion is to stop using controls to render all of your content, and even then, you might not get what you want, but it'll be a VAST improvement. You have to handle the Paint event of your form and draw all of your content yourself. Controls are too expensive to redraw and, from what I see if your small code snippet, you're not giving the form any time to redraw the controls in a timely fashion.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008so you suggest to drop all the controls and stick to graphics object? and/or i should increase the interval of the timer? to maybe 10 ms or what?
TheMrProgrammer
-
so you suggest to drop all the controls and stick to graphics object? and/or i should increase the interval of the timer? to maybe 10 ms or what?
TheMrProgrammer
Hi, 1. a simple timer will not provide small steps such as 1 msec (see my timers article for details). 2. you don't need such small times anyway; a movie is built with some 24 frames per second, that is 40 msec per frame. 3. you do need double-buffering, so you don't see the building-up of each frame. 4. As Dave said, get rid of the Controls, paint it all to a single Panel. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.