[XNA] PauseMenu Grundbaustein

    • VB.NET

      [XNA] PauseMenu Grundbaustein

      Hallo,

      ich hab vorhin mal das hier hingekritzelt:

      Spoiler anzeigen

      VB.NET-Quellcode

      1. ''' <summary>
      2. ''' This is the main type for your game
      3. ''' </summary>
      4. Public Class PauseMenu
      5. Inherits Microsoft.Xna.Framework.DrawableGameComponent
      6. Enum State
      7. Rein
      8. Raus
      9. Nichts
      10. End Enum
      11. Private WithEvents graphics As GraphicsDeviceManager
      12. Private WithEvents spriteBatch As SpriteBatch
      13. Private bgtexture As Texture2D
      14. Private Size As Vector2
      15. Private Point As Vector2
      16. Private Drawen As Boolean = True
      17. Private statemod As State = State.Nichts
      18. Public Sub New(ByVal game As Game, ByVal spriteBatch As SpriteBatch)
      19. MyBase.New(game)
      20. Me.spriteBatch = spriteBatch
      21. Size = New Vector2(game.Window.ClientBounds.Width, game.Window.ClientBounds.Height)
      22. Point = New Vector2(0 - game.Window.ClientBounds.Width, 0)
      23. End Sub
      24. ''' <summary>
      25. ''' Allows the game to perform any initialization it needs to before starting to run.
      26. ''' This is where it can query for any required services and load any non-graphic
      27. ''' related content. Calling MyBase.Initialize will enumerate through any components
      28. ''' and initialize them as well.
      29. ''' </summary>
      30. Public Overrides Sub Initialize()
      31. ' TODO: Add your initialization logic here
      32. MyBase.Initialize()
      33. End Sub
      34. ''' <summary>
      35. ''' LoadContent will be called once per game and is the place to load
      36. ''' all of your content.
      37. ''' </summary>
      38. Protected Overrides Sub LoadContent()
      39. ' Create a new SpriteBatch, which can be used to draw textures.
      40. 'spriteBatch = New SpriteBatch(GraphicsDevice)
      41. bgtexture = Game.Content.Load(Of Texture2D)("bgtexture")
      42. ' TODO: use Me.Content to load your game content here
      43. MyBase.LoadContent()
      44. End Sub
      45. ''' <summary>
      46. ''' UnloadContent will be called once per game and is the place to unload
      47. ''' all content.
      48. ''' </summary>
      49. Protected Overrides Sub UnloadContent()
      50. ' TODO: Unload any non ContentManager content here
      51. End Sub
      52. ''' <summary>
      53. ''' Allows the game to run logic such as updating the world,
      54. ''' checking for collisions, gathering input, and playing audio.
      55. ''' </summary>
      56. ''' <param name="gameTime">Provides a snapshot of timing values.</param>
      57. Public Overrides Sub Update(ByVal gameTime As GameTime)
      58. Dim val As Integer = +5
      59. If statemod = State.Raus Then
      60. val = +5
      61. ElseIf statemod = State.Rein Then
      62. val = -5
      63. End If
      64. If statemod = State.Raus Then
      65. If Point.X + Game.Window.ClientBounds.Width = Game.Window.ClientBounds.Width / 2 / 2 Then
      66. Else
      67. Point.X += val
      68. End If
      69. End If
      70. If statemod = State.Rein Then
      71. If Point.X + Game.Window.ClientBounds.Width = 0 Then
      72. 'statemod = State.Raus
      73. Else
      74. Point.X += val
      75. End If
      76. End If
      77. MyBase.Update(gameTime)
      78. End Sub
      79. ''' <summary>
      80. ''' This is called when the game should draw itself.
      81. ''' </summary>
      82. ''' <param name="gameTime">Provides a snapshot of timing values.</param>
      83. Public Overrides Sub Draw(ByVal gameTime As GameTime)
      84. 'GraphicsDevice.Clear(Color.CornflowerBlue)
      85. spriteBatch.Begin()
      86. 'spriteBatch.End()
      87. spriteBatch.Draw(bgtexture, New Rectangle(Point.X, Point.Y, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height), New Color(0, 0, 210, 200))
      88. spriteBatch.End()
      89. ' TODO: Add your drawing code here
      90. MyBase.Draw(gameTime)
      91. End Sub
      92. Sub Reinfahren(ByVal steps As Integer)
      93. statemod = State.Rein
      94. End Sub
      95. Sub Rausfahren(ByVal steps As Integer)
      96. statemod = State.Raus
      97. End Sub
      98. End Class



      Ich weiss, mieser Codestil, bla bla....
      Die Verwendung sollte klar sein.
      Nur falls jemand das braucht.

      Grüße