Home Lessons Apps Support About Consultations We create games Contact
Home Lessons Apps Support About Consultations We create games Facebook

Lesson 10: Coordinates of sprites.

Select the device which you develop the application for:
 

In this lesson we will see how the coordinates of child sprites (of composed characters) are transformed.
 

Start Game Pilot, select "Prepare demo project", then select the "10 Coordinates of sprites" project. Open the project. Touch the frog.

In this project, the frog character is a composite character.

Open the code of the frog character. In the head, the command Scale=50 is used. So we can say, the coordinate system for frog's child sprites is reduced 2 times.

If you touch the frog, state 7 will be executed. And then state 8 as well. In the 8 state, in the second line, there are the following commands:

Delay=300 dY[3]=-70 dY[2]=-30 dY[4]=5 Scale[5]=90 Scale[6]=90 Mp3=2 dX[7]=15 dY[7]=7 dX[8]=-15 dY[8]=-7 // mouth goes open, eyes look at the nose

The command dY[2]=-30 moves the head of the frog down. Since the coordinate system of the frog is transformed – in our case it is reduced 2 times – the head will move not by 30, but by 15 points, in the scene coordinates.

In other words, if we apply Scale=50 command, the whole frog will reduce 2 times and the distance of moving the head will be reduced 2 times accordingly.

This rule applies to all child sprites of a composite character. However, when we move the whole character using the command dX = -30, the character will move to 30 units regardless of its scale.

 

Task 1:

Download the Lesson010 folder on your computer.

Open file frog.stt and add the following commands (highlighted below) to the 8 state:

8: Delay=400
   Delay=600 dY[3]=-70 dY[2]=-30 dY[4]=5 Scale[5]=90 Scale[6]=90 Mp3=2 dX[7]=15 dY[7]=7 dX[8]=-15 dY[8]=-7 // mouth goes open, eyes look at the nose
   Delay=600 dY[3]=40 dY[2]=70 dY[4]=-5 Scale[5]=100 Scale[6]=100 dY[1]=30 dY[9]=-30 dY[10]=-30 dY[13]=-30 dY[14]=-30 // Croaking: mouth goes up, head goes up, body goes up, legs are still on their places
   Delay=400 dY[7]=-14 dY[8]=14 // eye movements
   Delay=400 dY[7]=14 dY[8]=-14 // eye movements
   Delay=400 dY[7]=-14 dY[8]=14 // eye movements
   Delay=400 dY[7]=7 dY[8]=-7 dY[3]=30 // eye movements, mouth goes closed
   Delay=700 dY[1]=-30 dY[9]=30 dY[10]=30 dY[13]=30 dY[14]=30 dX[7]=-15 dY[7]=-5 dX[8]=15 dY[8]=5 dY[2]=-40// body goes down, but legs are still on their places; eyes and head go back
   Delay=600
   Delay=600 dY=-30 // frog goes down
   Delay=600 dY=30 // frog goes up
   Delay=0 Slot[Touch_Self]=7 State=1

Now, run the project and touch the frog. At the end, the whole frog moves down and up by 30 points. Since the command dY = -30 does not refer to one of the child sprites, but to the character himself, the whole character moves by 30 units.

At the same time, when we move the head down using the command dY[2]=-30 (see the second line of the state), it moves by 15 points.

To see how the head moves, look at the three lines on the background. Note that during the first movement (down) the head makes the path from the top line to the middle one (15 points). During the last movement, the whole frog goes down by 30 points. If you look at the head now, you will see that the head follows the frog and goes down from the top line to the bottom one.

 

Task 2:

Add the string Delay=600 Angle=90 as shown below:

Delay=400
   Delay=600 dY[3]=-70 dY[2]=-30 dY[4]=5 Scale[5]=90 Scale[6]=90 Mp3=2 dX[7]=15 dY[7]=7 dX[8]=-15 dY[8]=-7 // mouth goes open, eyes look at the nose
   Delay=600 dY[3]=40 dY[2]=70 dY[4]=-5 Scale[5]=100 Scale[6]=100 dY[1]=30 dY[9]=-30 dY[10]=-30 dY[13]=-30 dY[14]=-30 // Croaking: mouth goes up, head goes up, body goes up, legs are still on their places
   Delay=400 dY[7]=-14 dY[8]=14 // eye movements
   Delay=400 dY[7]=14 dY[8]=-14 // eye movements
   Delay=400 dY[7]=-14 dY[8]=14 // eye movements
   Delay=400 dY[7]=7 dY[8]=-7 dY[3]=30 // eye movements, mouth goes closed
   Delay=700 dY[1]=-30 dY[9]=30 dY[10]=30 dY[13]=30 dY[14]=30 dX[7]=-15 dY[7]=-5 dX[8]=15 dY[8]=5 dY[2]=-40// body goes down, but legs are still on their places; eyes and head go back
   Delay=600 Angle=90
   Delay=600
   Delay=600 dY=-30 // frog goes down
   Delay=600 dY=30 // frog goes up
   Delay=0 Slot[Touch_Self]=7 State=1
   Rest

Run the project and see how the frog moves now. After turning, it moves up and down, according the commands dY=-30 и dY=30.

However, if you apply the command dY not to the whole character, but to one of the sprites (for example, for the head which is sprite 2), then the frog will move differently.

 

Task 3:

Instead of applying the command dY to the whole character, apply it to the head only. Substitute the strings:

   Delay=600 dY=-30 // frog goes down
   Delay=600 dY=30 // frog goes up

with the following ones:

   Delay=600 dY[2]=-30
   Delay=600 dY[2]=30

And look what happens now.

Instead of moving down in relation to the screen, the head of the frog moves to the left (down in relation to the frog).
 

So as you work on the project, the coordinates of child sprites will transform based on the Scale and Angle commands of the parent sprite.
 

- Download the archive with project files for this lesson -


Privacy Policy    Terms of Use     Copyright © Rais Garifullin