|
|
发表于 2006-7-29 19:22:00
|
显示全部楼层
Re:一般游戏中文字是怎样显示的,感觉DFONT。DRAW FPS降的
另外一个新点的版本~
用的MDX(DX9c apr 2004)
Public Class RenderObjText
Inherits RenderObj2D
' Methods
Public Sub New()
Me.m_DrawFont = New System.Drawing.Font("宋体", 16.0!)
Me.m_DrawPos = New Point(0, 0)
Me.m_DrawColor = New ColorValue(1.0!, 1.0!, 1.0!, 1.0!)
Me.m_strText = ""
End Sub
Public Overrides Function OnDestory() As Boolean
Me.m_Font.Dispose()
Return True
End Function
Public Overrides Function OnInit(ByRef _v As LLDevice, ByVal shader As Effect) As Boolean
MyBase.OnInit(_v, shader)
Me.m_Font = New Microsoft.DirectX.Direct3D.Font(MyBase.m_device.m_device, Me.m_DrawFont)
Return True
End Function
Public Sub InitMe(ByVal Group As GEngine.RenderGroup2D, ByVal Engine As GEngine.Engine, ByVal str As String, ByVal name As String, ByVal font As String, ByVal size As Int16, _
ByVal x As Single, ByVal y As Single, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte, ByVal a As Byte)
Me.m_strText = str
Me.m_objname = name
Me.m_DrawFont = New Drawing.Font(font, size)
Me.m_DrawPos.X = x
Me.m_DrawPos.Y = y
Me.m_DrawColor = New Microsoft.DirectX.Direct3D.ColorValue(r, g, b, a)
Me.m_Font = New Microsoft.directx.Direct3D.Font(Engine.m_device.m_device, Me.m_DrawFont)
Group.AddObj(Me, True)
End Sub
Protected Overrides Sub OnReadAtt(ByVal strName As String, ByVal strValue As String)
Dim temp() As String
If (strName.ToLower.CompareTo("text") = 0) Then
Me.m_strText = strValue
End If
If (strName.ToLower.CompareTo("name") = 0) Then
Me.m_objname = strValue
End If
If (strName.ToLower.CompareTo("pos") = 0) Then
temp = strValue.Split(",")
Me.m_DrawPos.X = temp(0)
Me.m_DrawPos.Y = temp(1)
End If
If (strName.ToLower.CompareTo("render") = 0) Then
If strValue = "1" Then Me.m_Render = True Else Me.m_Render = False
End If
If (strName.ToLower.CompareTo("font") = 0) Then
Dim text1 As String = strValue
Me.m_DrawFont = New System.Drawing.Font(text1, Me.m_DrawFont.Size)
Me.m_Font = New Direct3D.Font(MyBase.m_device.m_device, Me.m_DrawFont)
End If
If (strName.ToLower.CompareTo("size") = 0) Then
Dim single1 As Single = System.Xml.XmlConvert.ToSingle(strValue)
Me.m_DrawFont = New Drawing.Font(Me.m_DrawFont.Name, single1)
Me.m_Font = New Direct3D.Font(MyBase.m_device.m_device, Me.m_DrawFont)
End If
If (strName.ToLower.CompareTo("color") = 0) Then
temp = strValue.Split(",")
Me.m_DrawColor.Red = temp(0)
Me.m_DrawColor.Green = temp(1)
Me.m_DrawColor.Blue = temp(2)
Me.m_DrawColor.Alpha = temp(3)
End If
End Sub
Public Overrides Function OnRender() As Boolean
If Me.m_Render = False Then Return True
Me.m_Font.DrawText(MyBase.m_device.m_sprite, Me.m_strText, New Point(Me.m_DrawPos.X + 1, Me.m_DrawPos.Y + 1), Drawing.Color.Black)
Me.m_Font.DrawText(MyBase.m_device.m_sprite, Me.m_strText, Me.m_DrawPos, Me.m_DrawColor.ToArgb)
Return True
End Function
' Fields
Public m_DrawColor As ColorValue
Public m_DrawFont As System.Drawing.Font
Public m_DrawPos As Point
Public m_Font As Direct3D.Font
Public m_strText As String
Public m_Render As Boolean
End Class
|
|