Discuss Scratch

VJChatur
Scratcher
27 posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

I need to detect a change in X and Y of the mouse pointer, but I can't find a way to do it.
I tried this piece of script, but it didn't work
when green flag clicked
if <<<(mouse x) and (mouse y)> = [???]>
> then
end

end

Last edited by VJChatur (July 30, 2022 17:32:13)

musicROCKS013
Scratcher
1000+ posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

You can do this script;

when green flag clicked
set [mouse-X v] to (mouse x)
set [mouse-Y v] to (mouse y)
forever
if <<(mouse-X) = (mouse x)> and <(mouse-Y) = (mouse y)>> then//checks if the current mouse position is the same as the last one.
set [Position changed? v] to [0]
else
set [Position changed? v] to [1]
end
set [mouse-X v] to (mouse x)//updates every frame
set [mouse-Y v] to (mouse y)
end
VJChatur
Scratcher
27 posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

I accidentally reported ur post. I am Very Sorry. But thanks for ur help! It helped me a lot! Very sorry for the bother!
VJChatur
Scratcher
27 posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

it did not really work, i think it would be better for u to know what im trying to make. Here's the link to the project.
https://scratch.mit.edu/projects/718180904/
RT_Borg
Scratcher
1000+ posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

Hi VJChatur,

I looked at your project, but it's not clear what you want to use this for.

Maybe instead of those “set position changed” blocks, you want to broadcast a message when the mouse changes?

when green flag clicked
set [mouse-X v] to (mouse x)
set [mouse-Y v] to (mouse y)
forever
if <not<<(mouse-X) = (mouse x)> and <(mouse-Y) = (mouse y)>>> then
broadcast [Mouse Moved v]
end
set [mouse-X v] to (mouse x)//updates every frame
set [mouse-Y v] to (mouse y)
end

and then somewhere else you can

when I receive [Mouse Moved v]
... // do something with the standard (mouse x) and (mouse y) blocks

Note, every time the first script detects a mouse move, it broadcasts (maybe once per frame, while the mouse is moving). Each time it does, any “receive Mouse Move” blocks restart. This may or may not be what you want, depending on the behavior you need in your project.

If you're not sure, and you give more details about what you're trying to do, we may be able to give more specific advice.

– RT_Borg
awesome-llama
Scratcher
1000+ posts

Cant seem to find a proper block for detecting a change in mouse pointer X and Y

VJChatur wrote:

it did not really work, i think it would be better for u to know what im trying to make. Here's the link to the project.
https://scratch.mit.edu/projects/718180904/
The script musicROCKS013 shows is looking for mouse movements every frame. It works for that but if you don't want to know if the mouse has moved for each frame, you would have to slow it down to only check and update when needed.

I'm not sure what your goal is, I see the show/hide script with the wait 4 seconds so I assume you want the sprite to show/hide depending on whether the mouse has moved, but, what should the delay do?
Are you wanting the sprite to hide after the mouse has stopped moving for 4 seconds?

Powered by DjangoBB