# How to click a sprite once and have it move off screen?

**URL:** https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111
**Category:** CS Discoveries
**Tags:** csd-unit-3-lesson-14
**Created:** [January 22, 2020, 2:05pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111 "2020-01-22T14:05:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hcooper](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@hcooper](https://forum.code.org/u/hcooper)
#### Post date: [January 22, 2020, 2:05pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/1 "2020-01-22T14:05:21Z")

</div>

Hi, I have a student who is trying to click on her sprite once (a graduatuion cap) and have it then move off screen. We cannot seem to figure out how to just click once instead of repeating clicks to get it off screen.

---

<div class="post-metadata">

### Author: ![edavis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/edavis/32/4927_2.png) [@edavis](https://forum.code.org/u/edavis)
#### Post date: [January 22, 2020, 11:59pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/2 "2020-01-22T23:59:53Z")

</div>

Without having the link to the project, it’s a little hard to tell the best way about it. If you’d like to give us a link to the student’s project using the Share button we could look at it more closely.

---

<div class="post-metadata">

### Author: ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)
#### Post date: [January 23, 2020, 5:21am UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/3 "2020-01-23T05:21:42Z")

</div>

It does kind of depend exactly what you want it to look like, but one way to do it would be to use the blocks below …

![Screen Shot 2020-01-22 at 10.19.54 PM](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/0/054ffd9cfbe7f31e3468a2622807bbc19aebd604.png)

As @edavis said, if your program needs to work a little differently, we could help if you send a link!

Good luck!

Mike

---

<div class="post-metadata">

### Author: ![hcooper](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@hcooper](https://forum.code.org/u/hcooper)
#### Post date: [January 23, 2020, 1:48pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/4 "2020-01-23T13:48:40Z")

</div>

Thank you for the advice, here is the link to her project. My student wants the cap sprite to appear as if it is flying of the girl’s head on a diagonally with just one click.

Here is the link:

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

---

<div class="post-metadata">

### Author: ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)
#### Post date: [January 23, 2020, 2:49pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/5 "2020-01-23T14:49:33Z")

</div>

So, I created a variable (capFly) at the top of the program and set it to “false”. Then, inside the draw loop when the mouse is clicked, I set capFly to true. Then with another conditional block, I tell it if capFly is true, the x and y position of the cap need to change.

Here’s my remix of your student’s project.

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

Hope it makes sense.

Mike

---

<div class="post-metadata">

### Author: ![hcooper](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@hcooper](https://forum.code.org/u/hcooper)
#### Post date: [January 23, 2020, 3:19pm UTC](https://forum.code.org/t/how-to-click-a-sprite-once-and-have-it-move-off-screen/32111/6 "2020-01-23T15:19:34Z")

</div>

Thank you!!! This worked great!
