Controlling Sprites

Topic

Controlling Sprites

Topic Progress:

In the previous lesson we learnt what sprites are and some features about them. Now we are going to learn how to control and manipulate the sprites.

The following link will allow you to remix a partially completed application. The sprites and some blocks of code are already generated for you. In this lesson we will be building from this application and giving the sprites some controls.

https://x.thunkable.com/projectPage/5ea2800cbc33abfbfb801042

Select the stage component and take a few moments to review the application’s features, such as the names and costumes of the sprites.

There are many ways a sprite can move. You can make it teleport to a coordinate, move forward in a direction, by dragging it around, and many more.

Navigate to the blocks tab and inspect the “events” blocks in the canvas blocks section.

Now drag in “when pointer is down on canvas1”

This will trigger any blocks of code inside this block’s do section when the screen is touched.

Now add “point at pointer” from direction and “set speed in pointing direction” from motion until you have blocks looking like the following.

Now run your application on your preferred device through Thunkable Live and see what happens when you tap the screen.

Now that we have got our character sprite with the ability to move, let’s try changing the costumes of the apple sprites. 

We want our character to eat the apple by moving over the apple and leave behind apple cores.

From the events blocks, we need to find the “when sprite1 collides with sprite2” and set it up like below.

Be careful to make sure you’re using the Apple_Type and not an individual sprites name, as we want the character to eat any apple.

Now from the looks tab, find the “Set sprite image number to” block and set it up like below.

Now when your character touches an apple they will eat it.

Run your Thunkable Live application to see the effects of this block. Make your character run into the apples and see what happens!

Have a play around with some of the other event, motion, and direction blocks before continuing on to the next lesson.

@

Not recently active