Rotate the sprite to face the (x,y) coordinate.
In some animations or games you need a sprite to point in the direction of a mouse action or another sprite. You can get the x and y coordinates from the mouse or sprite.
var sprite = createSprite(200, 200); function draw() { background("white"); drawSprites(); sprite.pointTo(mouseX, mouseY); }
sprite.pointTo(x,y)
Name | Type | Required? | Description |
---|---|---|---|
x | Number | The x-coordinate you want the sprite to turn towards. Usually a number from 0 to 400, but smaller or larger numbers off the display area will also work. | |
y | Number | The y-coordinate you want the sprite to turn towards. Usually a number from 0 to 400, but smaller or larger numbers off the display area will also work. |
No return value. Changes output in the display after drawSprites() is called.
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org