Game Graphics - Quality Dependent FPS Control?

后端 未结 1 1013
太阳男子
太阳男子 2021-01-25 10:47

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

相关标签:
1条回答
  • 2021-01-25 11:27

    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:

    enter image description here

    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.
    0 讨论(0)
提交回复
热议问题