This site requires JavaScript, please enable it in your browser!
Greenfoot back
programmer274
programmer274 wrote ...

2013/5/17

Need help smoothing out game

programmer274 programmer274

2013/5/17

#
I recently posted my unfinished game to the gallery. It is called My Game and it needs some help. The problem is that whenever I try to move both characters at once the game goes really slow. Also, sometimes my character will fall through the platform and my object detection code only seems to intermittently work. If anyone has any suggestions for helping to smooth out the code that would be great.
davmac davmac

2013/5/17

#
You are calling Greenfoot.delay(...) in certain parts of the code, which delays the whole scenario including the other actor. You need to re-write the code to avoid calling Greenfoot.delay(...).
programmer274 programmer274

2013/5/17

#
what other methods would be an alternative to the wait one.
danpost danpost

2013/5/17

#
For any class you want to have a delay in, add the following:
private int delayTimer;

private boolean delay()
{
    if (delayTimer > 0) delayTimer--;
    return delayTimer > 0;
}
Then, enclose the action(s) that you want not to happen for a certain amount of time within an 'if' block using:
if (!delay()) {
    // code to run if not delayed
    // when action is executed, reset timer
}
To start (or reset) the timer, just set the value of the 'delayTimer' field to approximately sixty times the number of seconds you want it to delay for (so to delay for about 2 seconds: delayTimer = 120;).
You need to login to post a reply.