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

#1 2010-09-03 21:55:35

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Problem with recognizing one-time contact

Sorry for the probably stupid question, but I've just started and decided to first try my hand at making a pong game from scratch (no pun intended).  I have mostly everything down, but I want to make it so the background switches if you hit an object that appears in the middle of the screen after 30 seconds.  The if -> touching (ball) only counts if it is continuously touching the object.  I want it so it only needs to hit the object to change the background, i.e. the ball only has to travel through the object.

Thanks.

Offline

 

#2 2010-09-03 22:06:00

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Problem with recognizing one-time contact

You could use something like

Hide
wait (30) seconds
show
wait until (touching (ball))
broadcast (next background)

You can put this script in a forever block if you want to.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2010-09-03 22:07:25

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Problem with recognizing one-time contact

If I understand correctly, you have a sprite in the middle, and you want the background to change when the ball hits it? Then just have this on the sprite:

Code:

When green flag clicked
repeat until < game over >
    if touching [ball]
        broadcast [switch]
        wait until <not <touching ball> >
    EndIf
EndRepeat

And on the stage...

Code:

When I receive [switch]
next background

Hope that helps!  big_smile

P.S. <game over> is whatever condition(s) triggers a game over. (or a game over variable)

Last edited by Harakou (2010-09-03 22:09:04)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#4 2010-09-03 22:07:32

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Problem with recognizing one-time contact

M303MTL wrote:

Sorry for the probably stupid question, but I've just started and decided to first try my hand at making a pong game from scratch (no pun intended).  I have mostly everything down, but I want to make it so the background switches if you hit an object that appears in the middle of the screen after 30 seconds.  The if -> touching (ball) only counts if it is continuously touching the object.  I want it so it only needs to hit the object to change the background, i.e. the ball only has to travel through the object.

Thanks.

Use if touching, but put a 'Wait until [not <touching [object]>>]


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#5 2010-09-03 22:08:17

scratch_yoshi
Scratcher
Registered: 2009-06-12
Posts: 1000+

Re: Problem with recognizing one-time contact

Sprite:
http://scratch-yoshi.webs.com/scriptcaption.gif
Background:
http://scratch-yoshi.webs.com/scriptcaption1.gif

I got epicly outposted!  tongue

Last edited by scratch_yoshi (2010-09-03 22:08:44)


Retired from Scratch, but just the language itself. Not the forums.

Offline

 

#6 2010-09-03 22:18:55

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Re: Problem with recognizing one-time contact

Thanks for all the prompt responses guys, it works perfectly.

Offline

 

#7 2010-09-03 22:20:50

scratch_yoshi
Scratcher
Registered: 2009-06-12
Posts: 1000+

Re: Problem with recognizing one-time contact

M303MTL wrote:

Thanks for all the prompt responses guys, it works perfectly.

You're welcome!


Retired from Scratch, but just the language itself. Not the forums.

Offline

 

Board footer