Clicking on different x,y of the same sprite

Is is possible to customize the areas of a sprite to
get a different response depending on where you
click without having to create a different sprite for
each ?

i.e.
Something like this:

Sprite A
When Click on x=200 to 250 & y=180 to 200
Do action A

Sprite A (again)
When Click on x=100 to 200 & y=150 to 180
Do action A

Tanks a lot for your feedback in advance

Daniel

You can get the mouse pos x relative to the top-left corner of sprite by subtracting its left from the mouse x. You can do the same for mouse pos y, you subtract the sprite's top from the mouse y

untitled script pic (1)

[scratchblocks]
((mouse y) - (my [top v] :: sensing))
[/scratchblocks]

[scratchblocks]
define run(a) when x=(200) to (250) and y=(180) to (200)
forever
if << mouse down >and<<<(x position)>(200)> and < (x position)<(250)>>and<< (y position)>(180)> and< (y position)<(200) >>>> then
set(time v) to(0)
repeat until <not< mouse down >>
change (time) by((1)/(30))
if<(time)>(0.2)>then
stop(this script v)
end
end
run(a)
end
[/scratchblocks]

Thank you very much !

Thank you ! I am going to try this :slight_smile:

You're welcome. Tell me if it works!

The standard way to do things like this is sprite nesting. See page 10 of the manual. You can make a combined sprite with as many parts as you want. They all move as a unit, but receive clicks (or collisions, etc.) independently. You can clone the whole thing all at once.

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.