Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 图像框是否平稳移动?_Vb.net_Visual Studio - Fatal编程技术网

Vb.net 图像框是否平稳移动?

Vb.net 图像框是否平稳移动?,vb.net,visual-studio,Vb.net,Visual Studio,我想知道是否有一种方法可以使图像框在表单中流畅地流动 我在表单上启用了双缓冲区,但它并没有对表单进行太多改进 Public Class Form1 Dim Offset As Point Dim moveRight As Boolean = True Dim moveDown As Boolean = True Const Speed As Decimal = 1 Private Sub Timer1_Tick(sender As Object, e A

我想知道是否有一种方法可以使图像框在表单中流畅地流动 我在表单上启用了双缓冲区,但它并没有对表单进行太多改进

Public Class Form1
    Dim Offset As Point
    Dim moveRight As Boolean = True
    Dim moveDown As Boolean = True
    Const Speed As Decimal = 1

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If moveRight = True Then
            pxbox.Left += Speed
            If (pxbox.Left + pxbox.Width) > Me.ClientSize.Width Then moveRight = False
        Else
            pxbox.Left -= Speed
            If pxbox.Left < 0 Then moveRight = True

        End If

        If moveDown = True Then
            pxbox.Top += Speed
            If (pxbox.Top + pxbox.Height) > Me.ClientSize.Height Then moveDown = False
        Else
            pxbox.Top -= Speed
            If pxbox.Top <= 0 Then moveDown = True

        End If

        'Collision Method 1
        Dim Col As Boolean = Collision(pxbox, pbpaddle1)
        If Col = True Then
            moveRight = Not moveRight
            moveDown = Not moveDown
        End If

        Dim Col2 As Boolean = Collision(pxbox, pbpaddle2)

        If Col2 = True Then
            moveRight = Not moveRight
            moveDown = Not moveDown
        End If

        'Method 2
        'If pxbox.Bounds.IntersectsWith(pbpaddle1.Bounds) Then
        '    moveRight = Not moveRight
        '    moveDown = Not moveDown
        'End If
        'If pxbox.Bounds.IntersectsWith(pbpaddle2.Bounds) Then
        '    moveRight = Not moveRight
        '    moveDown = Not moveDown
        'End If
    End Sub

    Private Function Collision(ByVal P1 As PictureBox, ByVal P2 As PictureBox) As Boolean
        If P1.Left + P1.Width < P2.Left Then Return False
        If P2.Left - 15 + P2.Width < P1.Left Then Return False
        If P1.Top + P1.Height < P2.Top Then Return False
        If P2.Top + P2.Height < P1.Top Then Return False

        Return True

    End Function

Winform的计时器控件并不是为平滑动画所需的精度而设计的。尝试在动画中使用精灵控件时,也会有很多开销


您确实应该考虑使用GDI绘图代码对内存位图进行所有绘图,然后将该位图发布到单个大图像控件、窗体背景或其他一些显示表面。

计时器的间隔是多少?设置为最高值10,这就是为什么我的速度是1,所以它可以尽可能平滑,但它仍然不是。WinForm的计时器控件并不是为这种类型的动画设计的。它的准确度被限制在55毫秒左右。