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 / 2D Game Questions

Author
Message
JJAC116
19
Years of Service
User Offline
Joined: 3rd Oct 2006
Location:
Posted: 4th Oct 2006 03:17
Hi . I am somewhat new to Dark Basic. I've designed the basics of my 2D multiplayer game. I have some problems now, however.

I have made a sprite. I want it to move through an enormous bitmap, but when it goes off the screen, the screen doesn't follow after it. I've pored over the instructions for two hours and can't find a way to solve this problem. Have any ideas?
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 4th Oct 2006 15:30
Bitmaps cannot be moved. (Maybe using copy bitmap and using negative position values but I doubt that).

The best way would be loading as an image, and not as a bitmap. images are very easy to position. Using paste image nr, x, y, you can move your background as you like.

The only think left would be detecting when the image should be used.

Let's say your sprite passed 500 pixels on the x-axis. There are 2 things that should happen at that moment:
- Stop the sprite. The only thing moving should be the background and not the player, else the player can move out of the screen.
- Move the background. In this case, the background should move in the opposite direction of the player with the same speed of the player.

You can do the same for the other sides with the same algorithm.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Krilik
20
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 5th Oct 2006 06:52
The way that Sven B suggested is the way I would go about doing it.

I wrote some quick sample code to give you an example:


You would still need to check to see if the background is at the end and beginning and adjust the player movement.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Oct 2006 16:30
Have you considered using a matrix?

Like a 3D terrain, made from lots of squares, you could have a tile sheet that is used on the matrix to make the backdrop, then draw your 2D stuff over the top, or even use 3D plains for everything.

Using plains instead of sprites, and using a matrix for a backdrop would be pretty fast and smooth, 2D in DB is quite slow so this is a good way to ensure smooth gameplay.

''Stick that in your text and scroll it!.''
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 12th Oct 2006 22:39
Good idea, Van B.

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12
JJAC116
19
Years of Service
User Offline
Joined: 3rd Oct 2006
Location:
Posted: 14th Oct 2006 01:26
Hi again Just what exactly IS a 'plain', and how do I make it?
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 14th Oct 2006 14:32
A plain is a flat 3d object. You make it using the "make object plain" command. There are a variety of 3d shapes available to make in DB, e.g.

make object plain number,width,height
make object cube number,size
make object sphere number,size
make object cone number,size
make object box number,width,height,depth
make object cylinder number,size

each object you make must have a different number, so if you wanted a plain with the size 50 by 50, and a box that is 50 wide, 20 high and 10 deep, you would type the following:

make object plain 1,50,50
make object box 2,50,20,10

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12
JJAC116
19
Years of Service
User Offline
Joined: 3rd Oct 2006
Location:
Posted: 14th Oct 2006 15:50
Hi again. So far, I used a plain and it looks great! But how do I make the black part transparent, like a sprite? Is it possible? Or would I have to shape the plain somehow exactly like the image?
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 14th Oct 2006 19:36
Don't worry about reshaping the plain ('cos that's not possible!). The "set object" command will do this for you. Take a look at the attached image. This was made with the following code:


"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 14th Oct 2006 19:38 Edited at: 14th Oct 2006 19:40
And the image attached here was made with this code:

Note the "set object" command. If you type this command into DB and press F1 for context help, it will give you a page of info on what all the numbers after the command mean. Hope this helps.

P.S. Sorry that the image is a smily face! It's the only thing I could do in a few seconds. The eyes and mouth are green 'cos the "set object" command can be used to set all black color to transparent. With this second image, the eyes and mouth would have been transparent if I had made them black!

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12
JJAC116
19
Years of Service
User Offline
Joined: 3rd Oct 2006
Location:
Posted: 14th Oct 2006 21:19
Thanks so much! It works!
JJAC116
19
Years of Service
User Offline
Joined: 3rd Oct 2006
Location:
Posted: 14th Oct 2006 21:19
Thanks so much! It works!
Sonic 91 Software
21
Years of Service
User Offline
Joined: 19th Mar 2005
Location: In a Cryptic Crossworld!
Posted: 14th Oct 2006 23:14
Glad to help. Best of luck with your game!

"Fight the good fight of faith,
Lay hold on eternal life"
-1 Timothy 6:12

Login to post a reply

Server time is: 2026-07-06 10:33:00
Your offset time is: 2026-07-06 10:33:00