使用DrawAllChip方法绘制所有拼块的实现过程-VB.NET游戏开发教程第6至10章
DrawAllChip方法用于绘制所有拼块。
方法说明
- 方法
Draw_AllChip()
根据新图案序号 n 绘制目标图案,通过循环调用拼块类 Cchip 的DrawChip
方法,依次绘制所有拼块。
Private Sub Draw_AllChip()
'画出所有拼块
Dim bmp As New Bitmap(Me.Width, Me.Height)
Me.BackgroundImage = bmp
Dim g As Graphics = Graphics.FromImage(bmp)
g.Clear(Me.BackColor)
'载入指定图案并绘制
Dim r As String = "s" & n.ToString() & ".jpg"
Dim s As Bitmap = DirectCast(Image.FromFile(r), Bitmap)
g.DrawImage(s, New Point(180, 40))
'循环调用DrawChip方法,绘制所有拼块
For i As Integer = 0 To CHIP_COUNT - 1
m_chipList(i).DrawChip(g)
Next
End Sub
代码解析
- Dim bmp As New Bitmap(Me.Width, Me.Height):创建一个新的Bitmap对象,大小与窗体相同,用于存储背景图。
- g.Clear(Me.BackColor):清空背景,以窗体的背景色填充。
- g.DrawImage(s, New Point(180, 40)):在指定位置(180, 40)绘制加载的图片。
- For循环:遍历
CHIP_COUNT
个拼块,并通过m_chipList(i).DrawChip(g)
绘制每个拼块。
注意事项
确保指定图案序号的图片文件 sX.jpg
存在于程序路径中,否则会产生文件加载错误。
2.53MB
文件大小:
评论区