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

#1 2011-03-21 19:23:45

jpsrolls
New Scratcher
Registered: 2010-12-09
Posts: 17

Two sprites touching

One of my students is making a game.  If the two sprites touch, the game is over.  We tried the repeat until loop, but he says it's not working.  Can someone help with the code?  Thanks in advance.  Judy

Offline

 

#2 2011-03-21 19:25:41

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Two sprites touching

[blocks]<when green flag clicked>
<forever>
<if><touching[ sprite _
<stop all> [/blocks] or <broadcast[ ___
<end>[/blocks]

That should do it, modify it if you need to.

Last edited by kayybee (2011-03-21 19:25:52)

Offline

 

#3 2011-03-21 20:21:15

jpsrolls
New Scratcher
Registered: 2010-12-09
Posts: 17

Re: Two sprites touching

Will try this.  Thank you.

Judy

Offline

 

#4 2011-03-21 21:13:46

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Two sprites touching

Or this:

<when green flag clicked>
<wait( 0.2 )secsc>
<wait until>
<touching[ EndOfGameSprite ]>
<stop all>

The wait 0.2 is really just to wait until the game is initialized, it may or may not be necessary


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2011-03-21 21:21:04

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Two sprites touching

MoreGamesNow wrote:

Or this:

<when green flag clicked>
<wait( 0.2 )secsc>
<wait until>
<touching[ EndOfGameSprite ]>
<stop all>

The wait 0.2 is really just to wait until the game is initialized, it may or may not be necessary[/blocks]

You could replace that with "wait until not touching EndOfGameSprite" to get the desired effect in the least amount of time.

Last edited by Kileymeister (2011-03-21 21:21:12)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#6 2011-03-21 22:54:10

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Two sprites touching

Yeah, I would say Kiley's is more effective because of no forever loops and not using "wait .2 sec"

But people who don't plan on having 100 sprites and 1000 scripts in a game should be able to use several forever loops in their projects without slowing it.

Offline

 

#7 2011-03-22 17:33:57

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Two sprites touching

Good idea Kileymeister.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer