0

私は学校でインターネットにしかアクセスできないので、フィルターは実際の研究の邪魔になります。現在、学校のプロジェクトのRPGをコーディングしていますが、アバターをマップ上で移動させるのは困難です。これまでの私の哀れなコードは次のとおりです。

Public Class Map1

    Private Sub USER_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        User.Top = User.Top - 1
    End Sub

    Private Sub USER_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        User.Top = User.Bottom + 1
        'User.Location.X = 200
    End Sub
End Class

次の問題があります。xを削除したときと削除しなかったときに、User.location.x=200で構文エラーが発生しました。プレイヤーはまた、移動するためにキーを押し続ける必要がありました。

両方私は修正する方法がわかりません。私の最終学年のためですので、どんな助けでも大歓迎です。

4

3 に答える 3

2

timer_tickそれをループに入れることができます。それが私がしていることです。

の正しいバージョンUser.Location.X = 200は次のとおりです。

User.location = new point(200, User.location.y)
于 2012-04-29T04:20:17.560 に答える
0

nvm は解決策を見つけました。これは、将来コードが必要になる可能性がある他の人のためのものです。

Private Sub Map_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = Keys.Up Then
        User.Location = New Point(User.Location.X, User.Location.Y - 5)
    ElseIf e.KeyCode = Keys.Down Then
        User.Location = New Point(User.Location.X, User.Location.Y + 5)
    ElseIf e.KeyCode = Keys.Left Then
        User.Location = New Point(User.Location.X - 5, User.Location.Y)
    ElseIf e.KeyCode = Keys.Right Then
        User.Location = New Point(User.Location.X + 5, User.Location.Y)
    End If
于 2012-05-16T14:32:41.967 に答える
0
Module

    Public Sub MovePictureBox(ByRef PictureBox As PictureBox)
        Tiempo.Tag = PictureBox
        AddHandler PictureBox.Parent.KeyDown, AddressOf Parent_KeyDown
        AddHandler PictureBox.Parent.KeyUp, AddressOf Parent_KeyUp
        AddHandler CType(PictureBox.Parent, Form).Load, AddressOf Parent_Load
    End Sub
    Private Up, Down, Left, Right As Boolean
    WithEvents Tiempo As New Timer() With {.Interval = 1}
    Private Sub Tiempo_Tick() Handles Tiempo.Tick
        If Up Then Tiempo.Tag.Top -= 2
        If Down Then Tiempo.Tag.Top += 2
        If Left Then Tiempo.Tag.Left -= 2
        If Right Then Tiempo.Tag.Left += 2
    End Sub
    Private Sub Parent_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Up Then Up = True
        If e.KeyCode = Keys.Down Then Down = True
        If e.KeyCode = Keys.Left Then Left = True
        If e.KeyCode = Keys.Right Then Right = True
        Tiempo.Enabled = True
    End Sub
    Private Sub Parent_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Tiempo.Enabled = False
        Up = False : Down = False : Right = False : Left = False
    End Sub
    Private Sub Parent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        sender.KeyPreview = True
    End Sub
End Module
于 2016-09-10T09:53:57.637 に答える