Sets the x direction velocity for all the sprites in a group.
A positive velocity parameter will move the sprite to the right. Must be used with the draw() function containing a drawSprites()
. You can also update the velocity of each sprite in a group using setSpeedAndDirectionEach()
, setVelocityEach()
, setVelocityYEach()
.
The default velocity is 0.
// The gray dots have all the same velocity. var group1 = createGroup(); for (var i = 0; i < 10; i++) { var sprite = createSprite(0, randomNumber(0, 400), 5, 5); sprite.shapeColor='red'; sprite.velocityX=randomNumber(1, 10); group1.add(sprite); } var group2 = createGroup(); for (var i = 0; i < 10; i++) { var sprite = createSprite(0, randomNumber(0, 400), 5, 5); group2.add(sprite); } group2.setVelocityXEach(randomNumber(1,10)); function draw() { background("white"); drawSprites(); }
group.setVelocityXEach(velocity)
Name | Type | Required? | Description |
---|---|---|---|
velocity | Number | The velocity of each sprite in the positive x direction, to the right. |
No return value. Changes output in the display after drawSprites() is called.
drawSprites()
is called.setColliderEach()
is called for group before it is scaled, the collider is not scaled. But if a group of sprites is first scaled and then the collider set, the scale is also applied to the collider.Found a bug in the documentation? Let us know at documentation@code.org