sprite.pointTo()

Category:Sprites

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.

Examples

var sprite = createSprite(200, 200);
function draw() {
  background("white");
  drawSprites();
  sprite.pointTo(mouseX, mouseY);
}

Syntax

sprite.pointTo(x,y)

Parameters

NameTypeRequired?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.

Returns

No return value. Changes output in the display after drawSprites() is called.

Tips

  • Any changes to the properties of a sprite will not be seen until after drawSprites() is called.

Found a bug in the documentation? Let us know at documentation@code.org