|
-
Nov 14th, 2011, 06:38 AM
#1
Thread Starter
Junior Member
Beginner in need of assistance with game loop VB 2008
Hello, i am new to this site, and also new to programming with visual basic, infact i only just started laerning it at IT class about 4-5months ago.
At the moment i am trying to build a program which creates source code for a program known as DSGameMaker. The program records the position my mouse is over a box which is 256px x 192px, the size of a DS screen, then outputs the location in the form of a "set x to variable " scenario. the aim is to get a long list of positions, which in the end in the DS game moves a sprite every frame, to the location that the mouse was recorded in, giving one the ability to make custom animation paths, like the freestyle custom path drawing tool in ms powerpoint.
One problem i am facing, is that the code operates inside a timer event, which until recently i have found does not work well reading large amounts of code. when i tried running the code that moves the sprite, in the recording timer event, my framerate dropped to about 5fps, when i moved it to a seperate timer event, it went down to maybe 20-40fps, asuming it should have been 60 to appear normal.
What i was attempting to do, to make the application more versatile, was make an rpg walker, which allows you to move a sprite over the box, and record its location, as to achieve a motion animation which could be used in rpg games like pokemon (or at least pokemon-like games), since moving 32pixels at a time and straight lines, is a bit tough with a mouse.
What i need, since i cant find one, is an example of a game loop that works with vb 2008! because timer events just aint cuttin it.
I dont yet understand the functions and all, which are neccesary to create it.
Could someone please post an example code? thanks!
I want to build a game soon as well, and for obvious reasons would find this very helpful.
Also some pointers on improving the code would be greatly appreciated.
-
Nov 14th, 2011, 04:03 PM
#2
Re: Beginner in need of assistance with game loop VB 2008
Take a look at XNA. It's Microsoft's Game-designer framework. The Game object has a built-in game loop.
It uses DirectX so it's about 1000x faster than the GDI+ business graphics system you're probably using.
An example of using it to make a Tetris program is in my signature, and searching for XNA on here should give other examples.
-
Nov 14th, 2011, 08:19 PM
#3
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
I would rather not use XNA, well, not yet anyway. Ive heard it changes the programming language and that it is harder than VB, though at least now i know its not a whole other program altogether, but just an addon since i dug deeper.
Is it at all possible to still build a proper game loop in vb 2008? like all those tutarials for making one in vb 6?
Ill try out XNA, but i cant download it for a while, (prepaid internet), and ide like to add the changes to my program soon.
-
Nov 14th, 2011, 11:39 PM
#4
Re: Beginner in need of assistance with game loop VB 2008
XNA is just a set of libraries that you use with VB. You add them as references like anything else.
Without XNA, your only other real option is Managed DirectX which is pretty dated and no longer being developed. It's the predecessor to XNA. Or a game-library that includes DirectX management. There's a good one by Draculsoft in the codebank.
You can get some better speed using old-school GDI, BitBlit and a lot of routines to make it halfway feasible, but it's probably 100x harder than using XNA.
You can set up a working sprite moving game loop in XNA in about 10-15 lines of code.
-
Nov 15th, 2011, 12:50 AM
#5
Re: Beginner in need of assistance with game loop VB 2008
DirectX itself already manages the loop and locks the framerate for ya at your monitors refresh rate. With vb.net 2008 you can learn directx9. Im already making 2D based tutorials on it based on the vb6 DX8 tutorials I made shown in my signature. Its just a slow process cause of my personal life but soon it'll be done even with a new improved tile engine tutorial designed to create massive size worlds no matter how big and it'll never slow using my personal algorithm I designed on my own. So keep a look out
-
Nov 15th, 2011, 03:26 AM
#6
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
Once again, this knowledge has come to me moments before reading the post.
If only every single explanation of XNA , actually said that it was a class library, and not refer to XNA as a suite . you can understand my confusion, also thanks for your help thus far, ill try XNA and see if it solves my problem!
-edit-
new problem, at school i downloaded XNA 3.1 at a friends and it says i cant use XNA because i do not have microsoft visual C# 2008 Express, or Visual Studio 2008.
since im not going to buy a version, it would seem im being forced to use visual C# express, unless, is there a version of XNA that will work with visual basic 2008 express? is there?
otherwise what would change in transitioning from whatever visual basic uses (i asumed it was C#), moving to C#?
Last edited by jpoopdog; Nov 15th, 2011 at 04:06 AM.
Reason: tried XNA, but didnt work, new problem
-
Nov 15th, 2011, 07:32 AM
#7
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
I just got it to work! i can now run XNA based projects.
Now, anyone got an idea on where i can find a gameloop example which just is just that, a loop with a set fps, in which i can move a square, and let a timer event record it.
Pretty simple. However i think i need some code and help learning all this, yes, there is a built in gameloop, but how do i access it, i dont have a template or anything , im stuck at square -1
Anyone reading this with a similar problem, this is how i fixed the problem. I installed C# which allowed me to install XNA 3.1, and then i ran C#, completely baffled, still unable to understand, i exited the program, then found i could now access XNA stuff in the resources tab, which i beleive is what i am looking for. now also XNA game examples such as tetris work, unfortunatley it doesnt use the game loop , so i cant reverse engineer it. other games i see, that i think do use the loop, use all these other forms and class pages, which the loop wont work without for some reason. anyway, im starting at the loop, can someone point me in the right direction? Everyone here will be mentioned in the credit/about / special thanks page of my app, which is going to grow into a (almost) universal multiplatform XY (Z) animator, for heaps more complex things. all i need is this loop.
BIG THANKS!
Last edited by jpoopdog; Nov 15th, 2011 at 08:13 AM.
-
Nov 15th, 2011, 09:16 AM
#8
Re: Beginner in need of assistance with game loop VB 2008
Here's some examples I made.
The first is a simple sprite movement example that shows how to make a new Game object (which has your game loop), load some graphics in as sprites and move them around.
Simple Sprite Movement Examples
The examples below are each only about 1-page of code using XNA and a simple 2D game library called FlatRedBall. I use FlatRedBall because you can use it to take over your Render loop. It gives you more versatility with sprites as well since it handles the simple math of movement and rotation; i.e. you can give a sprite an X,Y,Z "Velocity" and it'll just move by itself. It's not a requirement because you can do this yourself with just XNA. You just need to build your own movement functions:
Space Invaders Style Shooter with Collision Example
Asteroids Style Rotation and Shooting
-
Nov 16th, 2011, 01:13 AM
#9
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
The first example is a link to a page called "two layers of graphics" , i think your tutorial is worthy of its own page, if it doesn't already have one.
-
Nov 16th, 2011, 02:37 AM
#10
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
Could someone show me where and how i should include a gameloop into my project on the main form ? or so that i can move the blue box (or use a sprite instead somehow), over the black square, with its location being readable by the main form?
I understand the tutorial fine, its just that i dont know how this can be done in a form. there are literally hundreds of posts to people with bad loops and such, all being told " use XNA, and use its built in gameloop, its really simple", but none say how.
Heres a link to my Project page: http://jpoopdog.com/spriteAnim.html just click source Documents.
all i want is a gameloop that runs at a decent FPS. I will still use a timer to record the value, i just need the gameloop to move the box so the timer can read its location every few mS.
Thanks
-
Nov 16th, 2011, 01:56 PM
#11
Re: Beginner in need of assistance with game loop VB 2008
You don't use Forms at all. You make a Game object which you can set the height and width of.
-
Nov 16th, 2011, 07:43 PM
#12
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
If its all the same, i would like to keep my GUI, and thus forms. At least for now. I want to make a properly useable version of my application available for the time being until i can run the entire thing in an object.
The fact im running this as a form wouldnt happen to be the reason why my program begins to lag moving the sprite after the xy array hits around 300-600 or so , would it?
-
Nov 17th, 2011, 01:45 PM
#13
Re: Beginner in need of assistance with game loop VB 2008
The lag is simply from the GDI+ graphics system which windows forms uses. It's a software-based renderer with no hardware acceleration at all. It's also not very well optimized. When you make a Game object with XNA, you create a DirectX render-space. This can either be windowed (in which case it'll have a standard Windows frame around it) or fullscreen. Since it's DirectX and not GDI+, you have all the advantages of DirectX such as hardware acceleration. Of course, Windows Forms controls are also part of the Windows Forms system, and thus use GDI+ and typically can't be used in the DirectX window.
There are ways to set up a DirectX viewport on top of a GDI+ form, thus you can have your GDI+ elements as well as your DirectX render window, but thay're a little tricky.
-
Nov 18th, 2011, 02:17 AM
#14
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
I see, i suppose then this means i am left with no choice but to switch from forms to classes.
Oh well. :s
-
Nov 18th, 2011, 09:02 AM
#15
Re: Beginner in need of assistance with game loop VB 2008
Hit up the XNA developers forums. They got a lot of XNA objects that mimic things like textboxes, buttons and other "control panel" type items you can use in an XNA game. Most of these will be written in C#, but tent to exist as .dll libraries you can just add in.
Most of these will seem somewhat primitive too. The button and text-input class I picked up a while back were nothing more than a mouse-click sensitive block and box you can type in. This is because they are meant to be skinned with graphics.
-
Nov 18th, 2011, 09:39 PM
#16
Thread Starter
Junior Member
Re: Beginner in need of assistance with game loop VB 2008
I think maybe i should keep a form GUI, but everything would run in seperate windows.
essentially buttons and such for settings and changing variables would all be on the one panel, and the recorder, in another.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|