180k views
0 votes
You need to update the code below to animate the fish to move from the right side of the screen to the left side of the screen. In the draw loop, what line of code do you need to add before drawSprites()?

You need to update the code below to animate the fish to move from the right side-example-1
User Jkoch
by
7.7k points

1 Answer

4 votes

Final answer:

To animate a fish to move from right to left on the screen, add the code 'fish.x -= 2;' before 'drawSprites()' in the draw loop.

Step-by-step explanation:

The correct answer is option fish.x -= 2; or similar. This line of code will move the fish 2 pixels to the left each time the draw loop runs, thereby animating the fish to swim from the right side of the screen to the left side.

Remember that the speed can be adjusted by changing the number; for a faster movement, you would use a larger number, and for slower movement, a smaller one.

The correct answer is option move(). In the draw loop, you need to add the line of code fish.move(-1, 0); before drawSprites(); to animate the fish moving from the right side of the screen to the left side of the screen.

The move() function in p5.js allows you to change the position of a sprite by specifying the amount to move along the x and y axes. In this case, fish.move(-1, 0); moves the fish sprite one unit to the left and zero units vertically.

User Aleksandr Ianevski
by
8.2k points

Related questions

1 answer
3 votes
141k views
1 answer
1 vote
52.0k views