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?
Printable View
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?
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.
what code would I use to render an image onto the background? (PNG image)
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++.
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!
I am glad you chose to read half of what I sent you.
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...
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
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.
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.
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.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
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
Thanks boops. That's exactly the kind of code I wanted. I will try it and see if it will work.
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... :(
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.
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.Quote:
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...
BB
Hey thanks I'll try it out. I will need XNA anyways because I'm making it X-Box/Game-pad controller enabled