Sprites not showing now and when they did was getting multiple lines on movement

My student is having trouble with the animation above and I don’t know how to help him.

Originally the sprite was showing and when moving was duplicating, we tried to fix it by adjusting the background to white and now they’ve disappeared.

Not sure how to have him fix it. Help is appreciated.

VaNessa

Hi VaNessa,

Here is what is happening with the student’s code:

Once time Setup (before the draw loop):

  1. put the chicken in a random place.
  2. draw all the sprites (the chicken)
  3. draw the background (covering up everything)
  4. put the seed in a random place
  5. draw all the sprites (chicken and seed)

Over and over (Inside the draw loop):

  1. If key is pressed
    1. move the chicken
    2. draw all the sprites (seed and chicken)

There are a couple problems with this. First, the student does not need to draw your sprites so many times. They don’t need to be drawn in the setup (outside the draw loop) at all. Just put them where you want them to go, and they will be drawn inside the draw loop.

Second, the background is only being drawn once. That’s why the chick is showing up over and over. Every time you move it, it is redrawn, but the code is not using “background” to cover up the old versions of it.

Third, all the sprites should be drawn automatically by default in every iteration of the draw loop, not just if something has been moved.

In general, you want to draw a background at the beginning of the draw loop so that old drawings are all covered up. Then, after you make all of your changes, using the if statements, you want to draw all of your sprites. drawSprites is usually only called once in the entire program.

So…

One time Setup (outside draw loop):

  1. Create all the sprites, and give them their default properties.

Over and over (in the draw loop):

  1. draw the background (covering everything up)
  2. Use conditionals, counter patter, etc. to make any changes to sprites
  3. draw all the sprites.

Elizabeth