# Change background image(animation) when score reaches a number

**URL:** <https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486>\
**Category:** Unit and Lesson Discussion\
**Tags:** csd-unit-3, csd-unit-3-lesson-22\
**Created:** [December 14, 2018, 6:23pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486 "2018-12-14T18:23:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason.smith](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jason.smith](https://forum.code.org/u/jason.smith)\
**Post date:** [December 14, 2018, 6:23pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/1 "2018-12-14T18:23:41Z")

</div>

> **[Check out what I made](https://studio.code.org/projects/gamelab/OLN9TQ--42-v2gqAluCPukECtwD9NXzqj3nrZzF4b9k)**
>
> I wrote the code myself with Code.org

  
A student wants the background image(animation) to change to another background image(animation) once the score reaches a certain amount. I am wondering, if they should include an IF statement inside showScore in order for it to work. Again making sure the order is:

drawSprites  
showScore

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [December 16, 2018, 11:27pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/2 "2018-12-16T23:27:38Z")

</div>

Jason,

The above link isn’t set for sharing - but generally you want to draw the background sprite first and then change the costume based on the `if` statement. Try it out and then come back and let us know if it worked OR if you have further questions.

Brad

---

<div class="post-metadata">

**Author:** ![jason.smith](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jason.smith](https://forum.code.org/u/jason.smith)\
**Post date:** [December 17, 2018, 5:17pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/3 "2018-12-17T17:17:51Z")

</div>

I published this, so it should be shareable.

> **[Check out what I made](https://studio.code.org/projects/gamelab/OLN9TQ--42-v2gqAluCPukECtwD9NXzqj3nrZzF4b9k)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [December 17, 2018, 7:05pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/4 "2018-12-17T19:05:00Z")

</div>

Jason,

Sorry, still getting an error (see attached screenshot). This might be part of a bigger issue - might want to submit a bug report.

Brad

 ![48%20PM](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/5/54b2fa5954d75fe972350d093d970b06f5f60b4b.png)

---

<div class="post-metadata">

**Author:** ![elizabeth\_admin](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@elizabeth\_admin](https://forum.code.org/u/elizabeth_admin)\
**Post date:** [December 17, 2018, 7:18pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/5 "2018-12-17T19:18:37Z")

</div>

Your student is really close. She’s using the if statement correctly for the most part.

The problem is that she’s using two sprites for the background, rather than just changing the animation of one sprite. Right now, she creates both of the sprites, and the one that she creates second shows up, because it’s the one that’s on “top” of the other when all the sprites are drawn.

Then, in her background function, she resets the animations of those two sprites. This isn’t doing anything, though, because those two sprites already have the respective animations that she’s setting them to.

What she should do instead is create only one sprite, and to set it to the image that she initially wants for the background. Then, in the `Background` function, use the same if statement, but in both cases set the animation of that original sprite. This way the sprite just changes what it looks like, rather than having two completely separate sprites.

Elizabeth

---

<div class="post-metadata">

**Author:** ![elizabeth\_admin](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@elizabeth\_admin](https://forum.code.org/u/elizabeth_admin)\
**Post date:** [December 17, 2018, 7:22pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/6 "2018-12-17T19:22:08Z")

</div>

Also, it looks like sharing permissions might not be turned on for your student. For students under 13, the default is not to allow them to share Game Lab projects. Teachers can edit this setting in the teacher dashboard.

Elizabeth

---

<div class="post-metadata">

**Author:** ![jason.smith](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jason.smith](https://forum.code.org/u/jason.smith)\
**Post date:** [December 18, 2018, 5:55pm UTC](https://forum.code.org/t/change-background-image-animation-when-score-reaches-a-number/23486/7 "2018-12-18T17:55:01Z")

</div>

Thanks to Elizabeth\_admin for your help. We made the changes you suggested, 1 var background sprite, changes to a 2nd one not listed as a var.  
Thanks
