[XNA 4.0]Content Loader erstellen

  • VB.NET

    [XNA 4.0]Content Loader erstellen

    Hi leute

    ich arbeite grad an einem Projekt, welches ich geheim halten möchte ;D
    Dort werden Module geladen
    und Module sollen fähig sein, texturen zu zeichnen.
    Dafür hab ich ein Game Libary Projekt gemacht, ein Content Projekt hizugefügt (zum Projekt und zur Mappe)
    aber ich kann keine Textur laden, ich bekomm immer den Fehler, dass die Textur nicht nichts sein darf

    Das interface:

    VB.NET-Quellcode

    1. Namespace Modules
    2. Public Interface ModuleInterface
    3. ReadOnly Property Name As String
    4. Sub Initialize()
    5. Sub LoadContent()
    6. Sub UnloadContent()
    7. Sub Draw(ByVal spriteBatch As SpriteBatch, ByVal spriteFont As SpriteFont, ByVal graphicsDeviceManager As GraphicsDeviceManager)
    8. Sub Update(ByVal keyboardState As KeyboardState, ByVal mouseState As MouseState, ByVal gameTime As GameTime)
    9. End Interface
    10. End Namespace


    Die Testklasse:

    VB.NET-Quellcode

    1. Public Class Main
    2. Implements ************.Modules.ModuleInterface
    3. Private content As Content.ContentManager
    4. Private service As New GameServiceContainer
    5. Dim tex As Texture2D
    6. Public Sub Draw(spriteBatch As Microsoft.Xna.Framework.Graphics.SpriteBatch, spriteFont As Microsoft.Xna.Framework.Graphics.SpriteFont, graphicsDeviceManager As Microsoft.Xna.Framework.GraphicsDeviceManager) Implements ************.Modules.ModuleInterface.Draw
    7. spriteBatch.Draw(tex, New Vector2(0, 0), Color.White)
    8. End Sub
    9. Public Sub Initialize() Implements ************.Modules.ModuleInterface.Initialize
    10. content = New ContentManager(service)
    11. 'You have to change this after compiling
    12. content.RootDirectory = "********** Module (Content)"
    13. End Sub
    14. Public Sub LoadContent() Implements ************.Modules.ModuleInterface.LoadContent
    15. tex = content.Load(Of Texture2D)("File")
    16. End Sub
    17. Public ReadOnly Property Name As String Implements ************.Modules.ModuleInterface.Name
    18. Get
    19. 'The name of the module.
    20. 'Just for identification.
    21. Return "<ModuleName>"
    22. End Get
    23. End Property
    24. Public Sub UnloadContent() Implements ************.Modules.ModuleInterface.UnloadContent
    25. End Sub
    26. Public Sub Update(keyboardState As Microsoft.Xna.Framework.Input.KeyboardState, mouseState As Microsoft.Xna.Framework.Input.MouseState, gameTime As Microsoft.Xna.Framework.GameTime) Implements ************.Modules.ModuleInterface.Update
    27. End Sub
    28. End Class


    Und der aufruf:

    VB.NET-Quellcode

    1. ''' <summary>
    2. ''' This is called when the game should draw itself.
    3. ''' </summary>
    4. ''' <param name="gameTime">Provides a snapshot of timing values.</param>
    5. Protected Overrides Sub Draw(ByVal gameTime As GameTime)
    6. c_fpsCounter.Draw(gameTime)
    7. spriteBatch.Begin()
    8. 'Main Loop
    9. If b_isDebugEnabled Then
    10. Dim count As Integer = CInt(f_DebugFont.MeasureString("A").X)
    11. spriteBatch.DrawString(f_DebugFont, "********* Build " & My.Settings.BuildCount, New Vector2(0, 0 * count), Color.Black)
    12. spriteBatch.DrawString(f_DebugFont, c_fpsCounter.frameRate & " FPS", New Vector2(0, 1 * count), Color.Black)
    13. spriteBatch.DrawString(f_DebugFont, "Modules loaded: " & i_modulesLoaded, New Vector2(0, 2 * count), Color.Black)
    14. Dim w As Integer = 3
    15. For i As Integer = 0 To s_moduleListNames.Count - 1
    16. spriteBatch.DrawString(f_DebugFont, s_moduleListNames.Item(i), New Vector2(0, w * count), Color.Black)
    17. w += 1
    18. Next
    19. End If
    20. For Each m As ***********.Modules.ModuleInterface In module_list
    21. m.Draw(spriteBatch, f_DebugFont, graphics)
    22. Next
    23. 'End of main loop.
    24. spriteBatch.End()
    25. MyBase.Draw(gameTime)
    26. End Sub
    Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.

    BeryJu.org BeryJu.org/Blog

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „JensMn“ ()