|
-
Aug 21st, 2012, 02:15 PM
#1
Thread Starter
Lively Member
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?
-
Aug 21st, 2012, 02:45 PM
#2
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)
-
Aug 21st, 2012, 02:55 PM
#3
Thread Starter
Lively Member
Re: XNA Help
 Originally Posted by ThomasJohnsen
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?
-
Aug 21st, 2012, 03:13 PM
#4
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)
-
Aug 23rd, 2012, 08:59 AM
#5
Thread Starter
Lively Member
Re: XNA Help
 Originally Posted by ThomasJohnsen
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
-
Aug 23rd, 2012, 11:37 AM
#6
-
Aug 23rd, 2012, 12:05 PM
#7
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)
-
Aug 23rd, 2012, 01:54 PM
#8
Thread Starter
Lively Member
Re: XNA Help
 Originally Posted by ThomasJohnsen
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
-
Aug 23rd, 2012, 02:33 PM
#9
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)
-
Aug 23rd, 2012, 06:05 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|