-
Jun 11th, 2009, 02:31 PM
#1
Thread Starter
New Member
Me.BackgroundImage Statement
Hi there, I'll explain this briefly as I need to be sure pretty quickly... basically, I'm developing a game. after the user gets 5 points, an alert box comes up saying "proceed to next level"... on the next (second level) I want the background image to change....
Now the default background is not a picturebox, it's actually part of System.Drawing.Bitmap
I am using the same form throughout the entire game, so when it says "Proceed to next level" the game stays on the same form... Here's my Select Case statement to tell it to change the background image:
Code:
Select level
Case 2
Me.BackgroundImage =
End Select
What comes after the =
I have incorporated the image as a resource, but what do I put after the = ?
I have tried putting the image file directory but I get errors that require debugging...
Look forward to your responses, and thank you in advance!...
-
Jun 11th, 2009, 02:32 PM
#2
Re: Me.BackgroundImage Statement
vb Code:
Me.BackgroundImage = new bitmap(filename)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 02:33 PM
#3
Re: Me.BackgroundImage Statement
or:
vb Code:
Me.BackgroundImage = my.resources.[resourcename]
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 03:05 PM
#4
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Thanks, you're a genius, I will rate you as your signature requests!
There is another question I would like to ask, if possible!
As there will only be a few levels in my game, how would I get it to automatically get it to go to another form that says "Game Over" when the score is at a certain amount of points? At the moment, after every 5 points the game moves onto a different level, but after 20 points (in the score) I would like it to automatically say "Game over".
I have a variable "score" ... Would I just do
Code:
If score = 20 Then
Me.Hide()
frmGameOver.Show
Or is it more complicated than that?
-
Jun 11th, 2009, 03:14 PM
#5
Re: Me.BackgroundImage Statement
that'd do it.
the easiest way to learn with that sort of thing is to try it + see.
if you still have questions after trying it, ask in the forum then.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 03:19 PM
#6
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Ok, cheers! That worked, although because I did a "Me.Hide" the game still runs in the background, so (the concept of the game is to dodge the falling apples by moving the character left and right with two of the keys) even when I've hidden the form, if I get hit by an apple, my alert box will still come up saying "You lost a life" (continuously until I die);
I could do a Me.Close, but I need the score to be retained so it can then be output onto a highscores table, what would you suggest?
-
Jun 11th, 2009, 03:23 PM
#7
Re: Me.BackgroundImage Statement
you could use:
vb Code:
If score = 20 Then
frmGameOver.Show
Me.close
end if
you need to go (in your design IDE menus) to:
Project-->Properties-->Application--> + set Shutdown Mode to: When last form closes
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 03:25 PM
#8
Re: Me.BackgroundImage Statement
Originally Posted by 13579
I could do a Me.Close, but I need the score to be retained so it can then be output onto a highscores table, what would you suggest?
i didn't spot that part. post your complete frmGameOver code + i'll show you how
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 03:36 PM
#9
Re: Me.BackgroundImage Statement
vb Code:
If score = 20 Then
dim frm as new frmGameOver(score)
frm.Show
Me.close
end if
then add this to your frmGameOver code:
vb Code:
Public sub new(_score as integer)
'_score is the number you passed to the new form
end sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 04:02 PM
#10
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Here's my frmGameOver code:
Code:
Public Class frmGameOver
Private Sub btnMainScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainScreen.Click
Me.Hide()
frmMainScreen.Show()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnHighScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHighScore.Click
frmHighScores.lstHighScores.Items.Add(playerUsername & ControlChars.Tab & ControlChars.Tab & score & ControlChars.Tab & ControlChars.Tab & score)
'Hides the screen and shows the high scores table.
frmHighScores.Show()
Me.Hide()
End Sub
End Class
Last edited by 13579; Jun 11th, 2009 at 04:08 PM.
-
Jun 11th, 2009, 04:06 PM
#11
Re: Me.BackgroundImage Statement
is it called frmGameOver or frmLevel2?
read post #9 again
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 04:09 PM
#12
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Ah sorry, didn't see post #9, forgot to refresh...
Yeah my code was for frmGameOver, I forgot to rename the form, but that's done now.
-
Jun 11th, 2009, 04:15 PM
#13
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Hi Paul, just added the bit to frmGameOver, got this error message
Code:
Warning 'Public Sub New(_score As Integer)' in designer-generated type 'RacingGame.frmGameOver' should call InitializeComponent method. H:\Unit 20\Race\RacingGame\frmGameOver.vb 20 16 RacingGame
-
Jun 11th, 2009, 05:10 PM
#14
Re: Me.BackgroundImage Statement
ok. try this:
vb Code:
Public sub new(_score as integer)
InitializeComponent
'_score is the number you passed to the new form
end sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 05:24 PM
#15
Thread Starter
New Member
Re: Me.BackgroundImage Statement
That seemed to work! Thanks... There is another issue though... After the fourth level (the end of the game), it shows my default alert box saying "Go onto the next level".
How do I get it to stop saying "Go on to the next level" after the fourth alert box? My code is currently as follows
Code:
If score >= leveltran Then
tmrCount.Enabled = False
msgres = MsgBox("Go on to next level", MsgBoxStyle.OkOnly)
spdmulti = spdmulti + 10
leveltran = leveltran + 5
level = level + 1
applesOnScreen = 0
tmrFly.Enabled = True
For i = 1 To 5
Me.Controls.Remove(picBadApples(i))
Call resetBaddie(i)
Next
Select level
Case 2
Me.BackgroundImage = My.Resources.[background]
End Select
How would I go about making sure my alert box doesn't appear when I get my 20 points?
Also, when it goes to frmGameOver, it closes that as well as the frmGame form... which is weird??? Any ideas?!
-
Jun 11th, 2009, 05:47 PM
#16
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Sorry that last bit didn't make sense.
At the end of the game, it closes both forms alltogether
-
Jun 11th, 2009, 05:48 PM
#17
Re: Me.BackgroundImage Statement
Originally Posted by 13579
How would I go about making sure my alert box doesn't appear when I get my 20 points?
Also, when it goes to frmGameOver, it closes that as well as the frmGame form... which is weird??? Any ideas?!
you need to use an if statement:
vb Code:
if level < 4 and score = 20 then
'show msgbox
end if
i'm not sure what you mean about the form closing?
did you see my post:
you need to go (in your design IDE menus) to:
Project-->Properties-->Application--> + set Shutdown Mode to: When last form closes
?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 06:01 PM
#18
Thread Starter
New Member
Re: Me.BackgroundImage Statement
I tried doing that (if statement) but it just corrupted the game (i.e. froze it in duration or closed it)...
Here is the full code for the msgbox:
Code:
If score >= leveltran Then
tmrFly.Enabled = False
msgres = MsgBox("Go on to next level", MsgBoxStyle.OkOnly)
spdmulti = spdmulti + 10
leveltran = leveltran + 5
level = level + 1
applesOnScreen = 0
tmrFly.Enabled = True
For i = 1 To 5
Me.Controls.Remove(picBadApples(i))
Call resetBaddie(i)
Next
Select Case level
Case 2
Me.BackgroundImage = My.Resources.[background]
End Select
If score = 20 Then
Dim frm As New frmGameOver(score)
frm.Show()
Me.Close()
End If
End If
-
Jun 11th, 2009, 06:06 PM
#19
Re: Me.BackgroundImage Statement
could you upload the project + i'll have a look at it?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 06:31 PM
#20
Thread Starter
New Member
Re: Me.BackgroundImage Statement
The folder is too big to upload, apparently :S
-
Jun 11th, 2009, 06:37 PM
#21
Re: Me.BackgroundImage Statement
use some sort of compression software, such as pkzip, to zip the project. then try again
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 06:45 PM
#22
Re: Me.BackgroundImage Statement
looking at it again though, try this:
vb Code:
If score >= leveltran Then
tmrFly.Enabled = False
spdmulti = spdmulti + 10
leveltran = leveltran + 5
level = level + 1
applesOnScreen = 0
tmrFly.Enabled = True
For i = 1 To 5
Me.Controls.Remove(picBadApples(i))
Call resetBaddie(i)
Next
Select Case level
Case 2
Me.BackgroundImage = My.Resources.[background]
End Select
if level < 4 Then
MsgBox("Go on to next level", MsgBoxStyle.OkOnly)
elseIf level = 4 and score = 20 Then 'change this if score could be 20 before level4
Dim frm As New frmGameOver(score)
frm.Show()
Me.Close()
End If
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 11th, 2009, 07:06 PM
#23
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Just tried your solution, it seems to jump to the next level and then the message box appears after the level has changed and not before it.
I'll get the thing uploaded onto a file sharing site tommorow
-
Jun 11th, 2009, 07:11 PM
#24
Re: Me.BackgroundImage Statement
ok. i'll have a look at it tomorrow
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 14th, 2009, 09:47 AM
#25
Thread Starter
New Member
Re: Me.BackgroundImage Statement
Hey Paul, I seem to have the script working now, apart from my scores and one other tiny glitch... The user has 3 lives, if they lose all of their 3 lives within each level, the game ends.
Then a message box saying "Game Over" appears, followed by a Yes.No message box saying "Would you like to play again?"
If the user selects "Yes", the game currently just re-enables btnStart and allows the user to carry on from where they died, I however, want the "Yes" button to go to the first level when the user clicks btnStart (Start)
Here is my code for that section...
Code:
Dim i As Integer
tmrFly.Stop()
MsgBox("Game Over")
If score >= hiScore Then
If MsgBox("New High Score: " & score & _
ControlChars.CrLf & "Would you like to try again?" _
, MsgBoxStyle.YesNo, "The End") = MsgBoxResult.Yes Then
highScore = score
lblHighScore.Text = hiScore
-
Jun 14th, 2009, 11:11 AM
#26
Re: Me.BackgroundImage Statement
you need to change your BackgroundImage to your first screen, reset score to 0, reset level to 1 + then enable btnStart
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|