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.

Dark GDK / Game Loop, Object and Animation Speeds

Author
Message
Vlad
18
Years of Service
User Offline
Joined: 5th Oct 2005
Location:
Posted: 31st May 2006 13:01
Hi all

Sorry for the length of the post. I don't have code here and since it's more of a conceptual problem I don't think it's needed.

After some months of hardwork a friend pointed out - following a problem I detected - that I don't really have a game loop. After understanding how I could implement a state-machine (sp?) to my objects, I have to undertake some serious recoding in major parts of my code.

Although very frustrated, I'll undertake this task and redesign classes, objects and the game loop. But I need your help and advice with some questions.

Any time something happened, my main loop called the apropriate functions or methods in which the objects were animated in some way. Since I had separate functions, I had total control over how the animation was running (using dbSetObjectFrame), but I could only animate a set of objects and have the rest in a idle state.

What I want to implement is a state-machine where my objects have a flag (e.g.: int state) and depending on the flag they will be running the proper animation. My doubt is, how will have control on how the animations are running? I took a look at the forums, examples and the CHM file. I can animate with dbPlayObject, but how can I control the state after starting the animation and revert it to the desire state after it completed? As an example I'll use a flower since it's the main object in the game:

State 1 - The flower waves in the wind

If a flower is clicked it gets State 2

State 2 - The flower closes

State 3 - The flower changes texture

State 4 - The flower opens

I have all these 4 states working with dbSetObjectFrame in separate functions outside the game loop. How do I know an animation ended and the state should change? I'm really puzzled.

Second part of the problem. I want to be able to control animation speeds. Will dbSetObjectInterpolation or dbSetObjectSpeed do the trick?

Thank you for your time and answers and sorry for the length of this.

The only lazy people that can complete games are genius. You don't look like a genius, so you better stop being lazy.
Support your local Riker 9 Chapter.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jun 2006 03:01
The first trick is to know the start and stop frames for each state.

During your game loop call an object function that checks to see if it is still playing or looping:


int taPlayable::IsStillPlaying()
{
int ID = GetID();
return ((dbObjectPlaying(ID)||dbObjectLooping(ID))?1:0);
}

(The GetID() function returns the DgSDK object id associated with the object.)

You could have a function called in the game loop that does something like (pseudocode):

ID = GetID();
if ((dbObjectPlaying(ID)||dbObjectLooping(ID))) return;
if cur_state>1 and cur_state<4 then
cur_state++
else
cur_state = 1

endif
dbPlayObject(ID,startframe[cur_state],numframes[cur_state]);
/code]

dbSetObjectSpeed seems to work. Some of it depends on how you built the model.

Cheers,
Ancient Lady
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jun 2006 03:03
The 'code' tags didn't work.

Cheers,
Ancient Lady
Vlad
18
Years of Service
User Offline
Joined: 5th Oct 2005
Location:
Posted: 2nd Jun 2006 15:15
Thank you for your answer.

I know where the animations start and end.

I sorted something out yesterday, but the dbPlayObject is not working. I searched for an old thread I saw but couldn't find it where it was mentioned that dbPlayObject would have to be used with a diferent sintax.

Took another look at Dark Dungeon example and spoted something like this:

dbPlayObject ( objNumber, 320*160, 370*160 )

I tried something like that with my own object and frames and didn't work. So I built a small state system for testing:

State 1 - Idle Loop
State 2 - Animation 1 (no loop required)
State 3 - Animation 2 (no loop required)

And more or less part of the code I used:


And this is working. Would be easier to do it with dbPlayObject, but nothing I try works with it, even the use of *value like in the DarkDungeon example.

If someone can give a better hint, I would love to hear from you.

V

The only lazy people that can complete games are genius. You don't look like a genius, so you better stop being lazy.
Support your local Riker 9 Chapter.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Jul 2006 22:56
I've just checked my code (I've been busy with other stuff for awhile) to verify that I am using the 'dbPlayObject' command. And I am.

In what way is it not working when you use it?

Also what tool do you use to make your models? I use 3dsmax and have tried a variety of tools to convert to .x format. Different tools provide a different number of frames, sometimes with very strange ratios. In one case, there were 64 key frames in 3dsmax and the conversion tool ended up with a .x file with 2100 frames.

Try a test program that just loads the model and uses 'dbTotalObjectFrames' to get the number of frames the model actually has and display the value. 'dbTotalObjectFrames' returns an 'int' value. You might be surprised to find that there are more or less frames than you expect.

For some of my models, I also need to change the playing speed (in one case I need to use 5000 in order for the movement to be visible) by using 'dbSetObjectSpeed' before executing the 'dbPlayObject' command.

I thought there was something wrong with the 'dbPlayObject' until I discovered that my models were not quite what I expected.

Good Luck.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-05-18 20:25:21
Your offset time is: 2024-05-18 20:25:21