{"id":677,"date":"2013-11-24T14:39:30","date_gmt":"2013-11-24T13:39:30","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=677"},"modified":"2013-11-24T14:39:51","modified_gmt":"2013-11-24T13:39:51","slug":"vb-net-and-xna-article-17-simple-buttons","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=677","title":{"rendered":"VB.Net and XNA : Article 14 &#8211; simple buttons"},"content":{"rendered":"<p>Quick and dirty : buttons for XNA with mouse over and mouse click.<\/p>\n<p>3 rectangles, 3 textures, mouse inputs&#8230;<\/p>\n<p>The source code : <a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/XNA_demo_13.zip\">XNA_demo_13<\/a> .<\/p>\n<p>The video to illustrate.<\/p>\n<div style=\"width: 695px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-677-1\" width=\"695\" height=\"417\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/xna13.mp4?_=1\" \/><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/xna13.mp4\">https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/xna13.mp4<\/a><\/video><\/div>\n<p><code><br \/>\nImports Microsoft.Xna.Framework<br \/>\nImports Microsoft.Xna.Framework.Graphics<br \/>\nImports Microsoft.Xna.Framework.Audio<br \/>\nImports Microsoft.Xna.Framework.Content<br \/>\nImports Microsoft.Xna.Framework.Media<br \/>\nImports Microsoft.Xna.Framework.Input<\/p>\n<p>Public Class Game<br \/>\n    Inherits Microsoft.Xna.Framework.Game<br \/>\n    Dim graphics As GraphicsDeviceManager<br \/>\n    Dim SpriteBatch As SpriteBatch<\/p>\n<p>    Private easy As Texture2D<br \/>\n    Private medium As Texture2D<br \/>\n    Private hard As Texture2D<\/p>\n<p>    Dim color_a As Color<br \/>\n    Dim color_b As Color<br \/>\n    Dim color_c As Color<\/p>\n<p>    Dim rec_a As Rectangle<br \/>\n    Dim rec_b As Rectangle<br \/>\n    Dim rec_c As Rectangle<\/p>\n<p>    Public Sub New()<br \/>\n        graphics = New GraphicsDeviceManager(Me)<br \/>\n        Window.Title = \"Test\"<br \/>\n        Me.IsMouseVisible = True<br \/>\n    End Sub<\/p>\n<p>    Protected Overrides Sub Initialize()<br \/>\n        MyBase.Initialize()<br \/>\n    End Sub<br \/>\n    Protected Overrides Sub LoadContent()<br \/>\n        MyBase.LoadContent()<br \/>\n        SpriteBatch = New SpriteBatch(GraphicsDevice)<br \/>\n        easy = Content.Load(Of Texture2D)(\"easy\")<br \/>\n        medium = Content.Load(Of Texture2D)(\"medium\")<br \/>\n        hard = Content.Load(Of Texture2D)(\"hard\")<\/p>\n<p>        rec_a = New Rectangle(40, 40, easy.Width, easy.Height)<br \/>\n        rec_b = New Rectangle(40, 140, medium.Width, medium.Height)<br \/>\n        rec_c = New Rectangle(40, 240, hard.Width, hard.Height)<\/p>\n<p>    End Sub<br \/>\n    Protected Overrides Sub UnloadContent()<br \/>\n        MyBase.UnloadContent()<br \/>\n    End Sub<br \/>\n    Private Sub update_mouse()<br \/>\n        Dim mouse_state As MouseState = Mouse.GetState()<br \/>\n        Dim x As Integer = mouse_state.X<br \/>\n        Dim y As Integer = mouse_state.Y<\/p>\n<p>        If rec_a.Contains(x, y) Then color_a = Color.Red Else color_a = Color.White<br \/>\n        If rec_b.Contains(x, y) Then color_b = Color.Red Else color_b = Color.White<br \/>\n        If rec_c.Contains(x, y) Then color_c = Color.Red Else color_c = Color.White<\/p>\n<p>        If rec_a.Contains(x, y) And mouse_state.LeftButton = ButtonState.Pressed Then color_a = Color.Yellow<br \/>\n        If rec_b.Contains(x, y) And mouse_state.LeftButton = ButtonState.Pressed Then color_b = Color.Yellow<br \/>\n        If rec_c.Contains(x, y) And mouse_state.LeftButton = ButtonState.Pressed Then color_c = Color.Yellow<br \/>\n    End Sub<\/p>\n<p>    Protected Overrides Sub Update(ByVal gameTime As Microsoft.Xna.Framework.GameTime)<br \/>\n        update_mouse()<br \/>\n        MyBase.Update(gameTime)<br \/>\n    End Sub<\/p>\n<p>    Protected Overrides Sub Draw(ByVal gameTime As Microsoft.Xna.Framework.GameTime)<br \/>\n        GraphicsDevice.Clear(Color.CornflowerBlue)<br \/>\n        SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend)<br \/>\n        SpriteBatch.Draw(easy, rec_a, color_a)<br \/>\n        SpriteBatch.Draw(medium, rec_b, color_b)<br \/>\n        SpriteBatch.Draw(hard, rec_c, color_c)<br \/>\n        SpriteBatch.End()<br \/>\n        MyBase.Draw(gameTime)<br \/>\n    End Sub<\/p>\n<p>End Class<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick and dirty : buttons for XNA with mouse over and mouse click. 3 rectangles, 3 textures, mouse inputs&#8230; The source code : XNA_demo_13 . The video to illustrate. Imports Microsoft.Xna.Framework Imports Microsoft.Xna.Framework.Graphics Imports Microsoft.Xna.Framework.Audio Imports Microsoft.Xna.Framework.Content Imports Microsoft.Xna.Framework.Media Imports Microsoft.Xna.Framework.Input Public Class Game Inherits Microsoft.Xna.Framework.Game Dim graphics As GraphicsDeviceManager Dim SpriteBatch As SpriteBatch Private <a href='https:\/\/labalec.fr\/erwan\/?p=677' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,35],"tags":[],"class_list":["post-677","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-xna","category-34-id","category-35-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=677"}],"version-history":[{"count":2,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/677\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/677\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}