Dizzee |
Posted - May 10 2006 : 11:19:56 PM Hey guys, Im very new to VB (took a class on it) and right now I am making a 2D action/shotting/racer.
Right now I am stuck on how to make the road move, I made the graphics for the road in PhotoShop. I alos have a set of 9 images that if i could some how make them switch between all of the images it would create a seemless animation of the road moving. I tried this using the game.picture = "/image.jpg" but it was to slow and would lag up the whole game bring the fps down to about 10.
Thanks if anyone can help me!
btw here is the code: http://exoload.net/uploads/506/1147285066.zip
and if you have any tips on better ways for me to write my code please help!! |
Dizzee |
Posted - May 14 2006 : 12:19:28 PM sweet, i will try that out once i get back to school on monday! |
Walrus |
Posted - May 12 2006 : 7:31:22 PM I tried using a Timer, just to see, and it didn't flash, so I think that must've been caused by sth else.
That said, the Timer control, while it has its uses, is in fact a bad choice for games. For example, if you set its Interval property to 1(millisecond), the Timer event is actually triggered much less often.
One way to slow the game down is to use the Sleep function: Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Put sth like Sleep 10 inside the loop.
Or, probably better, use sth like this:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Before the loop: Dim LastTime As Long Const Delay As Long = 1000 / 50 (change the 50 to sth else to get the speed you want)
Inside the loop: Do While GetTickCount < LastTime + Delay Loop LastTime = GetTickCount VB has a function called Timer that provides similar functionality as GetTickCount(as far as I can tell), but it doesn't really get the job done, it seems. |
Dizzee |
Posted - May 12 2006 : 4:49:27 PM Yeah everything is working, thanks so much!! and thanks for the help on ReloadTmr_Timer sub, ive been trying to think of a way to shorten that up, just couldnt think of it, (we never learned how to do that in class).
One thing, how can slow it down? I tried putting it in a timer and it made everything flash like crazy! I have no clue any other way of slowing it down. Wich is also why i used the timer for the bullets and the reload. |
Walrus |
Posted - May 12 2006 : 3:10:03 PM If you have any trouble getting it to work or any further questions, just ask. |
Dizzee |
Posted - May 12 2006 : 1:15:57 PM wow! thanks for the help, im checking it out now |
Walrus |
Posted - May 11 2006 : 06:57:47 AM Hello and welcome to the forum!
I had a look at the code. Seems pretty cool so far. I'm looking forward to seeing the game when you finish it.
Now, onto your question: The problem with the method you mentioned is(I believe) that the jpg picture has to be loaded everytime you change game.picture. Therefore, I added some code that loads the files in advance(before the loop) into an array of Picture objects. That speeds it up nicely.
As an alternative, why not paint the road using BitBlt, just like the car and the bullets? I did that too(it's currently commented out). That seems a bit slower, which I didn't expect... I don't think you can use Picture objects for BitBlt, so I added an array of Picturebox controls(not the same thing). Whichever you use, it makes the program load for a second when you run it(expected).
Also, I thought that if you used BitBlt, there'd be no need to clear the Picturebox everytime, since all of it is repainted. However, that doesn't work. I don't know why, but maybe you can figure it out, since you know more about BitBlt(probably).
Change the name of "openthrottle.jpg" into "openthrottle0.jpg" to make the code work.
Overall, the code seems very nice to me. I had no problem understanding it. I added a small improvement of the ReloadTmr_Timer sub.
Here's my version(.frm and .bas):
Download Attachment: OpenThrottle.zip<br>4.78 KB
EDIT: I fooled around with the code a bit more and came across some unexpected behaviour. Finally I realized that when you use BitBlt to paint the road, sth must still be loaded into the Picture property of the Game Picturebox. Otherwise, it doesn't work(properly). Frankly, I don't know why that is. |
|
|