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 / New to DB and need help moving cube

Author
Message
Dark Wichy
17
Years of Service
User Offline
Joined: 4th Feb 2008
Location:
Posted: 4th Feb 2008 20:20
im new to DB and am trying to create a simple game.

heres my code so far:

cls 0
make object cube 1,100

do
if leftkey() =1 then yrotate object 1, 5.0
if rightkey() =1 then yrotate object 1,-5.0
loop

but when i run it just moves back and forth by 5 but wont turn at all and i dont know how to make it go forward. if someone could help me i would really appreciate it.
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 4th Feb 2008 22:14 Edited at: 4th Feb 2008 22:15
welcome to the forums
- Have you read any tutorials yet?
- next time you post a code, use the code button, it's not a big a deal with this post, but it wil be when you post a 250+ line code.
now with that out of the way;

I'm not going to give you a working code, instead I'm going to give you hints, so you can make a working code.

If I'm correct you should already have had the error message "specified angle must be between 0 and 360 degrees". This is becouse yrotate object must be in degrees. Darkbasic uses the command wrapvalue(<var> to automaticly place numbers given between 0 and 360.

seccondly you should use the sync command. It makes sure the program updates once a loop (and not every time a command is given). Your program will run smooth if you use it.
So put "sync on" at the top of the code. This tels darkbasic to use the sync method (backbuffers and such)
then place "sync rate <var>" after it. this tells darkbasic how fast to update the screen. the human eye can see 24, but 30 or 60 is recomended.
finally place "sync" at the end of the loop so it will update the screen (else you'll see a black screen).

cls 0 was nicely placed but serves no purpose, since darkbasic already starts with a black screen and when you create 3d then darkbasic uses a blue background

Last you could use a varible to store the angle, then use yrotate to rotate the object by that value.

Note: Sorry if I come over a bit strong, english isn't my native language.

Login to post a reply

Server time is: 2025-06-04 01:48:08
Your offset time is: 2025-06-04 01:48:08