Results 1 to 14 of 14

Thread: Side-Scrolling In Form Application

  1. #1

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Question Side-Scrolling In Form Application

    I am making a video game in visual studio 2010 and want to know how to make side-scrolling. I have my background image on the form and since you can't see through a picture box, I can't do it that way. Is there a detailed way to doing this?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Side-Scrolling In Form Application

    I don't think there is any standard way, but I would guess that in most cases the images are rendered directly onto whatever surface you are using for the display. In that case, side scrolling would be the apparent result of drawing your image offset by the same amount in one direction or another. I would not expect the performance to be all that good if you are using GDI+, though.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    what code would I use to render an image onto the background? (PNG image)
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

  4. #4
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Side-Scrolling In Form Application

    Use Google.

    These are things that you should know before attempting to make a game.

    Because let's be honest. If you don't know how to control/render your environment, you're not going to know how to make any events and such.

    I would suggest looking up a VB game engine.

    Also, based off of your "company"s website, it seems you already know how to make games already with your experienced software developers and graphic designers...

    If you were serious about making games, i'd ditch VB and go straight to C++.

  5. #5

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    Quote Originally Posted by TCarter View Post
    Also, based off of your "company"s website, it seems you already know how to make games already with your experienced software developers and graphic designers...
    I have made tonnes of games in Visual Basic 6 but Bitblt doesn't work in VS2010 and thats where my trouble is! Also, the best answer you can come up with is: "Use google"? Seriously? That's the best answer you can come up with? You should definitely put more thought into helping people instead of saying that "You should know this" Forums aren't just for people to say use google on! You really think I didn't already try that? Google is much too broad for my needs!
    Last edited by Hack; Aug 26th, 2011 at 01:24 PM. Reason: Fixed Quote Tags
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

  6. #6
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Side-Scrolling In Form Application

    I am glad you chose to read half of what I sent you.

  7. #7

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    What is that supposed to mean? I HAVE ALREADY TRIED GOOGLE and it almost never helps. That's why I signed up for VBforums. Do you know how to code this stuff? I'm assuming not...
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

  8. #8
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: Side-Scrolling In Form Application

    Since you are too pissy to read it again, i'll summarize it for you.


    "I suggest you try looking up a VB Game Engine"
    Hell, i'll even do the work for you!
    http://www.google.com/search?aq=f&so...VB+Game+Engine

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Side-Scrolling In Form Application

    I have an idea...how about if everyone acts like the adult they would like everyone to believe they are.

    Only children get huffy and they get put in a time out.

  10. #10
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Side-Scrolling In Form Application

    Hi Revertive Death,

    Drawing a scrollable PNG image (with transparency/alpha blending) on top of the Form's background image is a fairly simple matter. You do it in the Paint Event. The example below will scroll a PNG image over the background using the left and right arrow keys. I think it's basically what Shaggy Hiker suggested, and I think it's worth trying because the performance may turn out to be adequate for your present purpose.

    Code:
    Public Class Form1
    
    	Private scrollImage As Image = Image.FromFile(enter your file path+name here)
    	Private scrollLeft As Integer = 0
    	Private scrollTop As Integer = 100
    
    	Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    		Me.DoubleBuffered = True 'you can also set this in the Designer.
    	End Sub
    
    	Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    
    		Select Case e.KeyCode
    			Case Keys.Left : scrollLeft -= 10
    			Case Keys.Right : scrollLeft += 10
    		End Select
    
    		'invalidate the area of the scroll image:
    		Dim r As New Rectangle(0, scrollTop, Me.Width, scrollImage.Height)
    		Me.Invalidate(r)
    		Me.Update()
    	End Sub
    
    	Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    		e.Graphics.DrawImage(scrollImage, scrollLeft, scrollTop)
    	End Sub
    
    End Class
    Some performance hints: 1. if either the scrollable image or the background image has to be rescaled extensively, use a pre-scaled copy. 2. only invalidate/update the changed area (as in the example above) rather than Refreshing the whole form.

    Other Graphic methods such as BitBlt and XNA make better use of graphics hardware so they can be faster. Your statement that BitBlt doesn't work in VB2010 isn't correct (although the syntax is slightly changed since VB6). It might be worth looking into that if you are already familiar with BitBlt and you find the above method too slow.

    BB

  11. #11

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    Thanks boops. That's exactly the kind of code I wanted. I will try it and see if it will work.
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

  12. #12

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    Quote Originally Posted by boops boops View Post
    Other Graphic methods such as BitBlt and XNA make better use of graphics hardware so they can be faster. Your statement that BitBlt doesn't work in VB2010 isn't correct (although the syntax is slightly changed since VB6). It might be worth looking into that if you are already familiar with BitBlt and you find the above method too slow.
    BB
    I coded it in and yeah, it's much too slow for my purposes. It also isn't very smooth... I recoded it for WASD and also scaled my image properly and I changed it so that it copied only .5% of the image each time at a faster rate but it was still a bit choppy...

    I used to code Bitblt ALL the time. I really liked it but I can't seem to find an updated version for VS2010. In VS, it says that vbsrc files and .hdc are not acceptable in my application so I tried finding something else. Also, I have the XNA framework installed, I'm just not sure how to use it as a game engine. I looked online and found only class projects not form ones and I'm far enough along in my current application to not want to start again...
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

  13. #13
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Side-Scrolling In Form Application

    Quote Originally Posted by RevertiveDeath View Post
    I coded it in and yeah, it's much too slow for my purposes. It also isn't very smooth... I recoded it for WASD and also scaled my image properly and I changed it so that it copied only .5% of the image each time at a faster rate but it was still a bit choppy...(
    Performance obviously depends partly on how many pixels are being updated as well as on the hardware. The GDI+ method works well enough if the Form and scroll image aren't all that big (I tried it with Form 800*600 and image 2000*500). At anything like full screen size it is probably going to be too slow for a game.

    I used to code Bitblt ALL the time. I really liked it but I can't seem to find an updated version for VS2010. In VS, it says that vbsrc files and .hdc are not acceptable in my application so I tried finding something else. Also, I have the XNA framework installed, I'm just not sure how to use it as a game engine. I looked online and found only class projects not form ones and I'm far enough along in my current application to not want to start again...
    Jenner posted a XNA Viewport class on this forum earlier this year - see this thread, post #11. The class inherits from panel, so once you build the project, the Viewport appears in your toolbox with a cogwheel icon. Then you can drag it onto your form and use it just like a Panel or a PictureBox. The link to the code is now dead, but maybe Jenner posted it in the VB.Net CodeBank or somewhere else on these forums. If you can't find it and Jenner doesn't resurface here, I could post my (modified) copy. I just tried running it again at full screen and I must say it provides excellently smooth scrolling, zooming and rotating.

    BB

  14. #14

    Thread Starter
    New Member RevertiveDeath's Avatar
    Join Date
    Aug 2011
    Posts
    13

    Re: Side-Scrolling In Form Application

    Hey thanks I'll try it out. I will need XNA anyways because I'm making it X-Box/Game-pad controller enabled
    Team Manager and Lead Software Developer for my company:
    http://www.infernalsoftworks.ca

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