# Flash/animate a sprite through frames

**URL:** <https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617>\
**Category:** Unit and Lesson Discussion\
**Tags:** csd-unit-3, csd-unit-3-lesson-22\
**Created:** [December 19, 2018, 4:59pm UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617 "2018-12-19T16:59:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lkeil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lkeil/32/5239_2.png) [@lkeil](https://forum.code.org/u/lkeil)\
**Post date:** [December 19, 2018, 4:59pm UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617/1 "2018-12-19T16:59:58Z")

</div>

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

After three lives are used, the students wants the YOU LOSE sprite (bb) to show up.  
He has created frames in the ANIMATION tab to make the sprite move like a .gif. When in the ANIMATION section, the sprite does flash through all the frames, but in the game, it goes to the first frame and stops, no flashing.  
How does one get the frames of a sprite to flash through on the game.

---

<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 24, 2018, 3:32am UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617/4 "2018-12-24T03:32:25Z")

</div>

Lena,

In all honesty I don’t know if GameLab supports .gifs. I know I’ve seen them in samples, but I don’t know if the one that students use support this. I’ll bump this question up to see if we can get answer from a developer.

Brad

---

<div class="post-metadata">

**Author:** ![lkeil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lkeil/32/5239_2.png) [@lkeil](https://forum.code.org/u/lkeil)\
**Post date:** [January 7, 2019, 4:49pm UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617/6 "2019-01-07T16:49:06Z")

</div>

It’s not a true .gif. He created it with layers In the animation section. It runs through the “layers,” when in the animation section, but in the game it does not.

---

<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:** [January 7, 2019, 9:51pm UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617/7 "2019-01-07T21:51:01Z")

</div>

@lkeil  
Hi Lena,

(I was on winter break but am now back.)

The problem is that he is creating a new sprite and setting its animation every time that function is called. So, in each iteration of the draw look, there is a new sprite that is starting again with the first frame of the animation.

For the most part, sprites should be created outside of the draw loop and only modified inside the draw loop. In this case, the sprite should be created outside the draw loop (at the end of the list of new sprites so it’s on top), and its visibility should be set to false. Then, when the user loses, the visibility should be set to true. This should fix the problem.

Elizabeth

---

<div class="post-metadata">

**Author:** ![lkeil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lkeil/32/5239_2.png) [@lkeil](https://forum.code.org/u/lkeil)\
**Post date:** [January 8, 2019, 5:35pm UTC](https://forum.code.org/t/flash-animate-a-sprite-through-frames/23617/8 "2019-01-08T17:35:22Z")

</div>

Thank you so much! I will pass this information along to the student.
