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

Lesson 11: Adding a scene.

Select the device which you develop the application for:
 

We will learn how to:
- add a new scene to a game;
- change to another scene from a character description (.stt-file).
 

As an example, we will take ready project with the penguin. Start Game Pilot, select "Prepare demo project", then select the "11 Adding a scene" project. Open the project.

We have created a similar project in the Lesson 9.

Let us imagine that the penguin came in Africa.

 

Task 1:

Download the background image BackgroundAfrica.png which you will need for the new scene.

Download the folder of the project "11 Adding a scene" to your computer as well.

Open the file Lesson011.sc and add a new scene:

 

- - - - - CODE BEGIN - - - - -

// Lesson 11. Adding a new scene

Scene Start
Png(Background,,,1024,768)
Person(penguin,1, 483,308) // Penguin
HeadTouch=0 // Penguin does not shake his head

Scene Africa
Png(BackgroundAfrica,,,1024,768)
Person(penguin,1, 483,308) // Penguin

- - - - - CODE END - - - - -

 

The name of the new scene is Africa. The background of the scene is BackgroundAfrica. And the character that acts in the scene is penguin. The penguin stays in the middle of the scene.

Copy the changed file Lesson011.sc and the background BackgroundAfrica.png to your iPad and run the project.

We don't see the Africa scene. This is because we didn't make the change between the scenes yet.

We can make the change like this: when one touches the head of the penguin, the penguin begins to shake its head and then it appears in Africa.

For this purpose, we will add a command at the end of the state 6 in the file penguin.stt (see the penultimate line):

// Head shaking
6: if TouchIndex<>2 Rest
   Delay=0 if HeadTouch=1 Rest // when the head is touched and it is shaking, ignore the next touches
   Delay=0 HeadTouch=1
   Delay=800 Angle[2]=-10
   Delay=800 Angle[2]=10
   Delay=800 Angle[2]=-10
   Delay=800 Angle[2]=0
   Delay=0 HeadTouch=0 // the head isn't shaking anymore, now you can touch the head again
   Delay=0 Scene=Africa
   Rest

 

Now, after we touched the head of the penguin and it shaked its head, we change to the scene Africa.

 

Task 2:

Add the string that allows to change the scene, to the project code.

Note that the penguin looks the same on the both scenes. It has the same size as well and makes the same movements. In the both scenes, we use the same character penguin.

Now, try to change the penguin on the Africa scene. Make it twice smaller and place it somewhere on the side.

We will still use the same file penguin.stt in the both scenes, but to make the character distinguish between the scenes, we will create a variable. We will change the value of the variable when the penguin changes to Africa scene.

We will add a general variable PenguinSize to the .sc-file. For each scene, we will set another value:

 

- - - - - CODE BEGIN - - - - -

// Lesson 11. Adding a new scene

Scene Start
PenguinSize=50
Png(Background,,,1024,768)
Person(penguin,1, 483,308) // Penguin
HeadTouch=0 // Penguin does not shake his head

Scene Africa
PenguinSize=25
Png(BackgroundAfrica,,,1024,768)
Person(penguin,1, 483,308) // Penguin

- - - - - CODE END - - - - -

 

In the penguin.stt file, add the following line to the state 1:

Delay=0 Scale = PenguinSize

Thus, if the scene Start runs, the value PenguinSize=50. However, if the scene Africa runs, then PenguinSize=25, that means, the penguin is twice smaller.
 

The code of penguin.stt file could look like this (the added strings are highlighted):

 

- - - - - CODE BEGIN - - - - -

Scale = 50
Slot[Touch_Self]=6

Parent[1]=0 Parent[2]=1 Parent[3]=2 Parent[4]=2 Parent[5]=3 Parent[6]=4
Parent[7]=2 Parent[8]=7 Parent[9]=2 Parent[10]=1 Parent[11]=1
Parent[12]=1 Parent[13]=1
Rest

1: Delay=0 Scale=PenguinSize // if Africa, make penguin smaller
   Delay=0 Img[1]=1 Z[1]=0
   Img[2]=2 Z[2]=2 X[2]=278 Y[2]=466 OX[2]=50 OY[2]=10 // head
   Img[3]=3 Z[3]=1 X[3]=182 Y[3]=313 OX[3]=50 OY[3]=50 // right eye
   Img[4]=4 Z[4]=1 X[4]=318 Y[4]=313 OX[4]=50 OY[4]=50 // left eye
   Img[5]=5 Z[5]=1 X[5]=53 Y[5]=42 OX[5]=10 OY[5]=35 // right pupil
   Img[6]=6 Z[6]=1 X[6]=13 Y[6]=42 OX[6]=10 OY[6]=35 // left pupil
   Img[7]=7 Z[7]=1 X[7]=250 Y[7]=200 OX[7]=50 OY[10]=50 // beak
   Img[8]=8 Z[8]=-1 X[8]=85 Y[8]=22 OX[8]=50 OY[8]=50 // beak - bottom part
   Img[9]=9 Z[9]=1 X[9]=260 Y[9]=0 OX[9]=50 OY[9]=50 // bow
   Img[10]=10 Z[10]=1 X[10]=100 Y[10]=450 OX[10]=80 OY[10]=90 // right wing
   Img[11]=11 Z[11]=1 X[11]=481 Y[11]=450 OX[11]=20 OY[11]=90// left wing
   Img[12]=12 Z[12]=-1 X[12]=150 Y[12]=-25 // right foot
   Img[13]=13 Z[13]=-1 X[13]=450 Y[13]=-25 // left foot
   State=2
   Rest

// Initialate movements
2: New=3 New=4 New=5 // execute new states 3,4 и 5
   Rest

// Breath
3: Delay=700 dS[1]=1 dS[2]=-1 dS[10]=-1 dS[11]=-1 dS[12]=-1 dS[13]=-1 dY[12]=3 dY[13]=3 dX[12]=1 dX[13]=-1 // breathe in
   Delay=700 dS[1]=-1 dS[2]=1 dS[10]=1 dS[11]=1 dS[12]=1 dS[13]=1 dY[12]=-3 dY[13]=-3 dX[12]=-1 dX[13]=1 // breathe out
   Delay=0 State=3

// Wings movement
4: Delay=800 Angle[10]=30 Angle[11]=-30
   Angle[10]=0 Angle[11]=0
   Delay=0 State=4

// Blinking and pupil movements
5: Delay=350 ScaleY[3]=0 ScaleY[4]=0
   ScaleY[3]=100 SCaleY[4]=100
   Delay=2000
   Delay=1000 X[5]=10 X[6]=10
   Delay=1000 X[5]=60 X[6]=50
   Delay=1000 X[5]=53 X[6]=13
   Delay=5000 State=5

// Head shaking
6: if TouchIndex<>2 Rest
   Delay=0 if HeadTouch=1 Rest // when the head is touched and it is shaking, ignore the next touches
   Delay=0 HeadTouch=1
   Delay=800 Angle[2]=-10
   Delay=800 Angle[2]=10
   Delay=800 Angle[2]=-10
   Delay=800 Angle[2]=0
   Delay=0 HeadTouch=0 // the head isn't shaking anymore, now you can touch the head again
   Delay=0 Scene=Africa
   Rest

- - - - - CODE END - - - - -

 

Task 4:

Make the changes described above in the files Lesson011.sc and penguin.stt and run the project.
 

Now, we will try to place the penguin somewhere on the side and not in the middle of the screen like it is in the Start scene. For this purpose, we will just change the coordinates of the penguin character in the .sc-file:

 

- - - - - CODE BEGIN - - - - -

// Lesson 11. Adding a new scene

Scene Start
PenguinSize=50
Png(Background,,,1024,768)
Person(penguin,1, 483,308) // Penguin
HeadTouch=0 // Penguin does not shake his head

Scene Africa
PenguinSize=25
Png(BackgroundAfrica,,,1024,768)
Person(penguin,1, 878,211) // Penguin

- - - - - CODE END - - - - -

 

Task 5:

Change the coordinates of the penguin for the Africa scene.

In the new scene, you can let the penguin move completely differently by adding new states in the penguin.stt file. You can use other characters as well (don't forget to add the new characters to the .sc-file).

Note that the PenguinSize value is a general value, because we added it to the .sc-file. Such values may be used by several characters if necessary.
 

- Download the archive with project files for this lesson -


Privacy Policy    Terms of Use     Copyright © Rais Garifullin