mouseWentUp()
Checks if the mouse button specified was released.
Some interactive games use the mouse for the user to control the game. mouseWentUp()
generates a single true value when the mouse button is released, no matter how long the button is pressed. Use mouseDown()
to continually check if the button is pressed.
Examples
function draw() {
console.log(mouseWentUp("leftButton"));
}
Move to the Mouse
Have the sprite move in the direction of the mouse when button was released.
// Have the sprite move in the direction of the mouse when button was released.
var sprite = createSprite(200, 200);
var angle;
drawSprites();
function draw() {
background("white");
if (mouseWentUp("leftButton")) {
console.log("here");
angle=(180/Math.PI)*Math.atan2(mouseY-sprite.y, mouseX-sprite.x);
sprite.setSpeedAndDirection(10, angle);
}
drawSprites();
}
Syntax
mouseWentUp(button)
Parameters
Name | Type | Required? | Description |
---|---|---|---|
button | String | The mouse button you want to check, either "leftButton" or "rightButton". |
Returns
Tips
- When testing your games that use keyboard or mouse input make sure you click in the display area before you run, otherwise the Workspace will record your keyboard and mouse actions.
Found a bug in the documentation? Let us know at support@code.org.