This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-13 22:15:02

kittenlols
Scratcher
Registered: 2010-01-21
Posts: 31

How to make your game run smoother.

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

 

#2 2010-03-13 23:23:14

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make your game run smoother.

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

 

#3 2010-03-14 05:30:06

kittenlols
Scratcher
Registered: 2010-01-21
Posts: 31

Re: How to make your game run smoother.

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

 

#4 2010-03-14 05:36:36

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: How to make your game run smoother.

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)


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#5 2010-03-14 05:44:21

kittenlols
Scratcher
Registered: 2010-01-21
Posts: 31

Re: How to make your game run smoother.

No, you got what I said wrong.

If it happened at 1.9, you wait 0.1 second before it checks.

Offline

 

#6 2010-03-14 06:02:41

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: How to make your game run smoother.

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?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

Board footer