Rotate every sprite ionthe group to face the (x,y) coordinate.
In some animations or games you need sprites 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 group = createGroup(); for (var i = 0; i < 20; i++) { group.add(createSprite(randomNumber(0, 400), randomNumber(0, 400), 20, 20)); } function draw() { background("white"); drawSprites(); group.pointToEach(mouseX, mouseY); }
sprite.pointToEach(x,y)
Name | Type | Required? | Description |
---|---|---|---|
x | Number | The x-coordinate you want the sprites 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 sprites 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