Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Better way to load objects?

Author
Message
Yodaman Jer
User Banned
Posted: 28th Feb 2008 23:07
I am designing a game that uses multiple platforms, all of which are the same model loaded again and again like so:



My question is, is there a better way to load this?
Maybe using a for..next loop could do it, but how would I place the platforms away from each other in that?
Or should I design the level in a 3D program and then use polygon collision?

Any tips would be greatly appreciated!


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Feb 2008 23:23
Use external level files which detail how to size/position the objects. At the start of each level, open the correct level file and use the data inside it in a For..Next loop to build the level.

TDK_Man

Yodaman Jer
User Banned
Posted: 28th Feb 2008 23:35
Can you point me to a tutorial that teaches such a thing please?
And thanks for the quick reply!


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Feb 2008 23:41
Hang on - I'll knock together a very simple example for you...

TDK_Man

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th Feb 2008 00:32
Here you go. I've kept it simple so you can follow what's going on.



Save the code snippet and the levels in the attachment into the same folder.

Run the snippet and press the number keys 1 to 5 to load the 'levels'.

If you look at the level files you will see I've commented the data for the first couple of objects. You can have as many objects in a level - just alter the first value so it matches with the number in the file.

You can also add data to the format - for example you might need an object scale value. Just alter the level loading procedure to match the data to load in.

I've not added a .X loading section but you can see how it would be implemented.

Feel free to alter the data values in the .lvl files to alter the 'levels'. And, you don't need the comments when you have the file how you want it - the program only reads in the values.

Finally, you might find it easier writing a utility which lets you place the objects with the mouse then creates the .lvl file rather than creating them manually.

Good luck!

TDK_Man

Attachments

Login to view attachments
Yodaman Jer
User Banned
Posted: 29th Feb 2008 15:32 Edited at: 29th Feb 2008 16:08
Thanks TDK! I have told you this week that you rock?
I looked at the examples, and the more I look at it, the more I understand. Thanks for writing this up for me in so little time!

Yodaman Jer

EDIT:

I have another question and I don't feel like starting a whole new thread.

Is there an advantage to using MIDI's in games as opposed to MP3's?

Just something that I wondered about...


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th Feb 2008 16:43
No - these days it can be a disadvantage as I've found more and more machines aren't set up correctly to play MIDI files.

For compatibility, stick to MP3's and if you can, re-encode them at 48K (rather than 128K or 192K) to keep the sizes down.

Also, load them with Load Sound instead of Load Music.

TDK_Man

Yodaman Jer
User Banned
Posted: 29th Feb 2008 16:58
OK I'll check it out. Thanks!


Thanks BigAdd!!
KISTech
17
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 29th Feb 2008 18:56
@TDK,

It may have been an old thread that I was reading, but wasn't there a problem with DB when you delete and create a bunch of objects? or was that just DBPro that has (or had) that problem?


Don't think, just code.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Mar 2008 01:05
Quote: "Also, load them with Load Sound instead of Load Music."

Definitely!
If you load as a sound you can adjust the volume, speed, position etc of the sound. If you load as music I don't think you can even adjust volume! and the file types are restrictive.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Mar 2008 03:50
Quote: "wasn't there a problem with DB when you delete and create a bunch of objects?"


I've read something similar myself in the past, but to be honest I've never come across the problem. Maybe it's only when you delete a very large number of onjects.

If I remember correctly, I think it was a a memory leak - which is also still present in DBPro...

TDK_Man

Yodaman Jer
User Banned
Posted: 2nd Mar 2008 19:19 Edited at: 2nd Mar 2008 21:48
OK, TDK, I understand how loading level files work.

The problem is...
how do I create one?

And can I write the level in DarkBASIC (like I'm doing right now) and export THAT as a level file?
You know, so far my code looks like:


Could I export all of that kind of info into a .lvl?


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Mar 2008 20:26 Edited at: 2nd Mar 2008 20:28
Quote: "Finally, you might find it easier writing a utility which lets you place the objects with the mouse then creates the .lvl file rather than creating them manually."


You don't really have a lot of choice unless you want a lot of work.

I'll knock together a modified version of my earlier program to get you started. But, a quick question first - are the objects primitive DB objects like I used or all loaded .X files?

[Edit] Oops - re-read you opening post and see it's a loaded .X object. Give me a while to come up with something...

TDK_Man

Yodaman Jer
User Banned
Posted: 2nd Mar 2008 21:46
Wow, man, you rock!! Yes, it's all loaded .x files. I like those because they keep texture information and so can speed up your games by not having to load an texture every object. They're also harder to get into and modify.

Thanks!!

Yodaman Jer


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Mar 2008 20:07
OK, here's what I have so far...

It's a work in progress as I've decided to use it as a test bed for my GUI function collection as it's never been used in a real world situation before. As it happens the process as shown up a few bugs with the functions which I have fixed!

The intention is to create a generic level editor that can be modified by anyone to suit their requirements.

So, by all means download and have a play. It might point you in the right direction, but be aware that it will change!

Zip file attached.

TDK_Man

Attachments

Login to view attachments
Yodaman Jer
User Banned
Posted: 4th Mar 2008 15:29
Thanks TDK! That is an awesome program so far.
I just couldn't get the save level to work, and I also couldn't figure out how to rotate objects. It runs great though and seems to be pretty stable. Thanks!

Yodaman Jer


Thanks BigAdd!!
Zelthor
17
Years of Service
User Offline
Joined: 12th Feb 2008
Location: in my Fort planning for world domination
Posted: 4th Mar 2008 18:50
Hey Yodaman!

I haven't looked at TDK's project,
but i've created a platform level builder myself.

http://forum.thegamecreators.com/?m=forum_view&t=125267&b=6

It's not yet refined, but i'll look into it, cos i'm gonna need it real soon for my own project
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Mar 2008 08:35
Quote: "I just couldn't get the save level to work, and I also couldn't figure out how to rotate objects"


Neither was enabled in that first version (it was only about an hour's work - just to get you started). It is in this one - and a load more!

The idea (when it's finished) is for users to adapt it for their own use by modifying the Load Level and Save Level sections so they load/save the required information.

Download: http://www.computechtenerife.com/levelmaker0_2.zip

Still unfinished, but getting there...

Using It:

Drag objects with the left mouse button (LMB) along the X and Z axis. Hold Shift key and use LMB to drag along the Y axis.

Rotate objects on the Y axis with the right mouse button (RMB). Shift+RMB - rotate on the X axis. Ctrl+RMB rotates on the Z Axis.

Tab Key - Cycles through the axis toggles.

Number Keys 1 to 7 - Camera views

U Key - Undo last action

F1 Key - Clone Object

F5 Key - Quick-Save Level

F9 Key - Quick-Load a Quick-Saved Level

Number 0 Key - Centre object at 0,0,0

Ctrl+Number 0 Key - Reset all object's angles to 0 (zero)

S - Save Level

L - Load Level

D - Delete Object

R - Set Oject's RGB Colour

Add Object: See Menu at the top of the screen

Numeric KeyPad:

7, 8 and 9 - Direct input an object's X, Y and Z Position
4, 5 and 6 - Direct input an object's X, Y and Z Angles
1, 2 and 3 - Direct input an object's X, Y and Z Size

TDK_Man

Yodaman Jer
User Banned
Posted: 5th Mar 2008 16:09 Edited at: 5th Mar 2008 16:15
Wow, thanks TDK! I think you will go in the credits of my game now...lol. Thanks so much!

EDIT:

Quote: "...use the data inside it in a For..Next loop to build the level."


OK, does that mean that I can still basically program the level in the same way except that it will be just ever-so-slightly different?

And could every object in that level be programmed to use box collision much in the same way as THIS tut?

Just curious...


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Mar 2008 17:14 Edited at: 5th Mar 2008 17:28
Quote: "OK, does that mean that I can still basically program the level in the same way except that it will be just ever-so-slightly different?"


Take a look at the LoadLevel procedure in the level editor.

You will see that it is a general procedure which will load and place any number of objects - Eg: a level! It doesn't matter what objects they are, how many there are or where they are - that one single procedure loads and places all of them.

This is because a) the load level procedure is written to be flexible - it reads the data files and builds the levels using the instructions in them and b) the level data files are created sticking to strict rules.

So, you just have to make sure that each level data file contains all the required information for the procedure to correctly build the level. All level data files must also have the same format - each data item listed in the same order - hence the reason you use a level editor.

Also, don't forget that the data file can also contain other level data stuff like 'spawn points', start of game variable values, enemy data - and pretty much anything else you care to mention. As long as the data in the file and the load/save level procedures all match exactly it doesn't matter what's in the file.

When you have everything you need, you simply create all your levels and copy the working Load Level procedure from the Level Editor into your game.

One thing I have to address with my level editor is the positioning on the matrix issue. At the moment, the centre of the matrix is 0,0,0 in space. So, for an object to be positioned correctly on the matrix in your game, it would have to be sized and positioned in the same way.

To do this, you would have to either load the matrix into the level editor so you can place the objects on it, or add the ability to create and modify matrices in the level editor - saving the matrix data out to the level file along with the object data.

What matrix are you using in your game? Is it flat? Does it vary in size or position?

I think this version of the editor is close to being good enough to give it it's own thread, so I'll stop posting updates in this one.

TDK_Man

Yodaman Jer
User Banned
Posted: 5th Mar 2008 19:54 Edited at: 5th Mar 2008 19:55
Quote: "What matrix are you using in your game? Is it flat? Does it vary in size or position?"


Well, I'm not using matrices. What I'm doing is making a platforming game ( that takes place in the sky) that uses the same object over and over to build the level. I'm using static collision (code copied from the codebase originally made by Dark Coder) for every object.

SO far it's going good. I actually have the game posted in the WIP board.

I actually got it to run really fast, but I'd still like to use the technique you have been helping me with.

THANK YOU SO MUCH!!!

Yodaman Jer

P.S. In that topic I originally posted the thread as [DBC] my untitled game, but the game is now known as MAZE-O-MANIA. Just so ya' know.


Thanks BigAdd!!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Mar 2008 21:10
Quote: "What I'm doing is making a platforming game ( that takes place in the sky) that uses the same object over and over to build the level."


Even better! My level editor should be perfect for that!

I've just created a new thread for it and uploaded version 0.3 which has more options and quite a few bugs fixed.

Please feel free to use the other thread to give feedback on the way it works - just in case no-one else is interested and I've wasted my time...

TDK_Man

Lazlazlaz 1
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location: England
Posted: 6th Mar 2008 00:41
Quote: "I've read something similar myself in the past, but to be honest I've never come across the problem. Maybe it's only when you delete a very large number of onjects.

If I remember correctly, I think it was a a memory leak - which is also still present in DBPro..."


sorry to jump in on the thread.

Regarding this, when I try to create and delete a group of 10-20 3d plains my program freezes for half a second or so.
Would the only way around this be creating only one every few sync cycles?

As with most people I jump around which projects I work on and which I drop for a while.
Currently I'm back working on Sioux, a Hollywood Western RTS.

Login to post a reply

Server time is: 2025-06-04 01:46:38
Your offset time is: 2025-06-04 01:46:38