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.

Newcomers DBPro Corner / Positioning

Author
Message
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 4th Sep 2011 22:30 Edited at: 4th Sep 2011 22:56
I really need help with this. I've never been good at positioning objects, but I completely confused myself. Can someone help me?



Too lazy to make a signature.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 5th Sep 2011 04:10
First off, your function is named Place_Objects, but you are using sprites in your function instead of objects. Are you intending to use sprites or objects? Is this 2D or 3D?

I believe the TEXTURE BACKDROP command is back in DBP v 7.61, so you could use that for the background if you are making a 3D game. If you are intending on making a 2D game, then you could simply paste the background.id image to the screen at the start of the main game loop.

A terrain would not be something to use in a 2D game typically. If you are not using a terrain, but intend on using sprites defined in an array named terrain, I would choose another name, as that would be real confusing as terrains are completely different than sprites.

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 6th Sep 2011 09:07 Edited at: 6th Sep 2011 09:07
oh yeah, its 2D, but my question was should I do this


Or just hand position them?
Also im just not sure if i did it right lol.

Too lazy to make a signature.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 6th Sep 2011 11:26
Actually, you're not far off. Hand positioning is always a bad idea, as you'll hardcode in the values and if you ever make a change you have to recalculate everything (been there, done that, it was an absolute nightmare...)

Your current code is good, though, but I get the feeling it's not placing your grass images where you want them? I'll try and explain how 2D positioning works.

Say your program runs in a 1024x768 window - that means you have a bitmap of 1024xx768 pixels to draw on. (0,0) is in the top left, (1024,768) is in the bottom right. Now suppose your grass.png texture is a 256x256 pixel image. If you call
then you'll paste the grass image in the top left corner (g = grass in the diagram below):
__ __
|g_|__|
|__|__|

Now, say we want another grass image to make a pathway, well, just paste it at (256, 0) for this:
__ __
|g_|g_|
|__|__|

And finally (256,256) for this:
__ __
|g_|g_|
|__|g_|

So, your for-loop currently puts a horizontal strip of grass across the screen. All you need to do is modify it slightly to adjust for the width/height of the original image. You can either write:


where I've used 256 as the pixel width of the grass image
or

which is more general and won't break if you move to a different size of image.


A few things to note, though - even though you're creating a 2D backdrop to represent the "landscape" your player moves through, don't call it a terrain. A terrain in DBPro is a 3D landscape and obeys a whole different set of rules. Also, don't call your player an "object" - object implies 3D as well!

You might be better off trying a few different data types in your code. Maybe use "entity" for your player, and landscape for what you currently call "terrain":



Lastly, your background appears to be a single image that's always there - there's no need to log all the other items in your data type with it, just give it an image number and let it go at that. The whole point of types is that it links together relevant variables - logging the rotation of your backdrop is a waste of memory, because it will never rotate.

Hope this helps!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 8th Sep 2011 07:33 Edited at: 8th Sep 2011 07:38
@Robert The Robot
Wow thanks, one more question, on

should I just increase the number if I want to add more images? Or should I do something else?

also getting syntax errors on endfunction()
the one at the very end.

Too lazy to make a signature.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 8th Sep 2011 10:51 Edited at: 8th Sep 2011 10:53
Quote: "should I just increase the number if I want to add more images?"

Yes, but you can get more creative if you want. Use commands like "Array Insert At Bottom", "Array Insert At Top" to add new entries to the array on the fly. Or you could call this:

and treat your screen like a chessboard and use a couple of for-loops to put the sprites on screen:

This won't just drop in to your own code without a little work, but it should give you an idea. The possibilities are almost endless, and you can just choose whichever solution works best for your program.

Quote: "also getting syntax errors on endfunction()"

Ah, I should have spotted that . You don't need to repeat the name of the function with endfunction. For example:


and to call it you just type


You only put something after EndFunction if you want to return something, for example:


and to call this one, you type

and MyVar will be given the value 42.
Hope this helps!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 10th Sep 2011 19:14
Hey, can anyone teach me how to do a map editor type thing for a 2D sidescroller

Too lazy to make a signature.

Login to post a reply

Server time is: 2024-11-22 17:10:55
Your offset time is: 2024-11-22 17:10:55