vb.net - 背景图片移动 vb.net
问题描述
我正在尝试创建一个小游戏,但遇到了麻烦。当玩家在地图上移动时,我希望背景图像作为循环移动。以下代码是我想要的示例,但相反。
Public Class Form1
Private WithEvents Tmr As New Timer With {.Interval = 40}
Private water As New Bitmap("C:\TestFolder\Water.png")
Private waterposition As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Size = New Size(240, 74)
Tmr.Start()
End Sub
Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
waterposition += 1
If waterposition = water.Width Then waterposition = 0
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(water, waterposition, 0)
If waterposition > 0 Then e.Graphics.DrawImage(water, 0 - (water.Width - waterposition), 0)
End Sub End class
现在,当我试图反转它(从右到左)时,图像不会重绘。
Private Sub Tmr_Tick(sender As Object, e As EventArgs) Handles Tmr.Tick
waterposition -= 1
If waterposition = 0 Then waterposition = water.Width
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(water, waterposition, 0)
If waterposition < 0 Then e.Graphics.DrawImage(water, (water.Width + waterposition), 0)
End Sub
有什么建议吗?谢谢
解决方案
推荐阅读
- swift - Swift Core Data 获取数据 1 列
- c# - 从视图模型更改 Xamarin 表单应用程序页面
- otrs - 在 OTRS 工单视图中添加列
- laravel - 使用 babel 和 laravel-mix 将 ES6 转换为 ES2015
- android - 如何在我的应用程序中访问工具栏小部件上的文本?
- javascript - getJSON 函数仅从 localhost 上的 url 获取数据
- c++ - 如何积累模板参数包?
- ruby-on-rails - 在rails中使用带有条件的复选框
- javascript - 验证 POST 请求
- swift - 快速显示 QLPreviewPanel