Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 [Help] Moving Road
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Dizzee
Squire

USA
13 Posts

Posted - May 10 2006 :  11:19:56 PM  Show Profile  Visit Dizzee's Homepage  Send Dizzee an AOL message  Click to see Dizzee's MSN Messenger address  Reply with Quote
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!!

www.ClanTemplates.com
Free Clan Templates for the masses!

Walrus
Squire

Slovenia
34 Posts

Posted - May 11 2006 :  06:57:47 AM  Show Profile  Reply with Quote
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.


Edited by - Walrus on May 12 2006 05:26:26 AM
Go to Top of Page

Dizzee
Squire

USA
13 Posts

Posted - May 12 2006 :  1:15:57 PM  Show Profile  Visit Dizzee's Homepage  Send Dizzee an AOL message  Click to see Dizzee's MSN Messenger address  Reply with Quote
wow! thanks for the help, im checking it out now

www.ClanTemplates.com
Free Clan Templates for the masses!
Go to Top of Page

Walrus
Squire

Slovenia
34 Posts

Posted - May 12 2006 :  3:10:03 PM  Show Profile  Reply with Quote
If you have any trouble getting it to work or any further questions, just ask.
Go to Top of Page

Dizzee
Squire

USA
13 Posts

Posted - May 12 2006 :  4:49:27 PM  Show Profile  Visit Dizzee's Homepage  Send Dizzee an AOL message  Click to see Dizzee's MSN Messenger address  Reply with Quote
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.

www.ClanTemplates.com
Free Clan Templates for the masses!
Go to Top of Page

Walrus
Squire

Slovenia
34 Posts

Posted - May 12 2006 :  7:31:22 PM  Show Profile  Reply with Quote
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.

Edited by - Walrus on May 12 2006 7:33:15 PM
Go to Top of Page

Dizzee
Squire

USA
13 Posts

Posted - May 14 2006 :  12:19:28 PM  Show Profile  Visit Dizzee's Homepage  Send Dizzee an AOL message  Click to see Dizzee's MSN Messenger address  Reply with Quote
sweet, i will try that out once i get back to school on monday!


www.ClanTemplates.com
Free Clan Templates for the masses!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.1 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.