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

#1 2007-06-01 00:22:50

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

'Mouse Released' sensor (one event per click)?

Some of my kids were making a "shooter" game where the crosshair moved with the mouse and you only got a hit when the crosshair and ball were touching AND you clicked to shoot (mouse button down).

However, tomorrow when going to keep score, it was clearly visible that you collected points for as long as the mouse button was held down and the sprites intersected, so if you just moved around with the button down you ran up the score.  Even a short click often generated several points each time.  I posted an example,  tennis sniper.

Ideally you only want one point per click.

In "real" mouse usage, the action for the click doesn't actually take place until the button is released, so as to only generate one event.  Would it be possible to get a "mouse released" sensor so this would work properly?

I can envision a messy workaround with some kind of timer or counter before it will register another hit, but that seems awfully complicated.  Am I missing something more simple?

Offline

 

#2 2007-06-01 02:08:48

paulmedwal
Scratcher
Registered: 2007-03-09
Posts: 100+

Re: 'Mouse Released' sensor (one event per click)?

I can think of a work-around that only involves adding one variable. Basically, it causes you to have to do a mouse up before you can get any more points, but it probably isn't the best solution. You can see the project and script at http://scratch.mit.edu/projects/paulmedwalhelp/8942

Paulmedwal


clutter.scratch.mit.edu Visit the Clutter site to create multi-scene stories and multi-level games with Scratch.

Offline

 

#3 2007-06-01 02:22:32

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: 'Mouse Released' sensor (one event per click)?

I use a "firing" variable.  It starts at zero.

When mouse down:
-if firing=0
- set firing to 1
- (run your firing script)
- (set firing = 0)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-06-01 14:32:07

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: 'Mouse Released' sensor (one event per click)?

You may be able to get what you want with

forever if mouse down
    do firing action
    wait until not mouse down

Offline

 

#5 2007-06-01 18:18:07

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

Re: 'Mouse Released' sensor (one event per click)?

Thanks Kevin, that last works well and adds the least amount of complexity.  I think I'll post in the enhancements thread elsewhere my wish for "mouse up" or perhaps "mouse click" to be added to Scratch.

Offline

 

Board footer