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 回答