1

So, my other posts regarding the movement problem I was having got a reply from CAE_JONES about using frames instead of multiple timers, in an attempt to cut down on the amount of discrepancies, and therefore, issues between two machines.  I have done research since then that suggests that this approach tends to be the most used and the most pleasing option. 
I looked at the clock code that was posted.  I also found an old post in the BGT forum that contained the code, along with permission to use said code if we chose.  So I copied it and placed it into a file called clock.bgt.  Then, in my main bgt script, I include it, thenn assign a variable to it:  clock C; just as I do with my ball class, ball B.  Problem is, when I try to run my script now, I get the following errors:
On line: 27 (7)
Line: clock C;
Error: No default constructor for object of type 'clock'.
Then, further down:
On line: 478 (15)
Line: speaker.speak(C.delay.elapsed());
Error: Use of uninitialized global variable 'C'.

Here's the code in clock.bgt.
class clock
{
timer time;
uint frame = 0;
double delay = 5;
clock(double fps)
{
delay = 1000.0/fps;
time.restart();
}

void tick() {
double elapsed=time.elapsed-delay+1;
time.restart();
time.resume();
wait((elapsed>=delay) ? 1 : delay-elapsed);
frame++;
}

bool update()
{
if (time.elapsed>=delay) {
time.restart();
time.resume();
return true;
}
return false;
}
}
Where's the issue?
I have a couple of other questions.  This appears to me to be a fixed time step, which will probably work best in my case, especially with respect to the network side of thing.  However, I have two things that need to move at different speeds:  a player, and a ball.  Is it possible to have those two things move at different rates.  Obviously the ball is going to move faster than the player in some cases, or the player faster than the ball in others.  Given the frame method, what's the best and easiest way to accomplish this?
I'm also going to try to cut down on discrepancies further by integrating motion equations and velocity vectors.  I've been researching that over the last few days as well, and from what I see, I think I'll first try doing that with the semi-implicit Euler method.  It looks like it should work fine with the fixed time step, as long as the frame rates are small enough.  All feedback is welcome.  Thanks.

JLove

Thumbs up

2

You need to give the clock a framerate when you create it. Ex, clock c(50); creates a clock that runs at 50 frames per second. 60fps is pretty standard for ntsc video, going back decades, and 50fps for Pal. Since this is audio, and since BGT is not the fastest toolkit out there, a lower framerate is probably better.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up