VS 2008 Me.BackgroundImage Statement-VBForums
Results 1 to 26 of 26

Thread: Me.BackgroundImage Statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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!...

  2. #2
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    vb Code:
    1. Me.BackgroundImage = new bitmap(filename)

  3. #3
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    or:

    vb Code:
    1. Me.BackgroundImage = my.resources.[resourcename]

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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?

  5. #5
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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?

  7. #7
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    you could use:

    vb Code:
    1. If score = 20 Then
    2.     frmGameOver.Show
    3.     Me.close
    4. end if

    you need to go (in your design IDE menus) to:

    Project-->Properties-->Application--> + set Shutdown Mode to: When last form closes

  8. #8
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    Quote Originally Posted by 13579 View Post
    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

  9. #9
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    vb Code:
    1. If score = 20 Then    
    2.     dim frm as new frmGameOver(score)
    3.     frm.Show    
    4.     Me.close
    5. end if

    then add this to your frmGameOver code:

    vb Code:
    1. Public sub new(_score as integer)
    2.      '_score is the number you passed to the new form
    3. end sub

  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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.

  11. #11
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    is it called frmGameOver or frmLevel2?

    read post #9 again

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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.

  13. #13

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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

  14. #14
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    ok. try this:

    vb Code:
    1. Public sub new(_score as integer)
    2.      InitializeComponent
    3.      '_score is the number you passed to the new form
    4. end sub

  15. #15

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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?!

  16. #16

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    Re: Me.BackgroundImage Statement

    Sorry that last bit didn't make sense.
    At the end of the game, it closes both forms alltogether

  17. #17
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    Quote Originally Posted by 13579 View Post
    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:
    1. if level < 4 and score = 20 then
    2.     'show msgbox
    3. 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
    ?

  18. #18

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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

  19. #19
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    could you upload the project + i'll have a look at it?

  20. #20

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    Re: Me.BackgroundImage Statement

    The folder is too big to upload, apparently :S

  21. #21
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    use some sort of compression software, such as pkzip, to zip the project. then try again

  22. #22
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    looking at it again though, try this:

    vb Code:
    1. If score >= leveltran Then
    2.     tmrFly.Enabled = False
    3.    
    4.     spdmulti = spdmulti + 10
    5.     leveltran = leveltran + 5
    6.     level = level + 1
    7.  
    8.     applesOnScreen = 0
    9.     tmrFly.Enabled = True
    10.  
    11.     For i = 1 To 5
    12.         Me.Controls.Remove(picBadApples(i))
    13.         Call resetBaddie(i)
    14.     Next
    15.     Select Case level
    16.         Case 2
    17.             Me.BackgroundImage = My.Resources.[background]
    18.  
    19.     End Select
    20.     if level < 4 Then
    21.         MsgBox("Go on to next level", MsgBoxStyle.OkOnly)
    22.     elseIf level = 4 and score = 20 Then 'change this if score could be 20 before level4
    23.         Dim frm As New frmGameOver(score)
    24.         frm.Show()
    25.         Me.Close()
    26.     End If
    27. End If

  23. #23

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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

  24. #24
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    Re: Me.BackgroundImage Statement

    ok. i'll have a look at it tomorrow

  25. #25

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Oxford, United Kingdom
    Posts
    12

    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

  26. #26
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,091

    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

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.