question

WONGTony-4228 avatar image
0 Votes"
WONGTony-4228 asked WONGTony-4228 answered

vb.net scrolling a picture at same speed or same performance in 3 computers

i am designing a game with 3 computers to show a picture (1920 x 3000pixel at 1.4Mb size) scrolling on screen from top to bottom. My requirement is to require all computers to scroll to the bottom at the same time or 0.5 seconds difference between them.

firstly, i tried
do while until end of picture, thread sleep in loop to have scrolling effect
but the result is not satisfied. the difference between computers is up to 15 seconds

secondly, i tried
timer to scroll the picture until to the bottom
but the result is better but still not satisfied. the difference between computers is up to 6 seconds

any advice to do it? regardless of controlling scrolling speed, can i design in another way by scolling the picture within 40 seconds, the program control the speed by calculation.

Besides, i found when i run these kind of loop repeatedly. The result seems much better. the computer seems to adjust its CPU to run at full speed but my game does not run the loop repeatedly

Possible to set CPU speed by VB? Thanks a lot.

dotnet-visual-basic
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

i just wonder it is better to set the program to higher thread priority and change jpg picture to uncompressed format (bmp or tif) to make the cpu processor easier

0 Votes 0 ·

I did a sample, but I have only 1 PC, so I cannot test if it works for any PC
You can test it : VB_Timed_Scrolling.zip
You must be connected to Internet because I download the 1920 * 3000 image at beginning
Use Right-Click to start the Scrolling, that I have set to 10 seconds for the test

131242-timed-scrolling.jpg


0 Votes 0 ·
timed-scrolling.jpg (35.0 KiB)

no code?

0 Votes 0 ·

If it does not work, it would be useless...

0 Votes 0 ·

How do you display and scroll the picture? (Are you using a Picture Box and a scrollable Panel?)

0 Votes 0 ·

yes , a jpeg picture in picturebox

then adjust its location from time to time

not sure it is better to do it by png or bmp

will do testing later

0 Votes 0 ·

Hi @WONGTony-4228 ,
If the execution time of the program is limited to 40, you can speed up the scrolling speed according to the remaining time.

0 Votes 0 ·
WONGTony-4228 avatar image WONGTony-4228 XingyuZhao-MSFT ·

Thanks a lot

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered

If you scroll the picture by adjusting its location, then try this code:

 Dim FinalTime = Now.AddSeconds(40)
    
 Dim t As New Thread(Sub()
    
                         Dim y As Double = Y1
    
                         Const dt = 20
                         While True
    
                             Dim iy = CInt(y)
    
                             Dim t1 = Now
    
                             PictureBox1.Invoke(Sub()
                                                     PictureBox1.Top = iy
                                                     PictureBox1.Update()
                                                 End Sub)
    
                             If iy = Y2 Then Exit While
    
                             Thread.Sleep(dt)
    
                             Dim dy = (Now - t1).TotalMilliseconds * (Y2 - y) / (FinalTime - Now).TotalMilliseconds
    
                             y += dy
                             y = Math.Min(Y2, y)
    
                         End While
    
                     End Sub)
    
 t.IsBackground = True
 t.Start()

where Y1 is the initial vertical position, Y2 — the final vertical position of the picture (Y2 > Y1), 40 — the duration of the animation (seconds).

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WONGTony-4228 avatar image
0 Votes"
WONGTony-4228 answered

the 3 computers of same model can be completed at that time by adjusting process priority to high.

amazingly, another older computer run faster than the 3 new computers

Thanks all for teaching me

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.