I know how to use getXposition for IU Elements but I need to fetch and store the x,y locations of the arrow cursor.
Is this possible? Does the arrow cursor have a hidden IU element name? other techniques?
Thanks for your help
I know how to use getXposition for IU Elements but I need to fetch and store the x,y locations of the arrow cursor.
Is this possible? Does the arrow cursor have a hidden IU element name? other techniques?
Thanks for your help
I don’t think it does! But, I’ll check with the staff!
##Thanks for your help
@jkeays - actually, you can! Here’s a project I spun up to show how it’s done: https://studio.code.org/projects/applab/0612j9xfwCqDh9IUENFZWpyPZmScX5aVW3TFKCoAyTI/view
onEvent("screen1", "mousemove", function(event) {
console.log("X: " + event.offsetX + " Y: " + event.offsetY);
});
A couple of notes:
event.offsetX
to get the x value and event.offsetY
to get the y valueconsole.log
just “event” (and also try changing the parameter - keyup, keydown, mousemove, etc.). Lots of things to explore!Thanks. This will work as a work around but I guess I wasn’t clear in my request. I want a function/method to tell me where the drawing cursor is located as it moves around the screen and draws. In your solution, I have to manually move the mouse which is different than the drawing "turtle/arrow. Thanks so much. Unless we know the name of the IU element of the built in “turtle/arrow” I don’t think there is a solution. Thanks again! Peace!
Ah! I understand now.
Would something like this work where you periodically check the turtle’s location? https://studio.code.org/projects/applab/AS_GmV3Lgi84pAnpGiPUuMbqrPS0htrIrKmi8DM141M/view
var turtleX;
var turtleY;
for(var i=0; i<30; i++){
moveForward(50);
getXandY();
turnRight(25);
getXandY();
moveBackward(50);
getXandY();
turnRight(25);
}
function getXandY(){
turtleX = getX();
turtleY = getY();
console.log("X: " + turtleX + " Y: " + turtleY);
}
You are amazing!
I can’t believe I missed the getX() and getY() functions in Applab. As soon as one of my students asked for this info, I said to myself, there has to be a built function which grabs the location data of the turtle.
Thanks a million!
Peace