Moving the cursor to the center vs. tracking it outside the frame

533 views
Skip to first unread message

a.st...@gmail.com

unread,
Nov 1, 2022, 9:53:31 PM11/1/22
to nodeGame
Hi Stefano,

One of my nodegames sports an avatar that always starts in the center of the screen and is controlled by the mouse cursor. The avatar moves whenever a mousemove event is triggered, which will cause the avatar to 'jump' to the current cursor position when the latter is not at the center, which it often is not depending on behavior in a previous round. This jumping behavior would not exist if the cursor could be forcibly moved to the center of the screen prior to the avatar's appearance in that location. But javascript apparently does not allow this level of control of the cursor (problem #1).

For a solution, I'm subtracting the offset of the cursor's last position from the center prior to the avatar's appearance. That way the avatar moves smoothly from the center out, as desired. The resulting issue, however, is that this offset can accumulate over rounds, to the point that the user might need to move the cursor outside the document entirely in order to make the avatar reach an intended location. However, problem #2 is that my current implementation of mousemove* no longer triggers events outside the document/element, such that avatar cannot move beyond a given point and thus not reach the intended location.

Any suggestions on how to bypass either problem #1 (forcibly moving cursor position to the center) or problem #2 (allow mousemove events outside the frame)?

All the best,
Arjen


*
W.getFrameDocument().body.addEventListener('mousemove', function (event) {
  ...
});

shakty

unread,
Nov 2, 2022, 2:08:56 PM11/2/22
to nodeGame
Hi Arjen,

I must confess I haven't understood #1 problem. Can you re-explain it? Perhaps an image or two would help. #2 seems solvable, you could just register the event on the body of the page. If your problem is that your code runs inside the iframe, then you could do re-emit the event: node.emit('XXX', { ... }), and inside your iframe you can listen to it with node.on('XXX', ...).

Let me know. 

Cheers,
Stefano

-  

shakty

unread,
Nov 2, 2022, 2:11:15 PM11/2/22
to nodeGame
I saw your asterisk a bit late.

document.body.addEventListener('mousemove', function (event) {
...
}

should work (assuming this is a step callback). This should be in addition, with the event listener inside the iframe.

a.st...@gmail.com

unread,
Nov 2, 2022, 2:58:40 PM11/2/22
to nodeGame
Thanks for the swift response.

"This should be in addition, with the event listener inside the iframe."

Interesting, I hadn't thought of the possibility of having two event listeners. This seems to work for parts of the document that are outside the frame. However, do you think it'd be possible to keep tracking mouse movement outside the document, if that's at all realistic? Alternatively, would there be a way to put the mouse cursor back in the middle of the screen after every run (from the program, thus without requiring user action)? 

Kingsley Obi

unread,
Nov 2, 2022, 3:08:34 PM11/2/22
to node...@googlegroups.com
Please, friends I really need to learn JavaScript and practice well...
How and where should I start. And I have knowledge about HTML and CSS and little about JavaScript and Java 

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/7190728b-0c14-4a97-86e8-08475562bb50n%40googlegroups.com.

Can Çelebi

unread,
Nov 2, 2022, 3:15:18 PM11/2/22
to node...@googlegroups.com
Dear Arjen,

You can most certainly not manipulate the cursor position of a participant's pc due to security reasons. I implemented mouse tracking for a study and wanted to move the cursor to a specific initial position like you wanted but found out that this is not an option. I solved my problem by creating an initial blank screen with a small button that the participant needs to click to begin the round (once the participant clicks the button the experiment screen becomes visible). I am not sure if such a solution will apply to your position.

Best,
Can

--

Can Çelebi

unread,
Nov 2, 2022, 3:20:32 PM11/2/22
to node...@googlegroups.com
Dear Kingsley,

You do not have to learn Java to build experiments in nodegame. There are ample amount of sources online to learn javascript. Also you do not initially have to understand everything about javascript (js) to begin coding experiments in nodegame (such as prototypes). As you build more experiments depending on your needs you will keep learning new stuff about js and get better at it.

Best,
Can

shakty

unread,
Nov 2, 2022, 4:53:50 PM11/2/22
to nodeGame
Dear Kingsley,

Can is right, Java is not needed for coding in in NodeGame. Here are two good refs for JavaScript:


If you have other questions, please open a new thread, so keep this faithful to the original request.

Best,
Stefano

shakty

unread,
Nov 2, 2022, 4:55:57 PM11/2/22
to nodeGame
Events bubble up until the iframe. Outside the iframe you can still track mouse movements and emit events that influence the iframe. I am not aware of methods to move the cursor, as Can mentioned it is a security issue.

Arjen Stolk

unread,
Nov 2, 2022, 11:08:16 PM11/2/22
to node...@googlegroups.com
Thanks for the clarification. Regarding security, I'm guessing it'll be equally hard if not impossible to send codes over the serial port from within the game? I'm asking since I'm thinking of ways to sync up the game with an external device like an eye-tracker.

--
You received this message because you are subscribed to a topic in the Google Groups "nodeGame" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodegame/mwY9ZyXm23E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/168c77a1-0f95-44ad-a983-edfff84b3f51n%40googlegroups.com.

Stefano B

unread,
Nov 3, 2022, 4:46:45 AM11/3/22
to node...@googlegroups.com
I haven't tried connecting devices over the serial port, but in principle you could try to use some packages like this: https://www.npmjs.com/package/serial-io

You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/CAAiwptTq2PMnbReRjYVHnQeBj1N29wxqw3pMx%3DqVU_XFN_J2iw%40mail.gmail.com.

Arjen Stolk

unread,
Nov 3, 2022, 5:45:44 PM11/3/22
to node...@googlegroups.com
Thanks, Stefano. I'll have a look at that package.

Reply all
Reply to author
Forward
0 new messages