Results 1 to 10 of 10

Thread: XNA Help

  1. #1
    Lively Member
    Join Date
    Jan 11
    Posts
    107

    XNA Help

    Hello,

    I'm trying to make a game with XNA, but how do I make something like buttons on the Gamescreen?

    Code:
    ''' <summary>
    ''' This is the main type for your game
    ''' </summary>
    Public Class Game1
        Inherits Microsoft.Xna.Framework.Game
    
        Private WithEvents graphics As GraphicsDeviceManager
        Private WithEvents spriteBatch As SpriteBatch
    
        Public Sub New()
            graphics = New GraphicsDeviceManager(Me)
            Content.RootDirectory = "Content"
        End Sub
    
        ''' <summary>
        ''' Allows the game to perform any initialization it needs to before starting to run.
        ''' This is where it can query for any required services and load any non-graphic
        ''' related content.  Calling MyBase.Initialize will enumerate through any components
        ''' and initialize them as well.
        ''' </summary>
        Protected Overrides Sub Initialize()
            ' TODO: Add your initialization logic here
            MyBase.Initialize()
        End Sub
    
        ''' <summary>
        ''' LoadContent will be called once per game and is the place to load
        ''' all of your content.
        ''' </summary>
        Protected Overrides Sub LoadContent()
            ' Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = New SpriteBatch(GraphicsDevice)
    
            ' TODO: use Me.Content to load your game content here
        End Sub
    
        ''' <summary>
        ''' UnloadContent will be called once per game and is the place to unload
        ''' all content.
        ''' </summary>
        Protected Overrides Sub UnloadContent()
            ' TODO: Unload any non ContentManager content here
        End Sub
    
        ''' <summary>
        ''' Allows the game to run logic such as updating the world,
        ''' checking for collisions, gathering input, and playing audio.
        ''' </summary>
        ''' <param name="gameTime">Provides a snapshot of timing values.</param>
        Protected Overrides Sub Update(ByVal gameTime As GameTime)
            ' Allows the game to exit
            If GamePad.GetState(PlayerIndex.One).Buttons.Back = ButtonState.Pressed Then
                Me.Exit()
            End If
    
            ' TODO: Add your update logic here
            MyBase.Update(gameTime)
        End Sub
    
        ''' <summary>
        ''' This is called when the game should draw itself.
        ''' </summary>
        ''' <param name="gameTime">Provides a snapshot of timing values.</param>
        Protected Overrides Sub Draw(ByVal gameTime As GameTime)
            GraphicsDevice.Clear(Color.CornflowerBlue)
    
            ' TODO: Add your drawing code here
            MyBase.Draw(gameTime)
        End Sub
    
    End Class
    Code:
    #If WINDOWS Or XBOX Then
    
    Module Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        Sub Main(ByVal args As String())
            Using game As New Game1()
                game.Run()
            End Using
        End Sub
    End Module
    
    #End If
    those are just the basic codes, but how do I add something like a button?

  2. #2
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 10
    Location
    Denmark
    Posts
    521

    Re: XNA Help

    I'm afraid there is no adding controls to a XNA-window. You will have to implement your own buttons by drawing them (using sprites, models or programmed 3d-objects) in the Draw sub and implementing your own procedural variant of the events driving them by recording MouseState (or KeyboardState) structures.
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  3. #3
    Lively Member
    Join Date
    Jan 11
    Posts
    107

    Re: XNA Help

    Quote Originally Posted by ThomasJohnsen View Post
    I'm afraid there is no adding controls to a XNA-window. You will have to implement your own buttons by drawing them (using sprites, models or programmed 3d-objects) in the Draw sub and implementing your own procedural variant of the events driving them by recording MouseState (or KeyboardState) structures.
    could you give me an example of that?

  4. #4
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 10
    Location
    Denmark
    Posts
    521

    Re: XNA Help

    There are many examples online - this was the first link provided by google, and it seems to be fairly straight-forward (though it is ofc in C# as most (!) examples will be, since VB is a relatively new XNA tool). Most of the eamples, I browsed, were simple 2d-buttons implementing only equivalents of VB mousehover and mouseclick events. You can ofc expand this to include mesh-buttons with texture-change on hovering and zooming or rotation for dragging/clicking. The only limitation is your imagination.
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  5. #5
    Lively Member
    Join Date
    Jan 11
    Posts
    107

    Re: XNA Help

    Quote Originally Posted by ThomasJohnsen View Post
    There are many examples online - this was the first link provided by google, and it seems to be fairly straight-forward (though it is ofc in C# as most (!) examples will be, since VB is a relatively new XNA tool). Most of the eamples, I browsed, were simple 2d-buttons implementing only equivalents of VB mousehover and mouseclick events. You can ofc expand this to include mesh-buttons with texture-change on hovering and zooming or rotation for dragging/clicking. The only limitation is your imagination.
    Yes, but that's #C and im just using visual basic. There are almost no tutorials for visual basic

  6. #6
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: XNA Help


  7. #7
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 10
    Location
    Denmark
    Posts
    521

    Re: XNA Help

    Like I said - most of the examples will be in C#, since that has been the XNA language for years. Conversion shouldn't be too difficult though.

    But if you tell me how to add a template to VB Express 2010 (whilst keeping the one I use for C#), I'd happily write you a small example (the XNA Refresh didn't do much of anything, and the google search provided tonnes of outdated information from before VB was available as an XNA tool).
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  8. #8
    Lively Member
    Join Date
    Jan 11
    Posts
    107

    Re: XNA Help

    Quote Originally Posted by ThomasJohnsen View Post
    Like I said - most of the examples will be in C#, since that has been the XNA language for years. Conversion shouldn't be too difficult though.

    But if you tell me how to add a template to VB Express 2010 (whilst keeping the one I use for C#), I'd happily write you a small example (the XNA Refresh didn't do much of anything, and the google search provided tonnes of outdated information from before VB was available as an XNA tool).
    What do you mean with 'how to add a template?'
    You'll need visual studio for windows phone to create a xna game

  9. #9
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 10
    Location
    Denmark
    Posts
    521

    Re: XNA Help

    Well that explains my difficulty getting it to work in any of my 2 versions of VB.Net.
    I'm afraid you will have to work with the C# examples then or wait for someone else to post a VB reply (I advice the C# examples, since you will probably run into loads of more problems, where you will need guides, tutorials or examples, and learning to read C# will pretty much be a prerequisite).

    Oh and by template, I meant project template (ie. the ones you click when you choose a new project). Without a template it is quite tedious to begin a new XNA project, since you will have to start with an empty project and manually do everything that the template does (references, content, base-classes etc.).
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  10. #10
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,956

    Re: XNA Help

    I have not used XNA under VB.Net myself since at last check the XBox did not support the VB dll and I have only worked with C# in XNA but I found a project template here http://www.codeproject.com/Articles/...sual-Basic-NET looks like it is for VB 2008 but may be able to adapt it to VB 2010. May be worth a look.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •