-
Jan 16th, 2012, 07:17 AM
#1
Thread Starter
Lively Member
[RESOLVED] Semi-transparent menu over the top of XNA graphics
Hello friends. I am making a 2D sports game using XNA graphics. I would like to create a drop down menu from which the user can select various tactics. The menu will be a panel so that I can add in various sliders and check boxes, and it will drop down when the user clicks or hovers over a button.
Since this drop down menu will overlap with the ground, I would like for the panel to be semi-transparent so the user can still see the game in the background.
Does anyone here have any experience with this? If so, it would be greatly appreciated
-
Jan 16th, 2012, 10:13 AM
#2
Re: Semi-transparent menu over the top of XNA graphics
I have dabbled with XNA a bit, but I'm not very sure about this but can't you just use images with transparency and/or add transparency to your colors that you are using to draw the menu ?
-
Jan 16th, 2012, 10:55 AM
#3
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
Well the menu would just be a panel with various controls and stuff on it. I'm not sure if the XNA bit is really all that relevant, I just need to be able to create a semi-transparent panel that partially shows through whatever is underneath, even if it is XNA.
-
Jan 16th, 2012, 10:57 AM
#4
Hyperactive Member
Re: Semi-transparent menu over the top of XNA graphics
Why not just create a normal form and alter the opacity?
-
Jan 16th, 2012, 11:01 AM
#5
Hyperactive Member
Re: Semi-transparent menu over the top of XNA graphics
To follow on, I guess the above was a fairly vague concept...
Create a form which has no border, has reduced opacity, has several labels which act as the drop down menu buttons and the startposition is dictated by the other windows position.
-
Jan 16th, 2012, 11:11 AM
#6
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
I wasn't aware that you could alter the opacity of forms, I'll give that a shot.
-
Jan 16th, 2012, 11:15 AM
#7
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
Okay, that works very well. I'll just make sure I can do everything fully before marking this thread as resolved.
-
Jan 16th, 2012, 11:26 AM
#8
Hyperactive Member
Re: Semi-transparent menu over the top of XNA graphics
Glad I could help
-
Jan 16th, 2012, 11:47 AM
#9
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
I'm trying to rep you but it won't let me! Silly forum.
It looks nice but now I just need code that will close the form whenever I click elsewhere. I tried using the LostFocus routine from the form but it did not work.
-
Jan 16th, 2012, 11:52 AM
#10
Hyperactive Member
Re: Semi-transparent menu over the top of XNA graphics
How about for the translucent form:
vbnet Code:
Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load Me.Focus() End Sub Private Sub Form2_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus Me.Close() End Sub
-
Jan 16th, 2012, 10:28 PM
#11
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
Hmm I wrote this last night but must have forgotten to click Post:
I have tried the code you suggested but it still does not work. When I click elsewhere on the main form the popup menu form disappears but it does not close, it simply goes behind the main form.
-
Jan 17th, 2012, 02:41 AM
#12
Re: Semi-transparent menu over the top of XNA graphics
Programmin: XNA has the ability, in the content pipeline, to allow you to have pixels of a certain color drawn transparent. You can look into that possibly?
-
Jan 17th, 2012, 06:14 AM
#13
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
Visual basic has very poor support for xna, at least with what I have seen. Despite trying I haven't been able to get the content pipeline going. Also it is not xna drawing the menu, the menu just goes over the top.
-
Jan 17th, 2012, 06:53 AM
#14
Re: Semi-transparent menu over the top of XNA graphics
Here's an idea: use a timer to close the form if the mouse stays outside it for a number of seconds. A Windows.Forms.Timer is no good for this purpose because it stops ticking when the form is minimized. So instead use a System.Timers.Timer with AutoReset set to True (by default it is a one-shot timer). It ticks on a separate thread, and continues ticking even when the form is hidden. To close or fade the form from the timer's Elapsed event, you have to invoke a delegate.
Here's an example where the form (Form1) starts fading as soon as the mouse leaves it and closes after 10 seconds, regardless of whether the form is visible. It resets to its original opacity if the mouse reenters the form. I haven't tried it in combination with XNA.
vb Code:
Private WithEvents tim As New System.Timers.Timer With {.Interval = 100, .AutoReset = True, .Enabled = False} Private millisecondsLeft As Integer Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load tim.Enabled = False Cursor.Position = Me.PointToScreen(New Point(50, 50)) millisecondsLeft = 10000 Me.Opacity = 0.8F End Sub Private Sub Form1_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter tim.Enabled = False millisecondsLeft = 10000 Me.Opacity = 0.8F End Sub Private Sub Form1_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave tim.Enabled = True End Sub Private Sub tim_Elapsed(sender As Object, e As System.Timers.ElapsedEventArgs) Handles tim.Elapsed millisecondsLeft -= 100 Dim fod As New FadeOutDelegate(AddressOf FadeOut) Me.Invoke(fod) End Sub Private Delegate Sub FadeOutDelegate() Private Sub FadeOut() Me.Opacity = Math.Max(Me.Opacity - 0.02F, 0.05F) If millisecondsLeft <= 0 Then Me.Close() End Sub
BB
Last edited by boops boops; Jan 17th, 2012 at 06:57 AM.
-
Jan 17th, 2012, 07:28 AM
#15
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
BB,
Thank you kindly for the suggestion. About to hit the hay but will test it out tomorrow and let you know how it goes! Cheers.
-
Jan 18th, 2012, 08:42 AM
#16
Thread Starter
Lively Member
Re: Semi-transparent menu over the top of XNA graphics
BB,
I have actually changed my code so that the popup menu form stays visible until the button is clicked again. Things are working fine now. Thank you for your suggestion though.
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
|