Codesters FAQ is the official FAQ site for codesters.com. We will continue to update this blog with the most common questions we receive form teachers using Codesters.

Move sprites together

Code executes from the top down in Codesters so there isn't a way for multiple sprites to move simultaneously using actions. One sprite will always move after the next. Here is some sample code that makes it look like two sprites are moving forward together.

sprite1 = codesters.Sprite("person1")
sprite2 = codesters.Sprite("person2",100,0)

for counter in range(20):
    sprite1.move_forward(5)
    sprite2.move_forward(5)

This next example uses the Physics toolkit to set the x speed of the sprites. By disabling the walls, it allows the 2 sprites to move together off of the stage. The same thing could be done to get multiple sprites to fly up by setting the y speed and disabling the ceiling.

P1 = codesters.Sprite("person1",-50,0)
P2 = codesters.Sprite("person2",50,0)
P1.set_x_speed(5)
P2.set_x_speed(5)
stage.disable_all_walls()