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 / walk cycle in dark basic?

Author
Message
blessmerized games
17
Years of Service
User Offline
Joined: 30th Dec 2008
Location:
Posted: 31st Dec 2008 04:19
how do i make a character walk in bark basic classic?
Quirkyjim
17
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 31st Dec 2008 16:17
What exactly are you asking for? You can just have an animated model/sprite and then change the x/y/z values...

~QJ
blessmerized games
17
Years of Service
User Offline
Joined: 30th Dec 2008
Location:
Posted: 31st Dec 2008 21:59
how do i setup and change the xyz values?
Robert The Robot
19
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 1st Jan 2009 16:18
Hi blessmerized games! Welcome to the forums and 2009! In answer to your question, it all depends on whether you want to work in 2d or 3d.

2d animations
For 2d, you can use "Paste Image" or sprites - the two are very similar, so we'll just use sprites as these are probably easier. Firstly, use a bitmap editor to create a series of images that make up the walking cycle. It's a bit like a Disney film, every frame in a scene is of the same character, but each frame is just that little bit different.

Each frame must be loaded into DarkBasic using either "Load Image" if each frame is a separate file, or "Load Bitmap" and "Get image" if all the frames are stored in a single bitmap image. IMPORTANT - all images when loaded in DB should be the same width and height!

Now we're ready to start the animation. Say the animation images run from 1 to 25. In the main loop, we call this command:
Sprite Sprite, X, Y, Image

Sprite is the animation number, X and Y are the screen coordinates of the top left corner, and image is the number of the image used when the sprite is drawn to screen. This examplecode shows what goes on, though don't take it as an example to compile!



An image will appear on screen at (50, 50) and each image of your animation will be played ("Inc Frame" makes the sprite move to the next animation frame every time the program loops around). When the animation comes to an end at frame 25, the variable Frame will increase to 26, so we just reset to 1 to make the animation loop again.

Now, suppose we have an animation of a character walking from left to right across the screen. At the moment, he'll just be walking on the spot. So, we increase the X-coordinate of the sprite every loop. How much we increase the x-value depends on how far the sprite appears to move in the animation frames:




With this, the sprite will move 2 pixels across the screen each time the program loops. You can change the y values as well, to allow full movement over the entire screen.


3d animations
DB uses a limb-based animation system for 3d objects. In a 3d model of a human, fpor example, the upper arm is a mesh, the lower arm is a mesh, and the hand is a mesh, but all three are linked together in a certain order called the limb hierarchy. As the upper arm mesh is moved, the lower arm and hand meshes automatically change position. Also, only the keyframes (the most important frames) need to be set as DB is clever enough to fill in the gaps and create smooth animation.

To use one of the sample objects (you probably have DarkMatter 1, so lets pick the knight figure for the sake of argument), you simply load it using "Load Object". To play the animation it contains, call "Play Object" to play the animation once only, or "Loop Object" to make the animation play forever.

Now, if you use the walking knight model, he (like the sprite) will walk on the spot. To make him move, you need to use the "Move Object" command. This will move the object the specified distance in the direction it is facing. So, bringing that together:



Two things to note - "Point Camera" is merely a hasty and not very good way of keeping the camera following the 3d object so you can see it move away. Without other objects as a reference point, you might not notice any movement at all.

The other thing to note is that again, the move distance may not be quite right for the animation. The animation and the actual movement produced are independant, and so you really have to play about with this until you find a value that makes it look good.

If you want to create your own 3d animations, you can do it manually with the rotate/position/scale limb commands. You can do it slightly moreeasily with a proper 3d animation program, like my Lightning Limbs . My site hasn't been updated in a while, but expect a newer version sometime in the next 2-3 months.

Hope this hasn't been too much of a bore!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 5th Jan 2009 01:31 Edited at: 5th Jan 2009 01:39
there is another possibility. If the object already has animation data you can simply use
play object [object number]
play object [object number] [from frame] [to frame]
loop object [object number]
loop object [object number] [from frame] [to frame]

play object will animate the character for one sequence, where as loop object will repeatably play the object. Additionally both Loop object and play object have optional parameters to specify at what frame the animation data will begin and end.

if the optional parameters are not specified, the animation data will begin at the first frame

bluestar4~
Caleb1994
17
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 5th Jan 2009 07:07
Bluestart4:

But that will only make him "walk" in place. animation and actual walking are 2 totally seperate things.

Robert the robot:

Move object is a great way of movement but if your going to want strafing then your best bet (actually i think your only bet) would be a newXvalue and newZvalue commands like so




and so on for the rightkey and forward and backward are the same just replace the wrapvalue command with just plane camangY#(or whatever your camera angle variable is) and then the 10 would be + or - (forward or backwards)
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 15th Jan 2009 11:19 Edited at: 15th Jan 2009 13:07
allow me to correct that a little - use the commands in my post to make the object animate or appear to be walking.

first, you will need to load an object that has animation data -
for the purpose of this tutorial we will load the object and set it to number one like so :
load object "somefile.x",1
now we will need to rotate or turn the object in the direction we want it to face. There are two alternate approaches to this. The first method is to simply use the turn object left or the turn object right command. The second alternative is to use the yrotate command , whitch is the most useful way if you need the program to internally keep track of the objects angle. lets say we want to turn the object 20 degrees to the right , we would then use

yrotate object 1,wrapvalue(object angle y(1)+20)
or
turn object right 1,20
Now that thats done, we need to make the character animate while moving it across the board. The following will now do this until the mouse is clicked:
loop object 1
repeat
move object 1,1
sync
if mouseclick()>0 : inc a : endif
until a>0
stop object 1

and there you have it.
bluestar4~

bluestar4~
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Jan 2009 21:45
you need to play the object first.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 22nd Jan 2009 17:42
loop object 1 is placed right before the main loop. It automatically plays the object BN2 (I take it you had been coding a all day or you would have noticed that in there).

bluestar4~

Login to post a reply

Server time is: 2026-07-05 00:01:52
Your offset time is: 2026-07-05 00:01:52