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.
function draw() { console.log(mouseWentUp("leftButton")); }
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(); }
mouseWentUp(button)
Name | Type | Required? | Description |
---|---|---|---|
button | String | The mouse button you want to check, either "leftButton" or "rightButton". |
Boolean true or false.
Found a bug in the documentation? Let us know at documentation@code.org