问题描述
我已使用Game.Start()
启动了计时器,并使用断点确定了计时器已启用,间隔为100。但是,单步执行代码时,将忽略timer子项,而paint子项是给予优先权。因此,计时器永远不会运行。
这是我指的代码:
Public Class Form1
Dim speed_s As Integer = 5
Dim speed_w As Integer = 5
Dim speed_d As Integer = 5
Dim speed_a As Integer = 5
Dim Enemy1 As New computerControlled(1,1,Me)
Private Sub Form1_Load(sender As Object,e As EventArgs) Handles Me.Load
player1.Bounds = New Rectangle(player1.Location.X,player1.Location.Y,player1.Width,player1.Height)
'Enemy1.DrawEnemy(Me)
Game.Enabled = True
Game.Start()
End Sub
Private Sub Form1_KeyDown(sender As Object,e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.W Then
player1.Top -= speed_w
ElseIf e.KeyCode = Keys.S Then
player1.Top += speed_s
ElseIf e.KeyCode = Keys.A Then
player1.Left -= speed_a
ElseIf e.KeyCode = Keys.D Then
player1.Left += speed_d
' Enemy1.enemypic.Left += 10 this moves enemy class well
End If
End Sub
Private Sub Timer1_Tick(sender As Object,e As EventArgs) Handles Game.Tick
'Enemy1.enemypic.Left += 10
Enemy1.Walk()
MsgBox("hi")
End Sub
Private MOUSE_X As Integer
Private MOUSE_Y As Integer
Private Sub Form1_MouseMove(sender As Object,e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
MOUSE_X = e.X
MOUSE_Y = e.Y
End Sub
Private Sub Player_Paint(sender As Object,e As PaintEventArgs) Handles player1.Paint
Dim GFX As Graphics = e.Graphics
Dim BMP As Bitmap = Image.FromFile("c:\firaas\ball.png")
Dim center As Point = New Point(player1.Width \ 2,player1.Height \ 2)
Dim angle As Integer
Dim rad As Double
Dim CENTRE_X As Integer
Dim CENTRE_Y As Integer
'=========================
Using cyan As New Pen(Brushes.Cyan,2)
GFX.ResetTransform()
GFX.TranslateTransform(CENTRE_X,CENTRE_Y)
GFX.RotateTransform(angle) ' angle in degrees!
'For Each pos As PointF In pat.Positions
' Dim r As New Rectangle(pos.X,pos.Y,1)
' r.Inflate(3,3)
' GFX.DrawEllipse(cyan,r)
' Next
End Using
'===========================
Dim rotatematrix As New System.Drawing.drawing2d.Matrix()
Dim srcRect As New RectangleF(64,64,64)
Dim OffsetX As Single = Me.Width / 2 - player1.Width / 2
Dim OffsetY As Single = Me.Height / 2 - player1.Height / 2
CENTRE_X = player1.Location.X + player1.Width / 2
CENTRE_Y = player1.Location.Y + player1.Height / 2
rad = Math.atan2(MOUSE_Y - CENTRE_Y,MOUSE_X - CENTRE_X)
angle = rad * (180 / Math.PI)
'================================================================================
BMP = New Bitmap(My.Resources.ball)
GFX.TranslateTransform(player1.Height / 2,player1.Width / 2)
GFX.RotateTransform(angle)
GFX.DrawImage(BMP,player1.Location.X,player1.Location.Y)
GFX.ResetTransform()
e.Graphics.TranslateTransform(player1.Height / 2,player1.Width / 2)
e.Graphics.RotateTransform(angle)
' BMP.RotateAt(angle,New PointF(player1.Location.X,player1.Location.Y))
e.Graphics.DrawImage(BMP,New Point(-player1.Width \ 2,-player1.Height \ 2))
e.Graphics.DrawImageUnscaled(BMP,New Point(0,0))
player1.Invalidate()
End Sub
结束班级
'最新项目
解决方法
如果这是完整的代码,则似乎没有在设置计时器的间隔。
因此,您要说的是,它可以打勾,每个打勾该怎么做,但实际上并没有设置打勾的时间。
Game.Interval = 60000 '1 minute
Game.Enabled = True
Game.Start() 'I don't believe you need this line