CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    65

    How can I make this work...

    Hi,

    In my game, I have 2 bitmaps (people), one facing forward and one downward. When I hit the `forward` button, I want one of the bitmaps to move forward and then I want it to change to ther other bit map (person falling) and I want that to fall.
    I am using timers as well. So far, I have only figured out how to move an object left, right, up or down, but not to replace one image with the next and carry out that specific procedure.

    I would appreciate it if anyone could give any code for this because I am in the middle of creating my game!!!

    Thanks

    Mark


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I make this work...

    have three picturebox (or three imagebox), two invisible, where you load the pictures you want to display and one visible, to show the picture you want.
    load the image or picture of faceup in the visible picture
    Move the picture visible
    change the image shown:

    'assuming you're using pictureboxes
    'faceup and facedown are the names of pictureboxes (visible = false)
    ' where you loaded the images
    picture1.picture = faceup.picture
    '...
    'move it
    'load the image of face down
    picture1.picture= facedown.picture



    You may improve this using pictureclip control (Microsoft PictureCip Control) and only one imagebox or picturebox. You can load one single image in pictureclip control, image done by adding all the picture you need in a single image (you can use paint), then setting rows and cols to obtain it divided in cells... have a look in msdn.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How can I make this work...

    Code:
    'Here is an example with imagebox. 
    'one form,
    'three imagebox,
    'one timer,
    'one commandbutton
    'Leave their defaults names.
    'Load in image1 the picture to
    'shown when moving from left to right
    'Load in image2 the picture for falling
    'Click on the command button.
    option Explicit
    
    private Sub Command1_Click()
      Timer1.Enabled = true
      Command1.Enabled = false
    End Sub
    
    private Sub Form_Load()
      Timer1.Enabled = false
      Timer1.Interval = 250
      Image1.Visible = false
      Image2.Visible = false
      Image3.Picture = Image1.Picture
    End Sub
    
    private Sub Timer1_Timer()
      static intCount as Integer
      intCount = intCount + 1
      Select Case intCount
        Case 1 to 4 'move
          Image3.Left = Image3.Left + Image3.Width
        Case 5, 6 'fall
          Image3.Picture = Image2.Picture
          Image3.Top = Image3.Top + Image3.Height
        'case 7= nothing, just wait
        Case is > 7 'reset
          Timer1.Enabled = false
          Command1.Enabled = true
          Image3.Picture = Image1.Picture
          Image3.Move 0, 0
          intCount = 0
          Exit Sub
        Case else
          'do you need to do something else?
    End Select
    
    End Sub


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    Last edited by Cimperiali; November 5th, 2003 at 03:38 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured