Let's say you have a soccer game. For a goal sprite, you might have this..
forever
if touching ball
broadcast playerwin
So what happens, is your computer thinks like this.
COMPUTER X +1
GOAL TOUCHING BALL? FALSE
COMPUTER X +1
GOAL TOUCHING BALL? FALSE
COMPUTER X +1
GOAL TOUCHING BALL? FALSE
You do not need to check that 4 times a second. It's OK to only check it every 2 seconds. So change it to
forever
wait 2
if touching ball
broadcast playerwin
And this is what happens
COMPUTER X +1
COMPUTER X +1
COMPUTER X +1
GOAL TOUCHING BALL? FALSE
Now if computer is the CPU player, the movements will be smoother.
Offline
That's really interesting! I never knew that! Thanks for posting this, I might just use it to optimize some of my programs.
Although isn't 2 seconds a little too long? That will slow down gameplay considerably...
Offline
Well, think about this.. You already know if the ball hit the goal or not. The 2 second could be simply restarting the game, Also you won't actually wait 2 second, the average time you are waiting is 1 second.
Offline
I don't think this will work because that means you are checking ONCE every two seconds. So if something happened at 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 2.1, 2.2, 2.3, 2.4, etc, it wouldn't detect that.
EDIT: well this will work IF the ball can't bounce.
Last edited by juststickman (2010-03-14 05:37:09)
Offline
No, you got what I said wrong.
If it happened at 1.9, you wait 0.1 second before it checks.
Offline
kittenlols wrote:
No, you got what I said wrong.
If it happened at 1.9, you wait 0.1 second before it checks.
But what if the ball bounced off the goal by that time?
Offline