游戏图形 - 质量相关的FPS控制? [英] Game Graphics - Quality Dependent FPS Control?
问题描述
目前,我正在做一个游戏(在vb.net),采用的 Graphics类绘制大部分游戏的对象,但我碰到的表现的老问题。为了打击我已经添加了一些code自动降低游戏品质,所以我可以尝试,以提高游戏的速度滞后,这部作品在一定程度上,但偶还是游戏速度变慢时,更多的敌人是相当明显加入到更高的水平。我很新的图形类(仅限开始前几天使用它),所以唯一的事情我知道,有助于加快我的游戏是:关闭抗锯齿,降低定时器的时间间隔(其中大部分pretty的支配我的游戏刷新率),所以除了previous,还有没有其他的方法来提高我的比赛中的表现?
游戏截图...
下面是我的code到目前为止(质量调整位是底部),
公共类Form1中
pssed作为新的HashSet(按键)私钥$ P $
私人firstRun由于布尔= TRUE
私人mouseDownB由于布尔= FALSE
私人newLevel由于布尔= TRUE
私人randomColour作为新的随机
私人RandomEnemyX作为新的随机
私人RandomEnemyY作为新的随机
私人RandomEnemySide作为新的随机
私人生活作为整数= 5
私人分数作为字符串= 0
私人PlayerX的作为整数= 403
私人playerY作为整数= 206
私人totaltEnemyCount为整数= 10
私人enemyCount为整数= 0
私人enemyX(0)作为整数
私人enemyY(0)作为整数
私人enemyID(0)作为整数
私人EX作为整数= 0
私人EY为整数= 0
私人ES为整数= 0
私人enemyMoved作为整数
私人enemySpeed作为整数= 1
私人enemyAttacked为整数= 0
私人enemyActive为整数= 0
私人levelNumber只要= 0
私人FPS作为整数= 40
私人G1作为图形
私人enemyCountIncrease由于布尔= TRUE
私人enemySpeedIncrease由于布尔= FALSE
私人小组Form1_Shown(发送者为对象,E作为EventArgs的)把手Me.Shown
G1 = Me.CreateGraphics
g1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
结束小组
私人小组Form1_MouseDown(发送者为对象,E作为MouseEventArgs)处理Me.MouseDown
mouseDownB = TRUE
结束小组
私人小组Form1_MouseUp(发送者为对象,E作为MouseEventArgs)处理Me.MouseUp
mouseDownB = FALSE
结束小组
私人小组Form1_KeyDown(发送者为对象,E作为KeyEventArgs)处理Me.KeyDown
如果e.Key code = Keys.Left然后
键pressed.Add(Keys.Left)
elseif的e.Key code = Keys.Up然后
键pressed.Add(Keys.Up)
elseif的e.Key code = Keys.Right然后
键pressed.Add(Keys.Right)
elseif的e.Key code = Keys.Down然后
键pressed.Add(Keys.Down)
结束如果
结束小组
私人小组Form1_KeyUp(发送者为对象,E作为KeyEventArgs)处理Me.KeyUp
键pressed.Remove(e.Key code)
结束小组
'''''''''''''''''''''''''颜色随机生成器'''''''''''''''''''''' ''''''
私有函数R()作为字符串
返回randomColour.Next(0,255)
端功能
私有函数g()作为字符串
返回randomColour.Next(0,255)
端功能
私有函数B()作为字符串
返回randomColour.Next(0,255)
端功能
'''''''''''''''''''''''''随机位置产生'''''''''''''''''''''' ''''''
私有函数x()作为字符串
返回RandomEnemyX.Next(0,494)
端功能
私有函数y()作为字符串
返回RandomEnemyY.Next(24,348)
端功能
'''''''''''''''''''''''''主显示器和放大器;球员一代''''''''''''''''''''''''''''''''
私人小组mainPaint(发送者为对象,E作为EventArgs的)把手Timer1.Tick
Timer1.Interval = FPS
昏暗ST作为新的秒表
ST.Start()
如果firstRun = TRUE,则
levelNumber = levelNumber + 1
g1.DrawString(等级&安培; levelNumber,新字体(DigifaceWide,64,GraphicsUnit.Pixel),新SolidBrush(Color.FromArgb(191,R,G,B)中)中,X,Y)的
g1.DrawRectangle(新笔(Color.FromArgb(128,R,G,B)),0,0,884,24)
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,R,G,B)),PlayerX的,playerY,24,24)
g1.FillRectangle(新SolidBrush(Color.FromArgb(128,R,G,B)),0,0,884,24)
g1.DrawString(生命:5,新字体(DigifaceWide,20,GraphicsUnit.Pixel),新SolidBrush(Color.FromArgb(191,R,G,B)),2,0)
g1.DrawString(分数:0,新字体(DigifaceWide,20,GraphicsUnit.Pixel),新SolidBrush(Color.FromArgb(191,R,G,B)),100,0)
firstRun = FALSE
结束如果
'''''''''''''''''''''''''''''''移机''''''''''''''''' '''''''''''''
如果按键pressed.Contains(Keys.Left)然后
如果PlayerX的> 0然后
PlayerX的= PlayerX的 - 5
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,R,G,B)),PlayerX的,playerY,24,24)
结束如果
elseif的按键pressed.Contains(Keys.Up)然后
如果playerY> 24然后
playerY = playerY - 5
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,R,G,B)),PlayerX的,playerY,24,24)
结束如果
elseif的按键pressed.Contains(Keys.Right)然后
如果PlayerX的< 860随后
PlayerX的= PlayerX的+ 5
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,R,G,B)),PlayerX的,playerY,24,24)
结束如果
elseif的按键pressed.Contains(Keys.Down)然后
如果playerY< 388随后
playerY = playerY + 5
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,R,G,B)),PlayerX的,playerY,24,24)
结束如果
结束如果
'''''''''''''''''''''''''''''''激光产生''''''''''''''''' ''''''''''''''''''''
如果mouseDownB = TRUE,则
g1.DrawLine(新钢笔(Color.FromArgb(102,R,G,B)),PlayerX的+ 12,playerY + 12,Control.MousePosition.X - Me.Bounds.X,Control.MousePosition.Y - Me.Bounds .Y)
结束如果
''''''''''''''''''''''''''''''''敌代 - 新的水平''''''''''''' '''''''''''''''''''''''
如果newLevel = TRUE,则
levelNumber = levelNumber + 1
做,而enemyCount< totaltEnemyCount
昏暗我作为整数= 0
REDIM enemyID(0)
做,而enemyID.Length< = totaltEnemyCount
EX = RandomEnemyX.Next(0,872)
EY = RandomEnemyY.Next(24,400)
ES = RandomEnemySide.Next(0,4)
REDIM preserve enemyID第(i + 1)
enemyID(ⅰ)= 1
REDIM preserve enemyX第(i + 1)
REDIM preserve enemyY第(i + 1)
如果ES = 0然后'左侧
enemyX(ⅰ)= 0
enemyY(ⅰ)= EY
elseif的ES = 1,则顶侧
enemyX(ⅰ)= EX
enemyY(ⅰ)= 24
elseif的ES = 2那么右侧
enemyX(ⅰ)= 872
enemyY(ⅰ)= EY
elseif的ES = 3然后'底侧
enemyX(ⅰ)= EX
enemyY(ⅰ)= 400
结束如果
g1.FillEllipse(新SolidBrush(Color.FromArgb(128,Color.Red)),enemyX(i)中,enemyY(ⅰ),12,12)
enemyCount = enemyID.Length
enemyActive = enemyActive + 1
I = I + 1
循环
循环
newLevel =假
结束如果
''''''''''''''''''''''''''''''''敌攻击'''''''''''''''' ''''''''''''''''''''''''
昏暗三为整数= 0
做,而III< totaltEnemyCount
如果(((Control.MousePosition.X - Me.Location.X)GT; enemyX(ⅲ)))和((Control.MousePosition.X - Me.Location.X)≤(enemyX(三)+ 16))和((Control.MousePosition.Y - Me.Location.Y)GT; enemyY(ⅲ))和((Control.MousePosition.Y - Me.Location.Y)≤(enemyY(三)+ 16))。然后
如果mouseDownB = TRUE,则
enemyID(ⅲ)= -1
enemyX(ⅲ)= -1
enemyY(ⅲ)= -1
enemyActive = enemyActive - 1
enemyCount = enemyCount - 1
结束如果
结束如果
III = III + 1
循环
''''''''''''''''''''''''''''''''招制敌'''''''''''''''' '''''''''''''
昏暗II作为整数= 0
做,而enemyMoved< totaltEnemyCount
如果enemyActive< 1然后
enemyCount = 0
newLevel = TRUE
如果enemyCountIncrease = TRUE,则
totaltEnemyCount = totaltEnemyCount + 50
elseif的enemySpeedIncrease = true,那么
enemySpeed = enemySpeed + 1
结束如果
g1.DrawString(等级&安培; levelNumber,新字体(DigifaceWide,64,GraphicsUnit.Pixel),新SolidBrush(Color.FromArgb(191,R,G,B)中)中,X,Y)的
退出小组
结束如果
如果enemyID(ⅱ)= -1。然后
转到skipMove
结束如果
如果(enemyX(ⅱ) - (PlayerX的+ 4))≤; 0然后'左敌人
enemyX(ⅱ)= enemyX(ⅱ)+ enemySpeed
结束如果
如果(enemyX(ⅱ) - (PlayerX的+ 4))> 0然后右边的敌人
enemyX(ⅱ)= enemyX(ⅱ) - enemySpeed
结束如果
如果(enemyY(ⅱ) - (playerY + 4))≤; 0然后'敌以上
enemyY(ⅱ)= enemyY(ⅱ)+ enemySpeed
结束如果
如果(enemyY(ⅱ) - (playerY + 4))> 0然后'下面的敌人
enemyY(ⅱ)= enemyY(ⅱ) - enemySpeed
结束如果
g1.FillEllipse(新SolidBrush(Color.FromArgb(51,Color.Red)),enemyX(ii)中,enemyY(ii)中,12,12)
skipMove:
enemyMoved = enemyMoved + 1
II = II + 1
循环
enemyMoved = 0
''''''''''''''''''''''QDSA - 质量Depentant调速''''''''''''''''''''
ST.Stop()
昏暗elapTick为十进制= ST.ElapsedTicks
如果elapTick< 5000那么慢下来
FPS = FPS + 1
enemySpeedIncrease =假
g1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
enemyCountIncrease = TRUE
elseif的elapTick> 5000然后加快
如果FPS> 1然后
FPS = FPS - 1
结束如果
g1.SmoothingMode = Drawing2D.SmoothingMode.None
enemyCountIncrease =假
如果enemySpeed< 4然后,
enemySpeedIncrease = TRUE
其他
enemySpeedIncrease =假
结束如果
结束如果
结束小组
末级
我都做过类似的你需要什么,只是给你一个想法强大,美观,快速WPF如何比较古老的技术。一个示例WPF项目
这看起来是这样的:
这是一个有点太多code将它张贴在这里完全,所以这里是一个链接与完整的源RAR文件。
在主界面XAML是这样的:
<窗口x:类=SamsGameSample.MainWindow
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
XMLNS:地方=CLR的命名空间:SamsGameSample
标题=SamsGameSample
previewKeyDown =Window_ previewKeyDown
previewKeyUp =Window_ previewKeyUp
SizeChanged将=Window_SizeChanged
的WindowState =最大化>
< Window.Resources>
< DataTemplate中数据类型={X:类型本地:玩家}>
<椭圆填充=绿色行程=黑色高度={结合Size.Height}WIDTH ={结合Size.Width}/>
< / DataTemplate中>
< DataTemplate中数据类型={X:键入地方:敌人}>
<椭圆填充=红行程=黑色高度={结合Size.Height}WIDTH ={结合Size.Width}/>
< / DataTemplate中>
< /Window.Resources>
< DockPanel中>
< DockPanel.Background>
<6一个LinearGradientBrush StartPoint可以=0,0的EndPoint =1,0不透明度=>
<渐变停止颜色=蓝偏移量=0/>
<渐变停止颜色=红偏移= /&GT5。
<渐变停止颜色=绿色偏移=1/>
< /一个LinearGradientBrush>
< /DockPanel.Background>
< StackPanel的方向=横向背景=#7000DockPanel.Dock =评出的>
< TextBlock的文本={结合生活,的StringFormat ='住:{0}'}保证金=10前景=艾莉斯蓝/>
< TextBlock的文本={结合分数,的StringFormat ='分数:{0}'}保证金=10前景=艾莉斯蓝/>
< / StackPanel的>
< ItemsControl中的ItemsSource ={结合GameObjects}X:名称=GameArea>
< ItemsControl.ItemContainerStyle>
<风格的TargetType =内容presenter>
< setter属性=Canvas.LeftVALUE ={结合Location.X}/>
< setter属性=Canvas.TopVALUE ={结合Location.Y}/>
< /样式和GT;
< /ItemsControl.ItemContainerStyle>
< ItemsControl.ItemsPanel>
< ItemsPanelTemplate>
<帆布IsItemsHost =真/>
< / ItemsPanelTemplate>
< /ItemsControl.ItemsPanel>
< / ItemsControl的>
< / DockPanel中>
< /窗>
- 的code在我的项目金额(和它的洁净度)比较,你需要做的WinForms几乎所有的东西多的黑客。
- 也比较性能和分辨率无关。
I'm currently making a game (in vb.net) that uses the Graphics class to draw most of the game objects, but i've run into the old problem of performance. To combat the lagging i've added some code to automatically lower the game quality so i can try to boost the game's speed, this works to a degree, but even still the game slows down quite noticeable when more "enemies" are added to the higher levels. I quite new to the graphics class (only started to use it a few days ago), so the only things i know that help speed up my game are: turning off Anti Aliasing, and lowering the Timer interval (which pretty much governs my games refresh rate), so besides the previous, are there any other ways to improve my game's performance?
Game screenshot...
Here's my code so far (the quality adjustment bit is at the bottom),
Public Class Form1
Private keysPressed As New HashSet(Of Keys)
Private firstRun As Boolean = True
Private mouseDownB As Boolean = False
Private newLevel As Boolean = True
Private randomColour As New Random
Private RandomEnemyX As New Random
Private RandomEnemyY As New Random
Private RandomEnemySide As New Random
Private life As Integer = 5
Private score As String = 0
Private playerX As Integer = 403
Private playerY As Integer = 206
Private totaltEnemyCount As Integer = 10
Private enemyCount As Integer = 0
Private enemyX(0) As Integer
Private enemyY(0) As Integer
Private enemyID(0) As Integer
Private EX As Integer = 0
Private EY As Integer = 0
Private ES As Integer = 0
Private enemyMoved As Integer
Private enemySpeed As Integer = 1
Private enemyAttacked As Integer = 0
Private enemyActive As Integer = 0
Private levelNumber As Long = 0
Private FPS As Integer = 40
Private g1 As Graphics
Private enemyCountIncrease As Boolean = True
Private enemySpeedIncrease As Boolean = False
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
g1 = Me.CreateGraphics
g1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
mouseDownB = True
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
mouseDownB = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Then
keysPressed.Add(Keys.Left)
ElseIf e.KeyCode = Keys.Up Then
keysPressed.Add(Keys.Up)
ElseIf e.KeyCode = Keys.Right Then
keysPressed.Add(Keys.Right)
ElseIf e.KeyCode = Keys.Down Then
keysPressed.Add(Keys.Down)
End If
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
keysPressed.Remove(e.KeyCode)
End Sub
'''''''''''''''''''''''''Random colour generator''''''''''''''''''''''''''''
Private Function R() As String
Return randomColour.Next(0, 255)
End Function
Private Function G() As String
Return randomColour.Next(0, 255)
End Function
Private Function B() As String
Return randomColour.Next(0, 255)
End Function
'''''''''''''''''''''''''Random location generator''''''''''''''''''''''''''''
Private Function X() As String
Return RandomEnemyX.Next(0, 494)
End Function
Private Function Y() As String
Return RandomEnemyY.Next(24, 348)
End Function
'''''''''''''''''''''''''Main display & player generation''''''''''''''''''''''''''''''''
Private Sub mainPaint(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Interval = FPS
Dim ST As New Stopwatch
ST.Start()
If firstRun = True Then
levelNumber = levelNumber + 1
g1.DrawString("Level " & levelNumber, New Font("DigifaceWide", 64, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(191, R, G, B)), X, Y)
g1.DrawRectangle(New Pen(Color.FromArgb(128, R, G, B)), 0, 0, 884, 24)
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, R, G, B)), playerX, playerY, 24, 24)
g1.FillRectangle(New SolidBrush(Color.FromArgb(128, R, G, B)), 0, 0, 884, 24)
g1.DrawString("Life: 5", New Font("DigifaceWide", 20, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(191, R, G, B)), 2, 0)
g1.DrawString("Score: 0", New Font("DigifaceWide", 20, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(191, R, G, B)), 100, 0)
firstRun = False
End If
'''''''''''''''''''''''''''''''Move player''''''''''''''''''''''''''''''
If keysPressed.Contains(Keys.Left) Then
If playerX > 0 Then
playerX = playerX - 5
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, R, G, B)), playerX, playerY, 24, 24)
End If
ElseIf keysPressed.Contains(Keys.Up) Then
If playerY > 24 Then
playerY = playerY - 5
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, R, G, B)), playerX, playerY, 24, 24)
End If
ElseIf keysPressed.Contains(Keys.Right) Then
If playerX < 860 Then
playerX = playerX + 5
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, R, G, B)), playerX, playerY, 24, 24)
End If
ElseIf keysPressed.Contains(Keys.Down) Then
If playerY < 388 Then
playerY = playerY + 5
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, R, G, B)), playerX, playerY, 24, 24)
End If
End If
'''''''''''''''''''''''''''''''Laser generation'''''''''''''''''''''''''''''''''''''
If mouseDownB = True Then
g1.DrawLine(New Pen(Color.FromArgb(102, R, G, B)), playerX + 12, playerY + 12, Control.MousePosition.X - Me.Bounds.X, Control.MousePosition.Y - Me.Bounds.Y)
End If
''''''''''''''''''''''''''''''''Enemy generation - New level''''''''''''''''''''''''''''''''''''
If newLevel = True Then
levelNumber = levelNumber + 1
Do While enemyCount < totaltEnemyCount
Dim i As Integer = 0
ReDim enemyID(0)
Do While enemyID.Length <= totaltEnemyCount
EX = RandomEnemyX.Next(0, 872)
EY = RandomEnemyY.Next(24, 400)
ES = RandomEnemySide.Next(0, 4)
ReDim Preserve enemyID(i + 1)
enemyID(i) = 1
ReDim Preserve enemyX(i + 1)
ReDim Preserve enemyY(i + 1)
If ES = 0 Then 'Left side
enemyX(i) = 0
enemyY(i) = EY
ElseIf ES = 1 Then 'Top side
enemyX(i) = EX
enemyY(i) = 24
ElseIf ES = 2 Then 'Right side
enemyX(i) = 872
enemyY(i) = EY
ElseIf ES = 3 Then 'Bottom side
enemyX(i) = EX
enemyY(i) = 400
End If
g1.FillEllipse(New SolidBrush(Color.FromArgb(128, Color.Red)), enemyX(i), enemyY(i), 12, 12)
enemyCount = enemyID.Length
enemyActive = enemyActive + 1
i = i + 1
Loop
Loop
newLevel = False
End If
''''''''''''''''''''''''''''''''Enemy attacked''''''''''''''''''''''''''''''''''''''''
Dim iii As Integer = 0
Do While iii < totaltEnemyCount
If (((Control.MousePosition.X - Me.Location.X) > enemyX(iii))) And ((Control.MousePosition.X - Me.Location.X) < (enemyX(iii) + 16)) And ((Control.MousePosition.Y - Me.Location.Y) > enemyY(iii)) And ((Control.MousePosition.Y - Me.Location.Y) < (enemyY(iii) + 16)) Then
If mouseDownB = True Then
enemyID(iii) = -1
enemyX(iii) = -1
enemyY(iii) = -1
enemyActive = enemyActive - 1
enemyCount = enemyCount - 1
End If
End If
iii = iii + 1
Loop
''''''''''''''''''''''''''''''''Move enemy'''''''''''''''''''''''''''''
Dim ii As Integer = 0
Do While enemyMoved < totaltEnemyCount
If enemyActive < 1 Then
enemyCount = 0
newLevel = True
If enemyCountIncrease = True Then
totaltEnemyCount = totaltEnemyCount + 50
ElseIf enemySpeedIncrease = True Then
enemySpeed = enemySpeed + 1
End If
g1.DrawString("Level " & levelNumber, New Font("DigifaceWide", 64, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(191, R, G, B)), X, Y)
Exit Sub
End If
If enemyID(ii) = -1 Then
GoTo skipMove
End If
If (enemyX(ii) - (playerX + 4)) < 0 Then 'Enemy on left
enemyX(ii) = enemyX(ii) + enemySpeed
End If
If (enemyX(ii) - (playerX + 4)) > 0 Then 'Enemy on right
enemyX(ii) = enemyX(ii) - enemySpeed
End If
If (enemyY(ii) - (playerY + 4)) < 0 Then 'Enemy above
enemyY(ii) = enemyY(ii) + enemySpeed
End If
If (enemyY(ii) - (playerY + 4)) > 0 Then 'Enemy below
enemyY(ii) = enemyY(ii) - enemySpeed
End If
g1.FillEllipse(New SolidBrush(Color.FromArgb(51, Color.Red)), enemyX(ii), enemyY(ii), 12, 12)
skipMove:
enemyMoved = enemyMoved + 1
ii = ii + 1
Loop
enemyMoved = 0
''''''''''''''''''''''QDSA - Quality Depentant Speed Adjustment''''''''''''''''''''
ST.Stop()
Dim elapTick As Decimal = ST.ElapsedTicks
If elapTick < 5000 Then 'Slow down
FPS = FPS + 1
enemySpeedIncrease = False
g1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
enemyCountIncrease = True
ElseIf elapTick > 5000 Then 'Speed up
If FPS > 1 Then
FPS = FPS - 1
End If
g1.SmoothingMode = Drawing2D.SmoothingMode.None
enemyCountIncrease = False
If enemySpeed < 4 Then
enemySpeedIncrease = True
Else
enemySpeedIncrease = False
End If
End If
End Sub
End Class
I have made a sample WPF project similar to what you need, just to give you an idea how powerful and beautiful and fast WPF is compared to ancient technologies.
It looks like this:
It's a little too much code to post it here entirely, so here is a link to a RAR file with the full source.
The main UI XAML is this:
<Window x:Class="SamsGameSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SamsGameSample"
Title="SamsGameSample"
PreviewKeyDown="Window_PreviewKeyDown"
PreviewKeyUp="Window_PreviewKeyUp"
SizeChanged="Window_SizeChanged"
WindowState="Maximized">
<Window.Resources>
<DataTemplate DataType="{x:Type local:Player}">
<Ellipse Fill="Green" Stroke="Black" Height="{Binding Size.Height}" Width="{Binding Size.Width}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type local:Enemy}">
<Ellipse Fill="Red" Stroke="Black" Height="{Binding Size.Height}" Width="{Binding Size.Width}"/>
</DataTemplate>
</Window.Resources>
<DockPanel>
<DockPanel.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0" Opacity=".6">
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="Red" Offset=".5"/>
<GradientStop Color="Green" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<StackPanel Orientation="Horizontal" Background="#70000000" DockPanel.Dock="Top">
<TextBlock Text="{Binding Lives, StringFormat='Lives: {0}'}" Margin="10" Foreground="AliceBlue"/>
<TextBlock Text="{Binding Score, StringFormat='Score: {0}'}" Margin="10" Foreground="AliceBlue"/>
</StackPanel>
<ItemsControl ItemsSource="{Binding GameObjects}" x:Name="GameArea">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Location.X}"/>
<Setter Property="Canvas.Top" Value="{Binding Location.Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
</Window>
- Compare the amount of code in my project (and the cleanliness of it) to the multiple hacks you need to do almost anything in winforms.
- Also compare the performance, and the resolution independence.
这篇关于游戏图形 - 质量相关的FPS控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!