Lock the rotation property of each sprite in the group to the sprite's movement direction.
You animations and games are more realistic if the sprites turn in the direction they are moving.
Swarm of bees following the mouse.
// Swarm of bees following the mouse. var group = createGroup(); for (var i = 0; i < 100; i++) { group.add(createSprite(randomNumber(150, 250), randomNumber(150, 250), 2, 2)); } group.setAnimationEach("bee_1"); group.setScaleEach(0.5); group.setRotateToDirectionEach(true); function draw() { background("white"); drawSprites(); var direction=(180*Math.atan2(World.mouseY-200, World.mouseX-200))/Math.PI; group.setSpeedAndDirectionEach(10, direction); }
group.setRotateToDirectionEach(bool)
Name | Type | Required? | Description |
---|---|---|---|
bool | Boolean | Should each sprite in the group rotate to its movement direction or not. |
No return value. Changes output in the display after drawSprites() is called.
setVelocityXEach()
, setVelocityYEach()
, setVelocityEach()
, setSpeedAndDirectionEach()
drawSprites()
is called.Found a bug in the documentation? Let us know at documentation@code.org