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

#1 2008-05-21 11:03:08

angelren1225
Scratcher
Registered: 2008-05-21
Posts: 2

How to do "if sprite is clicked?"

I'm making a game like whac-a-mole, and I really need something like "if the sprite is clicked, change custom."
Is there anyway I can do that?
(ps: "when sprite is clicked" doesn't work for me, I really really need the IF statement!!)

Offline

 

#2 2008-05-21 11:52:18

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: How to do "if sprite is clicked?"

Try this:
[blocks]
<if><< <mouse down?> <and> <touching[ mouspointer >>
<end>
[/blocks]


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#3 2008-05-21 16:03:04

Zelda123
Scratcher
Registered: 2007-11-21
Posts: 1000+

Re: How to do "if sprite is clicked?"

JSO wrote:

Try this:
[blocks]
<if><< <mouse down?> <and> <touching[ mouspointer >>
<end>
[/blocks]

Note that if you use this someone could just keep the mouse held down the whole time, while the when ____ key clicked is a test of one click.

Offline

 

#4 2008-05-21 17:50:49

S65
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: How to do "if sprite is clicked?"

Zelda123 wrote:

JSO wrote:

Try this:
[blocks]
<if><< <mouse down?> <and> <touching[ mouspointer >>
<end>
[/blocks]

Note that if you use this someone could just keep the mouse held down the whole time, while the when ____ key clicked is a test of one click.

A slightly more complex way, taking this into consideration:

[blocks]
<if><< <mouse down?> <and> <touching[ mousepointer > <and> <( MDown <=> 0 )> >
<set{ MDown }to(1
(do whatever)
<end>

<if>  <not> <mouse down?> >>
<set{ MDown }to(0
<end>
[/blocks]

Offline

 

#5 2008-05-21 20:01:21

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: How to do "if sprite is clicked?"

S65 wrote:

Zelda123 wrote:

JSO wrote:

Try this:
[blocks]
<if><< <mouse down?> <and> <touching[ mouspointer >>
<end>
[/blocks]

Note that if you use this someone could just keep the mouse held down the whole time, while the when ____ key clicked is a test of one click.

A slightly more complex way, taking this into consideration:

[blocks]
<if><< <mouse down?> <and> <touching[ mousepointer > <and> <( MDown <=> 0 )> >
<set{ MDown }to(1
(do whatever)
<end>

<if>  <not> <mouse down?> >>
<set{ MDown }to(0
<end>
[/blocks]

What I do is:
[blocks]
<when green flag clicked>
<forever>
<if><< <mouse down?> and <touching[ mouse-pointer ] >>
<wait until><not><mouse down?>>>
<end>
<end>

Last edited by coolstuff (2008-05-21 20:03:02)

Offline

 

#6 2008-05-23 12:03:34

angelren1225
Scratcher
Registered: 2008-05-21
Posts: 2

Re: How to do "if sprite is clicked?"

thank you all ^0^

Offline

 

Board footer