Skip to Content

Sprite go "HOME"!

With a little explanation and planning you can get your sprites “home” correctly; we’ll explore a few common things they’ll need to do as their project levels advance.

iTCH, Coding Tidbit

Sprite Go HOME!

One of the most common frustrations I see with students is getting sprites back “home” after they run their creations.
Students oftentimes will reset their sprites manually, dragging them back to where they want them to be before they hit that start button.
With a little explanation and planning you can guide them to get those sprites “home” correctly; we’ll explore a few common things they’ll need to do as their project levels advance.


First, lets learn to walk!

Lets suppose to start that you put in some code to make your sprite glide across the screen like so:

The problem is.. this only works the very first time you do it. Your sprite is stuck at the destination and clicking the green flag a second time does nothing.

This is where you’ll often see your students grabbing the sprites on the stage and moving them back each time — the ideal learning opportunity.

Have them reflect on what needs to happen at the start of their project. See if you can guide them to thinking that at the beginning of the project they want their sprite to be in a specific place at the start. Perhaps — “So where do you want the sprite to start from?”.. .”Oh there, ok”.. “Is there another way you can have the sprite go to that location with code without dragging it there?”.. “A moveto block! Perfect, that will make it go there immediately at the start without even a blink of the eye”.

Another great tip is that the blocks of code in the main area update with the location you drag your sprite to. Have them position it where they want it to start and drag out a moveto block like so:

Now, lets go for a jog

Now, as the students projects get more advanced it’s important to “initialize” all the characteristics of our sprites that we might change during our program.

Here’s an example where we change the backdrop at the end of the project, we make our character costume change and the color effect on our character also changes after they reach their destination along with some other effects.

We have the same problem though as before. When we hit the green flag this only seems to work the first time. We have to reset the attributes of our character. ITCH helps us out a little, when you hit the green flag, it resets some of the attributes such as the graphic effects and the whatever our sprite was saying. However, the backdrop and the size and costume have to be set back to their “home” or starting condition. For now we are going to reset everything we change to get this working; to learn why, read on to our “Finally, we can sprint”, below.

Now we’re talking! This resets every one of our sprites attributes that we change in our program, so every time we run it, it first is put back to it’s initial state or “goes home”.


Our project is now jogging along nicely!

However, as you progress, you’ll find that you have other times you want to reset things; perhaps you have a multi-level game you are creating or you might have a button that you want to reset your character back to their starting spot. In that case you’ll need to follow along in our “Sprint to the Goal” section below.


Sprint to the goal

You’ll often want to separate out the initialization from the rest of the code, this helps in two ways. Firstly, you can re-use this code at other times, and secondly it makes it more clear what this part of the code is doing. Here’s our example broken into a message receiver below:



Here you can see how we have broken up the initialization or “go home” code into a broadcast receiver for “reset girl sprite”. This means we can call this code anytime we need to by sending out this message. One other example of using this here is when we receive the “end of game” message, our own sprite can respond to this by resetting itself back to the “home” state.

I hope you enjoyed this article; if you have any feedback or thoughts please leave them in the comment section below!

Find more tidbits on my blog here.