Android_1_12syncx - App Dev Empire

kingfishblacksmithΚινητά – Ασύρματες Τεχνολογίες

14 Δεκ 2013 (πριν από 7 χρόνια και 10 μήνες)

386 εμφανίσεις

Lesson 1

Welcome to the video part of the android Empire video course, the property of
The practical part of our course includes 12 comprehensive tutorials that will teach you how to develop
Android apps from A to Z so you don't have any probl
em even if you don't have any programming skills.

Make sure you also check our important articles and future updates inside the members area that will
help you promote the app, find traffic and get great sales! Without much further ado let’s get started.

Lesson 1

offers a step
by step guide on how to set up the development environment. You’ll find out
what components are installed with the development environment, how to configure the development
environment and gain practical skills on setting up a progra
mming environment. At the end of the
tutorial you’ll be shown how to create a test project and get a general idea of what it involves.

00:00 Development environment installation.

00:04 In order to develop the mobile applications on the Android platform,
you will need the
development environment.

00:11 I advise you to download it from nvidia website, because it provides everything that you need for
its development, and it is installed as one pack as opposed to the case when we download it from the


00:26 To install it we go to nvidia website,

00:34 Then we go to the section mobile development.

00:40 Then we choose Tegra Android Development pack.

00:45 Here you will be offered to download the installation file for the v
arious operating systems, such
as Windows, Mac OS and Linux.

00:58 Once you downloaded the installation file, you run it.

1:13 You will be offered to choose what you want to install, where you can select the components for
the installation.

1:29 It is bett
er to install everything by default.

1:33 Next, you will be offered to choose the folder where the development environment will be

1:43 After you installed the development environment just run it, it is already set up, and it will work.

1:55 Her
e is being started the development environment, let's create a test project.

2:03 Here we will be asked to enter its name.

2:12 Then we choose the device target, namely a version of Android on which an application will be
installed, we select 2.2 version.


Next we will be offered to select a package name, and we click finish.

2:38 Here is our test project, it is ready.

2:48 Let us run it!

2:59 As we can see, though not clearly that the application is running.

3:13 So, our environment is completely ready

for further development.

3:19 In

the next lesson, we will decide what game to create. First, we define our tasks, and second, we
will present the full gaming process.

Lesson 2

The second tutorial is all about the game interface concept and how its elements connect with one
another. You’ll find out how to implement various classes and create game resources to be used later in
the game development.

00:25 Now let's create the gam
e. The first thing we look at the tasks, and the second we look at the
gameplay. Our task is to create a Scroller game. A spaceship is flying through the corridor and is
collecting bonuses. The player's goal is to collect a certain number of bonuses, not c
olliding with walls of
the corridor.

00:26 Then we look at the application interface. It will include Main Menu, Pause Manu, Menu Lose,
Menu Win, and Game. Now we can see the connection between our elements of the interface, so let’s
look at each interface


1:01 Main Menu

We will place the buttons in Main Menu, such as Start Button, Game Title and Background.

1:20 Pause

Pause menu will consist of Background that has two buttons, Continue Button and Main Menu Button.

1:37 Win and Lose Menu

These menus will consist of Background, Header Text and Main Menu Button.

1:56 Game

n the game screen will be placed Playing Field, Pause Button and Score Panel. In order to implement
the gameplay, we should bring Ship Class, Bonus Class, Barrier Class an
d Background Class into play.

2:19 Then let’s take a look at Resources, which we will use in our application. These Resources are Main
Menu, Background, Title and Start Button.

2:42 Next in Pause, Win, Lose Menu will also be used some Resources as Buttons
and Background. In the
game screen we will be using Ship, Bonus, Barrier, Background and Pause Button Resources.

2:14 In the next lesson we will prepare the application resources and create our project.

Lesson 3

This tutorial
will give you an idea of
how to plan a product, you’ll elaborate the se
quence of actions
you need to implement. As an example of planning we’ll use the Scroller game and will show you how to
define user interface and how the modules should interact.

00:16 Let us gather the
resources we need. According to the plan, which is drawn up in the last lesson,
we need music, sounds, font and different images for our game.

00:17 Let’s create for each type of resource its own folder for convenience.

00:33 We need 4 types of music for
Main Menu, namely they are for loss, inside the game, playing and

00:47 Now we will do that.

00:48 First, we make the resource.

1:00 This great resource belongs to a good musician Kevin MacLeod who writes great music and
distributes it for free on

the condition that he will be mentioned in the credit titles of the commercial
product, where is used his music, you do not pay any royalty fees for downloading and it is not a piracy.

1:28 So let’s open Royalty
Free Music and choose a type that mares our

mood and we like, let's say we
need electronic music in an action style.

01: We open the electronics, and we can listen to any track, which we like.

2:26 We have spent some time for looking, and we found a great track something like "What do you
want", if

you want to find that one you need to select the mood of aggression, driving in the rock style.

3:28 After we found it and we want to download it, so we press the blue button download and start
downloading the track.

3:45 Also, we need the track for winni
ng, it should be uplifting one. Here is the uplifting in the rock style.

4:05 Then we click download button.

4:14 We need another track for loss in the Main Menu as well, Oppressive Gloom is a wonderful track
for loss, which casts sadness over the dead pla
yer. Neo Western track was found for the Main Menu.

5:05 You can choose for yourself any track you like that will create the mood for your game and gives it
a share of uniqueness. While the tracks are downloading we move over to an audio search. We need
wo sounds when the player will be picking up a bonus and losing life during an explosion. To search for
the sounds we go to website, this is one of the many websites that provides the possibility to
download Royalty
Free sounds.

6:02 Next, we pla
ce the downloaded files into folders, so we do not need to look for them throughout
the computer. They are New western, Soft hop, What do you want and Pencil boom.

6:19 New western goes for the Main Menu.

6:32 Soft hop is joyful sound that goes for winning

6:45 The main track for the game we call the game track, and another track goes for loss.

17:13 After we are done with the music, we can move on to the sounds.

7:29 We can download the wonderful sounds from this website, there is a search option. Let’s s
we want sound to pick something up.

7:42 Picking up the handset.

7:53 There is sound to pick coin up, something like item pickup. It is stated in the description that here is
an item pickup for the video game, so a noise will be played when it will
be picked up. Perhaps, that is
what we need.

8:12 So we take it. In order to download the sound, an authorization is required here. But there is a little
trick. When the website developers were doing this site, they did not remove the testing data, so when

we type the username and the password, the authorization is not required. We can easily download the
sound we want to.

8:38 Also, we need a sound for loss. You may spend some time going through the different sounds. We
already found a wonderful sound that

sounds like this. Yep, it is stated in console that it is recorded from
the old chip.

9:25 Now we have the sound for loss and the sound for coin pickup, but we still have to create images or
state font. The main font should not be simple like Arial, Time
s New Roman or your favorite one it must
be a different style of font.

9:51 Then we go to Google, there are a lot of good fonts, for example, we may go to website
and choose the style.

10:17 This font is good. Let’s download it and see how it work

10:26 We have sounds, Let’s set the fonts. You can download and unpack it.

10:41 So we downloaded our font, unpacked it, and we got the desired file, we can use it in our various
applications, such as Photoshop, we need to connect it to the operating
system, as a rule in Windows
and Mac this is done with one click.

11:13 Now let's move on to create own images. We will need the icon images, such as in
background, bonuses, barriers, the player's spaceship, explosion, when the players will be
colliding with
our barriers, and our buttons.

12:13 Title and background of the Main Menu.

12:28 Let's start with the Main Menu background, title and button. We will have the outer space and a
space station as the background and at the top game title.

49 First, we have to start looking for the resources, so let’s go to Why do we go
to Google? Because most of us cannot draw the great outer space, space stations, ships, and shots. Let’s
admit, you dream to draw something like X
Wing fig
hter from Star Wars or a battle cruiser from around
the Galaxy, but as soon as we take a pencil or pad tablet all our fantasies stay in a head.

13:35 There is a second option that we can use, namely we can always order the resources from artist
websites. I
t costs a lot of money, and we do not have an extra million dollars to create the hit, so there
is always the third option to take the free resources from the Web.

13:56 Let’s look for some cosmic nebula. Let's say it will be deep
space nebula.

14:26 We sh
ould not choose too bright image, because it will draw all the attention, in fact the image
must always remain as the background in this case. Also, we need to try to search for the images with
high resolution that allows us to set the filter. The image ha
s some bright and dark spots; however it
does not have a large size, so we can choose the cloudiness which we will fit the most.

15:41 Let’s save our image and move it to Main Menu background folder.

15:59 Now we get to the space station that will be place
d on the space background.

16:06 Once again we go to and type space station, and we see many space stations,
so we chose the one that fits to our game project.

16:23 Here is this picture. We also save it.

16:46 Now you can begin to create

our game background.

16:50 We are creating a new file in the resolution of our device, namely it is 1280x800, and drag it. It is
slightly reduced and it does not have the original size. That allows us to select the part we are interested
to. Let’s set 100

17:45 Here we have a background. Now we drag the space station here, let’s assume it we will be here.

18:00 Then we erase a title, because it looks better without it. In order to fit our space station into the
background we set a light type. Now we have

the space station that is fit to the background. Our image
is still very light, let’s create a separate layer.

18:30 This is done by the icon below. Let’s suppose we choose hue and center shade.

18:37 This is the color menu, we reduce the color saturation

and brightness, it will not be so bright and
it will not distract a player while one reading the text.

19:00 Now it's time to create the name for our game.

19:09 To do this we use text tool.

19:19 We specify the font on the panel that will be used, which
we already downloaded. Then we set
the desired color, type the title and choose the style.

20:10 Now we add to our style the option of mixing. Let us make it multicolored.

20:21 For example, like this and we add to it some light outlining. Also, we add the

title here and make it
red. In addition, we add a small glow.

21:18 Next, we add some glitter inside. To do this, we select white color and put a screen.

21:40 In order to see the word Intruder, we make it smaller.

20:43 Now let’s take another layer and m
ake a little illumination on the edge. In order to make a frame,
we select all our images and click on transform selection in the menu, reducing its size up to 80%.

22:10 Then we make a soft edges, so we open select, mapdefy, feather and set the radius of
200 pixels.
After that, we press the right button and invert the selected part outside of our circle and fill it with
another color. The color maybe optional now. We can use the color overlay and choose any color.

22:43 We chose this color, but you can cho
ose any color you want to. Then we hold down control + T
keys to enable transformation, and again we hold down shift + T keys for even transformation, and we
are increasing our image.

22:58 So we got even coloring on the edge. Well, in order to diversify t
he background more and to
distract a player from the object that is on the background, we can add small crosses to make the image
truly captivating.

23:24 To do this we will use the white color to create the small crosses. We set the pixel type. Let’s draw
one cross and replicate it, then we transform and turn it, and we get a small cross.

23:57 Again, we transform it then we reduce it to a certain si
ze that we need, and we set the
transparency about 20%. We place a few of them on the screen. Photoshop will help us to place them.

24:42 We select the layer in Photoshop, and we place them.

24:56 You can lift a little bit, because it is convenient. Also,
there is possibility to reduce the
transparency that it will not distract us.

25:05 After we are done with this we can move on to create the buttons that will interact with our
game. Now we can work with what we have, namely we can select all the layers. W
e may place them in
smart object or in a group, and now we create a button.

25:33 To create the buttons we use polygonal lasso tool and hold down a shift key in order to maintain a
degree angle, and we draw a small element. Let’s say like this button, w
e cut out a small stripe to
separate it and then we fill with white color, so it would not look of the same type.

26:27 After we created this button we open the mixing layers and make this rectangle beautiful. First,
we use the filling that we have then we

select blue color, as we do all in blue shades. Let's make it
transparent and add a small edging, also, we try to use the colors that we have to keep the same color.

27:16 Next, we choose thickness size and add some inner glow to single out the edges. Act
ually, our
buttons are ready.

27:38 Our button has two states, a regular state and pressed position. Pressed one is easy to get by
adding a little glow. We choose the color of glow and the size. We try to use colors that we already have
on the image, the f
ewer colors we have, the easier to work, and the better quality of image we get.

28:22 Now we can do different text on these buttons. Let’s say a star game. Also, we need to specify we
want to; in this case it is white. Now we can use the same button for
as long as we need it.

28:50 To do that we need to save it as a separate image. Also, we need to finish the other one, as we
have two button states. We have a title and a background image. In order to use all that in the game, we
need to save them as indiv
idual elements. To do this, we convert that in the smart object so it will be as
an individual object and a separate layer. Title will be added manually, using a special program.

29:34 Then we choose the button is not illuminated and convert it into the sm
art object. Our task is to
make it all look like a single file. To do this, we open the smart object main menu and do the right
on the layer, and then we click on duplicate layer and indicate that we are going to copy to a new
document. Next we open
our group and we get from the smart object our name. Then we save it and
hold control + S keys. Next, we close the window and duplicate the name in a separate file. Then we
click on trim to cut the white pixel, so it does not take up too much memory. Next,

we hold shift +
control keys to save our resources.

31:01 Then we open the image and save it. We chose png format and not jpeg one to keep the
transparency of our layer. Jpeg format does not support what we need.

31:27 After that we close the document. Th
en we remove the title image from the background and hold
shift + control keys to save the background of our Main Menu.

31:37 Now we have 2 separate things, such as the background image and the title image. Next we have
to save the button states. It is nec
essary to clarify, as our button is used for multipurpose functions like
for different menu and so on, therefore, we will later discuss how to use this image in order to stretch
the width by height. Our button should have an equal ratio of the sides. We ne
ed slightly to decrease
the size of our button that it was not so stretched

32:24 To do that we open smart object. Then we choose the central part to delete it. As we work with
styles, it was divided into two different pieces. There is no need to conn
ect the edges. We pull it, and
during overlapping they will disappear.

32:54 We click on trim and remove the empty space. It should be noted that we keep activated the auto
effect and save it with this effect in a button folder.

33:19 Then we turn off this

effect without changing its size and save it one more time without any
changes with addition off. Also, we need to remember to indicate png format. We do not save the
changes, but we save only the current document. Now we are done with our image for the M
ain Menu
of the game.

34:04 Now let's move on to create an image for the inside of the gameplay. Let’s assume that the
spaceship is flying on a background of some space station like the Stars of Death. We will have metal
surfaces, grills, and different lig
hts on the background. All that is done from steel.

34:32 So we go to and look for various metal textures. We try to choose some even
metal texture, and we do not forget about the size, we need the bigger one. We set the large size and
lect the image we like the most.

35:23 Let's take this one. We see that the size is not big enough, but it will fit for us. We need a few
thousands at least. We can set the size that would be more than 2 mega pixels.

35:57 We take this image, because it is

illuminated well and there are no other lights and images, so we
can use it and add any other glow. Then we placed it in a game folder.

36:31 Also, we find a couple of grilles at once. We try to look for a grille that would look right on the
player, and t
hat we would not able to place on the background. We need to find seamless grille that we
can replicate later. It will be seamless metal.

37:36 The problem is that we set a large size. We will look for any size.

37:59 This great grille will do that and it
has a large size, so we save it.

38:27 Then we create a new document where we drag our image. Let’s keep in mind to save the grille
together with our resources. Photoshop trimmed our image to the right size, namely it is 34%. We can
increase it to a large

39:09 It will be our background. This will be our grille, which sometimes will fly in the background. It
should not be too large. Next, we will do some title to make it seems that this is the space station. Let's
write a word danger slightly then we
a little bit reduce it, and we will try to add here some lighting. To
do this, we create another layer and fill it with gray color.

40:19 This is the gray color. We add here the light filter. Let's say our base will be covered by the
spotlights from the to
p. We choose the color. You can set your own parameters. In order to see our old
layer, we can use a right function that makes the illumination better. If we copy it several times, then we
can replicate it as much as we need.

42:03 We add another layer in
order that our background layer would not seem too dark and would not
distract the player. This layer is added below our spotlight layers. We also add here small lights. To do
this we choose a round brush and set stiffness and a small size.

43:05 To create

specks of light, we open the blending options and set ingredients for the overlay. We
choose a radial ingredient. Let’s place it so that the light will seem like it is coming a little bit from the
side. We also can change the scale, transparency, and we g
et a ball like this one.

43:34 To create the light we use the same method as with the illumination. We create a new layer and
fill it with gray color.

43:49 Also, we move on to the creation of rendering, lighten mix. We selected intensity parameters to
e it bright and shiny, and you can select your own parameters.

44:21 We use our settings and set the type of linear
beam. When we move our light, we can notice that
area gets brighter; in order to do this we use a control key to cancel it, namely Alt + Z k
eys, then open
new history, and in the history menu we change paint bucket and set ambience to keep this black color.
To have speck of light brighter we set intensity. Also, we can select the transformation by using Control
+ T keys and compress the image

so that the speck of light will be narrow, then we replicate the layer
and do transformation by using Control + T to reflect it vertically, and these two layers will place under
the light. We can add to the light a bit of the outer glow of the red. It wou
ld seem like a cap covers our
light. We select all three layers and mix them into one group, and we will make another option. Also,
they can be slightly reduced if they seem too big.

46:43 We still have available a lower part. In order to fill the space wi
th something, we will find some
metal fence or structure with the edging to it.

47:05 Let’s go again to to find some fence. You can choose whatever you want to;
we can also recommend you another great website where you may
find different
textures. For example, let’s choose metal one.

47:59 You can register on the site to download or just drag them using your browser. In this case, we
just did it.

48:17 We can place them on the right layer. In order to fit it, we duplicate it

several times due to the
fact that we downloaded this texture from the foreign website, it will be seamless and we can replicate
it many times.

48:47 As we placed it under shading layer, we see that it is slightly darker than it is necessary. To do this,
we will do a separate layer, using the blending effects. That's it. We take the color out of our
background image, so it would not look differently.

49:33 We slightly reduce the transparency. Maybe, we find some interesting elements for placement. In
al, all designs are made on the same principle in the world. There are all sorts of locks, latches, and
you can combine it all at your convenience.

50:16 What we downloaded now is a container door, but we can make it smaller, and it may look like
some kind

of door.

50:36 Perhaps, grille looks kind of large, but you can reduce it. Here everything depends on your taste,
and you can do what you want to.

51:01 We can stop here and save it. So we save the image in a folder Main Menu.

51:28 Now it is time to do t
he barriers, bonuses, and the player's ship. We open up Google and type a
spaceship icon.

51:50 W see a lot of icons, but we have to choose what we like to. We liked the spaceship in the center
and its color fits to our game.

52:52 So we drag it, but this
image needs some additional work. To do this, we select a brush and
contour the spaceship. Then we select the white color. We see the remaining white pixels at the edges
that we don’t need, so we remove them using the menu options.

54:14 Here we see that
we got a wonderful spaceship. Now, we turn it as we need to. We can also
compress it. Then we attach a rear engine. We choose the one that is close to the orange color, using a
big soft brush and then we slightly stretch it. As a result, we have a great sp
aceship. Then we combine
the ship with flash in a separate group and name it as spaceship.

55:29 Now we move on to create a bonus icon. Let’s suppose that we have a coin as the bonus. We type
coin icon, and we see a large number of coins. You can select a
ny coin you like to, we choose this one.
Now we drag it in Photoshop, and we do the same as we did with the ship. In addition, you can make an
elliptical selection and try to do the selection for the coin. You need to choose text menu and click on
m selection and adjust it as you need to.

56:52 Then we make one more selection for this part remove white color, using the menu options. All
right! The white parts are selected, but we do not need that, so we click on Alt key and remove the
selection of t
hese parts. Next we convert our coin in the smart object and reduce it to the size we want
to. Then we set glow for all mixing and add the orange glow around that the player knew it may be
important and might help the payer.

57:56 We add a bit of color, yo
u can choose at your discretion to make it a bit like the style of the game.
Let’s suppose like this.

58:56 All we have left is to do the barriers that the player will encounter. Now we form a corridor. We
create a rectangular selection and fill it with th
e color, which we like to. In order that the player could
see better we put small bright outlining, using the blending options. Namely our task is to make it clear
to the player that it is dangerous to collide with them.

59:43 Now everything is ready and w
e have to save all that as separate files. In order to use some parts
separately during the game. So we use the button to click on the right layer. Then we duplicate them in
the new files. Next we choose image tree in order to remove voids and we save in a
rground game.

1:00:25 Well, we are done with that and we don’t need this file anymore, we just close it. The same
operation we do with the coin. We choose the coin and replicate it on a new layer. Then we save in a
bonus folder. There bonuses will be colle
cted by the players.

1:01:05 The spaceship is replicated in the group. We save it in the image tree document. Also, we
choose png, because we have a transparency file.

1:01:32 Now we can unmark all our items, titles and save the rest of the background in t
he ground

1:01:58 Now we have left of all the resources to prepare the effect of the explosion when the spaceship
will be crashing into the barriers. When it crashed or fell down at this point should be a blast.

1:02:10 We go to and

type explosion sprite sheet. Everything is done in a sequence
of frames. These frames are called sprite sheets. The game has a lot of explosions, and you can choose
any you like.

1:02:38 We chose this one. Let’s drag in Photoshop. We see a white
background, but we do not need it.
It has a lock, so we cannot remove it, we will do it manually. Let’s click twice using the mouse and the
lock is gone, now we cover with another layer. We select the color and choose the needed color, and
now we have the

image explosion without the background.

1:04:00 We will place it on the game background. In order to use them in the game, we need to use the
explosions in a sequence of frames. First, let's look at the size of the image that has 310 pixels, it makes
t 75 pixels per one explosion.

1:04:39 We create our slice and set the layout 79x75 pixels, and 75 is not enough, so we take 77. Then
we set the same slices with width 77x79. It is important that each frame of our explosion should be in
the same place.

5:20 Now we can select each piece. We may lose the ratio of angles when copying it, as Photoshop
grabs the empty space, so we use overlaying brush and set 1% transparency, and there are added small
spots. We cannot see them, but they are there and they wil
l not allow Photoshop to remove empty

1:05:59 Let’s copy it, and then we create a new document and paste it. We remove our ground in the
trash and save it to explosion folder.

1:06:43 Let’s do the same with other two frames.

We created the explos
ion in individual frames, so we can use it in further development.

1:07:37 Also, we still have left to create the icon for the application in the size of 512x512 pixels. To do
this, we take the ship and cut a blank space, and then we rotate it, so it will
look up. The icon will have
rectangle form that the width will be equal to the height. We lower it a little bit.

1:08:26 Next, we place it on the background of the outer space from the Main Menu. It is done, and we
see how our spaceship tends to the stars.

All we have left is to set the size of 512x512 pixels. We can see
that our ship a little blurry, so we use the filter, namely sharpen edges to fix it. We hold Control + F keys
and the edge of the ship become sharper. Then we need to save it, we choose ima
ges, icons and save as
512x512. As to the application, we need an icon in the size of 128x128 pixels. Next, we lick on image size
and save it.

1:09:42 That is it, this creation is complete.



This tutorial


will show you how to place all application resources into the project and create main
menu and the whole project in the development environment. You will get to know the general
structure of the project hierarchy in the environment, learn to use the 9path

resource tools and gain
practical skills on placing a variety of resources.

00.09 In the fourth lesson, we will allocate the resources and create our project.

00:10 In order to do that we open the development environment and create a new project.

Let’s set a name and call it our game.

00:31 Then we choose the version of our android, let’s set 4.03.

00:42 Next the application requires to enter a package name.

00:54 Then we enter the name of our activity, let’s call it Main Menu.

1:12 Also we choose
Min SDK Version 8 in Android 2.2.

1:20 Then we click finish and our project is being created.

1:30 Our project is created, let’s open it.

1:37 Now, it is briefly about the project creation.

1:42 The project consists of the following folders: SRC folder
contains the packages with our java files,
and the folders Gen and Din are utility folders used by the development environment to store its
generated files.

2:15 Android 2.2 and Android dependencies are branches that contain the libraries selected by OS.

:30 Assets folder stores the resources that will be presented in its original form and will not be changed
during compilation.

2:44 Then RES folder that is used to store the resources. These resources will be compiled and
converted to a byte code, which wi
ll be assigned its own unique identifier to which our application will
be referred.

3:15 Also, each project must contain a manifest.

3:22 The file from which the system receives the application configuration settings.

3:30 Now we move to the allocation of
resources in our project, and we will put images in RES folder,
the environment provides usage of image resources for the various devices with different dpi by default,
it also divided into the folders, namely drawable folder has the identifier of its dpi.

4:10 But we will do a little differently.

4:16 We will create drawable folder and use nodpi identifier, which means that all resources that we will
be using from this folder will ignore dpi level on the device.

4:43 Then we move to the folder with our res
ources and select all images.

5:00 After we are done with that, we simply transfer them using a mouse, and the environment offers
us to copy the file or put a tag on it.

5:12 We choose to copy the file.

5:17 It should be noted that the development environm
ent is telling us that our file has invalid name
and is describing what it should contain.

5:32 Now we move over and rename the file to (phone game, bonus).

5:59 So we renamed it and the development environment accepts our names.

6:08 Then we put the music

in RES folder, but the music should be in RAF folder, and this folder is not
created by default, however we can create it yourself.

6:28 So we created RAF folder.

6:32 Next we open our folder with our resources, select all music resources and copy them to


6:47 Now we have left only font.

6:52 Here is our font, and we copy it in Assets folder.

7:10 As we can see, we copied all our resources.

7:20 Now I will draw your attention to this file, we will use it for our buttons and panel. The file
the image is very small.

7:45 When we will be stretching and deforming this image, it will lose its shape, and it will look ugly.

7:50 So what we can do at this point. Standard utilities of the development environment have nine
patch utility.

It can be used easily, we go to the directory where our development environment is setup.

8:18 Then we go to Android SDK and get in the Tools folder, and we run the nine
patch utility.

8:30 Here it is running and ready for use.

8:35 Now we move over to our

resource directory and select our file.

8:43 The file is selected.

8:48 Here is our working area of the window on the left, which we will draw.

8:55 The stretched image will be shown on the right, namely it looks awful now.

9:07 So at the top, the image i
s blocked for us, we can only draw the top, left side, bottom, and right

9:29 We highlight the area from above and the left side that will be drawn during stretching.

9:41 For example, here we put a dot.

9:44 The image is changed from the left, we c
hoose show patch, it will show us the pink area that will be

10:05 Then we put another dot from the other side, this is on the left side it points to stretching up and

10:18 Finally, we got a cross, so here this line will be displayed and

stretched to the right and to the left.

10:38 The other one will move up and down.

10:40 Now our image looks pretty decent, and it's stretched nicely, so we need to define an area for

10:55 Using a checkmark we select show content.

11:00 Now ent
ire area of our image is highlighted for the content by default.

11:18 We don’t want that our content would come out of our button, we limit the area itself.

11:25 We do it this way. We draw a line down and highlight the entire area that will be used for t

11:43 In order to draw, we just that point and click on the left mouse button.

12:00 Then we draw another line at the bottom, selecting border.

12:05 You can see how the size of the blue area is changing on the left that is showing the size of
future content, which will be placed on our element.

12:25 Here we did it, let’s look at the content, it will be placed slightly lower.

12:37 When this is done we just save the file.

12:46 Next we choose a folder and name it as Button and save it.

00 Now we move over to our folder with the resources.

13:04 It should be noted that the file name was changed to BTN.9.png.

13:13 Please note that the name must not be changed.

13:18 If you change this name and remove .9, then the image will be used as reg
ular without nine


13:27 Actually, we will do the same thing with our image in the pressed position.

13:38 Then again the same thing we select show patches.

13:44 Now the whole image is stretching.

13:48 We select the shades at the top and the left
side, and we switch to the content.

14:03 Then we highlight the needed content area. We do exactly the same thing as we did with the first

14:51 So, we're done and we save our image.

15:15 Now we do not need the patch utility anymore, so we can clo
se it.

15:22 If we will need it we always know where to find it.

15:29 Now we move our resources to the project.

15:36 Namely, they are being moved in the drawable with nodpi folder by copying.

15:44 You should notice that the development environment reads

BTN.png and BTN.9.png as the same

16:00 Therefore, we need to rename our original images.

16:10 We just copy this pressed position and rename the file in the same way as we did before.

16:29 Now, we will look at the example that shows the
difference between a regular resource without
using nine
patch and the resource that uses nine

16:39 For this we go to our layouts.

16:42 Then we open Mainexcel folder and place a regular image.

16:50 We choose our regular image without nine


and as example 7

inch screen.

17:02 We stretch it throughout the screen.

17:05 We set properties to stretch this image.

17:15 As you can see, the image looks awful.

17:19 if you enlarge this image, it is stretched terribly, and it looks not good.

Now we choose our resource using nine


17:35 you can see that the image is stretched nicely, it is well proportioned and it looks great.

17:45 Even if we set 10.1

inch screen, it will still remain beautiful.

17:58 Also, if we stretch it throughout

the screen, the image keeps its quality, and we can use it as we

18:12 So all our resources are already allocated in the project.

18:17 In the next lesson, we will create the Main Menu and explain how to handle the events in it.

Lesson 5

The fifth

tutorial will help you understand how to create a game class and game activity as well as how
to form user interface. You will learn how to bind elements of the interface with activities. This
knowledge will help you create different user interfaces, swit
ch from one activity to another and learn
to handle events.

00:03 Now we move on to create the Main Menu. When we create a project, we had already created
one activity, which was set initially, and one description of our layout that is XML, where is stor
ed our all
interface. What does activity do? It's just a window that interacts with the user through the interface
that is created in XML.

00:55 In order to create the interface in XML, there are two ways. It is a graphical one, which is open
now and text
interface. We are going to use a graphical one.

1:11 As our game will work in a landscape mode, we choose the landscaped layout. Here it is.

1:24 Here is the layout content that is set as light type by default. The development environment has
many types of

layout. Main difference between them is in the placement of elements on the layouts. In
our case we will need the relative and linear layouts.

At 1:57 In linear layout all things will be placed in a line, either vertically or horizontally. Relative layou
places the elements on itself in relation to each other, or depending on the edges and the center of
layout. Let's try to add our background.

2:20 To do this we choose the relative layout, select properties and the background, and a dialog box is
being o
pened. We select drawable and

2:40 Here came up our background. You need to take a look at our stripe at the top there is a status bar
and the title. Later we will show you how to remove it during the game, but it will always be displayed in

3:05 Let’s place the image with the title. The element is being placed from the edges, but we'll place it
from the top edge and choose the main title.

3:43 Our image is placed perfectly. Next, let's place our button. The button will consist of the image an
the text. Let's place for this button the separate relative layout in the center.

4:15 Now we're going to add everything to our relative layout. Let’s add the image. Then we choose
BTN, using nine
patch. We do not need any resources without using
patch, we can remove them,
and they will not be needed anymore. There are only two resources left that will be used with nine

4:47 Now we add the medium size test to the relative layout and place it in the center. Next, we set the
relative layo
ut size, 350x150 pixels.

5:24 Also, we add other elements to our parent relative layout, and we simply stretch our text across
the line and set gravity properties for it. This will indicate where the text will be placed, namely below,
left, right or at the

top. We select center horizontal and the text is line up at the center. Then we stretch
the image, and we got it. Now let's edit the text.

6:30 Let's do it this way. You can type the text here yourself, and it will be changed. But we advise you
to use in
your values folder, xml string function. It may also be edited by the environment in graphical
and textual types. But we use the graphical type. We add value and select the value string type, and
then we type in the name line start_game and in the value li
ne start_game as well. Next we save it, and
now it is changed. Then when we select text, we click on the start_game, and here it is from our
resources. Here it works.

7:50 Thy is this approach easier? For example, when you want to change the text or the re
source, you
do not need to look for the text view or some text elements throughout the entire XML files, you just
edit it in one file. Also, if you are using the same text, you don’t need to go to every layout to change it;
you can set a value and change i
t here. It will be changed automatically throughout your project. It is
convenient and good. Use it.

08:36 So our XML is ready, but we still need to add one small thing. In order to use our elements in
activity in the future, we should change the identifie

9:02 What is the identifier? It helps to find our element. Let’s call our relative layout, button_start and
hit ok. We see that our name has been changed to ID, and for the image, we change to image_button.
Now our XML is completely ready.

9:50 Now we
move on to create the activity. We open SRC folder, then we open our package and main
menu java.

10:08 So what do we see? We see that our Maine Menu class is being described that inherits from the
activity. In onCreate function we see that we assign and li
nk our activity to main.xml.main. The solution
is not written here.

10:44 Now we look at the things that that we will use in the future. This is the relative layout that we call
it button, and also we use image view. Let's call it image button. Now we need

to link our variable
activity to the elements.

11:40 How do we do this? We assign the button and specify that is going to be the relative layout and
we call a function “find view by id”, and here we choose the identifier that we have given to our relativ
layout. Here it is a start button. We tied our variable to an element in XML.

12:25 We do the same with the image button. In addition, we will use our text, but initially we did not
assigned the Id to it, so we go back to XML and assign text_start

id, and we save it.

13:15 Then we go back, and here we also add text view and link to it.

13:54 Next, we notice that our font is not used in the text. If we go to the folder with the resources and
open our font we will see that.

14:18 How do we use the f
ont? We move to our activity, and also we need to remind you that the font
should be downloaded from assets folder, but we download it in the different way from the RES folder,
not like regular resources. So we choose typeface, custom, = and create it. So
we have a method to
create with assets.

15:20 Then we choose assets that allows us to access assets folder, and as a path we specify our file
name. If we have inside of the assets folder other folders, we specify the path to the font. In our case,
this is

the font. So we downloaded our font, and we applied it to our text view. Now, this font will be
used in text view.

16:20 Now we move on to handle the events. In order to handle the events, we use listeners in the
development environment. Listener is the d
eveloper of a specific event, in which we describe what a
program should do at the specific event. In our case, our relative layout will handle two events, such as
onTouch and onClick.

17:13 Now we set the Listeners on the relative layout “set on tough lis
tener new”, and the methods are
added automatically. Now the program is highlighting the new element in red, and it is okay, we have to
import on tough listener from the Android library.

17:53 This is done very simply, we can use control +lock+ shift +o ke
ys, or by selecting it from the
context menu. Also, after this we will add to it onClick developer. OnClick listener is taken from Android
library as well.

18:36 Now we have left to describe what it should do with on touch and onClick. It should change the

image on touch and make it illuminated, and at a time when we remove a finger from the button, it
should return it to its original state. Next, when we click on the relative layout, it must move to a new

19:16 Now, let's create it. In order to c
reate activity, we move to our package explorer and choose new
class. Let’s call it game, and in the future it will be our game class and we will inherit it from activity.
Now we click on finish. As we can see the class is created, but it went into another

package, because we
did not specify it. We can move it to another package, this is no problem.

20:20 The activity does not have on create method, let's create it. We must specify what XML will be
used for it. In the same way, let’s create XML. To create X
ML in the package explorer, we do the right
click and select new XML Android file.

20:57 Next, we specify the type of layout resources, and then we indicate the project that is our game,
and the XML name that is game. Also, we can select the root element t
hat is relative layout. We choose
next or finish. We click on finish.

20:39 Here XML is created, as we see here is our root relative layout. Then we do XML landscape. Now
we link our second activity to XML, and when we move to the game activity we place a
pause button in
there, so that it would not look empty. But we will place it dynamically.

22:34 Let’s link the relative layout to XML game and assign to it the identifier and add to our activity. So
we link a layer in XML to variable in activity. We are do
ne with it, so we move on.

23:31 Features of dynamic element creation are not written in XML. We add them in the creation
process of activity.

23:53 Now we create XML for the pause button. This XML will be used only as a pause button, not as a
layer. You k
now already how to create XML, so we just do it.

24:36 XML is done, and the only new thing that we used is margin. It is indention from the side of the
left, right, top and them bottom.

25:05 Now the main task is to place XML element as a new button. We us
e LayoutInflater to do this.
LayoutInflater allows us to create and use view in XML.

26:12 So here it is initialized. Then using LayoutInflater we create our view, but first we create the
variable, let's call it the pause button.

26:54 Next, we import it f
rom the Android library. We assign to our pause button = myInflater and
specify the name of XML resource that will be used for view.

27:26 Then we tape null and false.

27:40 Next, we will need our screen size for dynamic placement of our element on the sc
reen. This is
done like this, but we are not going to concentrate too much on that, most importantly that the width
and height of the screen will be stored in these two variables.

28:10 Then we set value for our pause button. Now for the proper operation o
f the LayoutInflater, we
change SDK target of our project, this is done in the project properties. We change project build target
to 4.0.3 then click on apply and ok buttons. We are done here.

28:50 Now here is displayed that we are using the Android 4.0.3

library, and in manifest is written the
min version of SDK, just like in Android 2.2.

29:01 Now we can set X and Y positions for our button.

29:23 The pause button we will be placed at the top along X, the screen width is minus 250 pixels. After
that we

add the pause button to relative layout and set the button settings for the height and width.

30:07 Then we take its layout settings and change the height of 250 pixels, and we do the same thing
with width.

30:33 Now when we described all pause button set
tings, we can move to the game activity. To do this,
we go back to the Main Menu in the handler "OnClick listener", and then we will run our activity
through our intent.

30:00 To do this, we create a new intent and give it a name, and then we assign new
intent value, where
we pass activity by two parameters from which we want to run a new activity and its class. In our case,
this is Maine Menu and the class that we want to run, this is the game class.

31:57 All right, intent is created, we just have to ru
n activity. To do this, we type start activity and select
myIntent settings. Now, the event handler is created, and that our application was aware that it has one
more activity by the name Maine Menu we will have to add it to the manifest. If this is not d
one, there
will be many errors.

32:45 To do this, we open the manifest and go to the application tab. There is application nodes tab at
the bottom. Here we click on add button and choose activity, and attributes appear on the right.

33:08 We select the nam
e and activity and save it. Now we can run our project on the device and see
how it works.

33:31 Here it starts, we click on the start game button and go to the game activity where the pause
button is located.

33:47 You may note that at the top are the sta
tus bar and the title application. To remove it, we again
need to specify it in the manifest and we will do it now. We also set some attribute for our activity like a
screen orientation, as our game is used only in landscape mode, and we set the sensor lan
dscape value.
This is specified in the Main Menu and activity of the game.

34:42 To make our application in full size screen without title bar, we need to go to the last tab of
Android manifest, then select text editing and add Android theme to the applic
ation tag, next we choose
a style without the title bar, full screen, and we save it. Our application runs on full screen.

35:25 Now when we configured both activities in the manifest and we will run our project on the device
and see how its look is change

35:43 Now it is displayed on the full screen without title bar, and it also moves in the game activity.

35:55 Now we'll create the pause in menu in the game activity, and we will implement a return of the
game activity in the pause menu. We'll have to
create XML with description of our layer, pause menu,
and we add it to the game activity.

36:37 We already know how to create XML, so we will do it easily. We created XML pause menu and
added the relative layout with identifier Rel, image view with identif
ier imCont, and image view with
identifier toMain. In this instance, they will be as our buttons.

37:09 We link our XML to the game activity. It is the same as we did with the pause button. Here we
created view using XML, and now as the pause should appear

only when we click on the pause button,
we set visibility for it and tell it to disappear. That is it, now it will be placed in our activity, but it will be

37:59 Then we find image view and link it to our variables, so that we can assign to them

the listeners
later. As you can see, we created image view, but listeners will be created separately from the onCreate

38:48 Next, we create a second onClick listener, that is our toMaine menu.

39:19 Now we created, and we assigned listener to eac
h image. Now let's describe this process.

39:50 When we click on continue, the pause menu should disappear. We set the value for visibility to
disappear and return the pause button, because after clicking the pause disappears. We tell it that it is


40:34 Now we will describe onClick listener and toMaine menu. It's simple. We tell our class that we do
not need it.

41:00 Now let’s create onClick listener for the pause button. We create it separately. So we created it,
now what should happen when
we click on the pause button. We tell button that we do not need it. We
have to hide it and show our pause to the menu.

42:10 It should be noted that now we have to put the game on pause. Then we assign the pause button
to our class, it is onClick listener
. Now we can run our project.

42:56 Let's see how it works. Here is the start screen, and we select start game, pause button, pause
menu, then we click on continue and go back again in the game activity and
then to
the main menu.
Everything works fine. Ou
r lesson is over.

43:26 In the next lesson, we will create a game panel in our class of game activity and discuss it in

Lesson 6

In this


tutorial we’ll get down to actually creating the main game class. You'll find out how to create
the backgr
ound class and do the drawing in the application, practice in creating game classes that will
handle all game events. We will also reveal elements of the user interface that work best for speeding
up the game.

00:05 Today we will create a game class and p
lace it in the game activity. In the last lesson, we created
the Main Menu and the event handler button.

00:18 Also, we did a smooth transition from the game menu to activity and back.

00:30 Now we open the game activity and create the class of our game
panel. Then we create a variable.
This is another way to create a new class. When the development environment underl
ines some
variable with red it

means that it offers options.

00:30 It offers to create a class, interface, num, and type parameter to game.

We choose to create a
new class. Now our game panel will be inherited from surface view and not from activity. The surface
view provides a separate area for drawing, which actions are rendered in a separate thread and that
allows quickly handling the draw

2:27 Next, we click on finish, and here is created our class that suggests to add a
, and we
added it. Also, our class should include and implement the interface, surfaceholder, and callback.
Accordingly, we create additional methods.

We also add to our class onTouchEvent handler, it will help to catch the events by clicking on the
screen on the game panel.

3:50 Next, we create two methods, such as draw and update. Draw method will keep all of our drawing,
and update method will update
the gameplay. We are done for now, and we move on to the game

4:23 Here we have created a variable, and now we need to place it in the game activity. To do this, we
assign to our variable that it will be a new game panel, then we pass the context

and at the same time
we will give the parameters to ourselves.

5:08 Here we change the
. Subsequently, we will need it later. Now we add the game panel
to the relative layout. Next, we go back to the description of our game panel class.

5:47 He
re we say a little bit about the gameplay as it will take place on the game panel. The entire
gameplay will be running in an infinite loop. In order to handle the events, we will use surface view, this
is our game panel.

6:14 Also, the game panel will hold

all classes of game elements. To create an endless loop, we will use
the thread. Now in our

we specify that we get holder and add callbacks this, it will allow
intercepting the surface view events. Then we type thread and put it in the variabl

7:30 Next, we create the class and inherit it from thread. Our class is created. Let’s leave it blank for

7:56 Here we say to our thread that it is a new instance, main thread. We pass two parameters here,
such as holder and this (us) that our thre
ad knew its main parent, and thread could turn to our game

8:43 The

is added and we set the parameters true. After that we could handle the events
from our surface view.

9:04 Now we move on to edit the main thread. We create three variabl
es in it, such as surface holder
variable that will keep our main surface holder, the game panel variable that will keep our game panel
that our thread could easily call to it, and running variable that will show if our thread running or not.
Now we go bac
k to our

and fill in variables, and assign to them values. We are done with it.

10:12 Now let's create a set running method to be a parameter. We use Boolean variable to pass the
game state.

11:13 Then we create main run method where will be im
plemented our infinite loop. We create canvas
in our run method where we will be drawing later. Next, we create the infinite loop and say while
running we start doing our drawing.

11:55 Then we see that the game is not paused, and our game panel does not d
isplay this state, so we
add it now.

12:53 To calculate the position change of various objects on the screen, we need to know the elapsed
time since the game update. This value we can get from main run function of main thread class. This
delta T value, we

will pass to each gameplay object.

13:18 Now we create our variable that will record the time at the start of the drawing. We call it from
the system. Next, we will place the drawing. Then we create a variable in which we place the value after
drawing. U
sing the same method, we will get the value of delta T, it will be equal to value difference end
draw minus the start draw. Since this value in fraction of seconds, we divide it by 1000.

14:47 This is its receiving in a second. We declare a variable to del
ta T. In the

we specify that
initially it is equal to zero.

15:08 Then we will do the drawing inside of run method of our main thread. We have the canvas
variable, we set canvas value to null inside of the loop, and then in try method we try to

set canvas value
with surface holder, lock canvas. It is done in order that we can edit surface holder and its drawing.

16:07 Next, we select a method finally and return to our try. Then we synchronize our canvas with
surface holder, and we call update an
d drawing of our game panel. First, we deal with update and as a
parameter we pass our value to delta T, and then we deal with draw method where we pass our canvas.

17:13 Next, we add this parameter to the draw method and go back. Then if our canvas is not

equal to
null in the method finally, we unlock our canvas.

18:00 At the end of the lesson, we created our game class and prepared everything for drawing of
elements. In the next lesson, we will place the background and make it looped around.

Lesson 7


the seventh tutorial you’ll be taught how to create the scrollable background in the game class, make
infinite background drawing and obtain practical knowledge of Thread use.

00:03 In the last lesson, we created the game class. Now we will create a back
ground class and will add
its drawing to the game panel.

00:16 Let’s open the game panel and create a background variable.

00:57 We create the background class and describe its constructor. In the constructor, we pass to the
parameters our bitmap and the
width of our screen. Also we add the variables that will keep the class.

2:17 They are bitmap, X and Y positions, the width of the game screen, and the value of how many
backgrounds can be placed on the screen.

3:08 Now our constructor is filled.

3:26 When

we create background the starting positions of X and Y is equal to zero.

3:48 Also, we set the width of the screen and calculate the number of screen images that can be placed
on our background. To get this number, we divide the width of the screen by the

width of the bitmap.
We add 1 to this value we well.

4:46 Then we create another parameter in the constructor that will be passed. We will pass our game
panel, in order that our class could always refer to it.

5:31 Next, we set the variable.

5:40 Our cons
tructor is ready, and now we create draw and update methods. In the draw method, we
indicate canvas, as here will be done the drawing, and in the update method will be calculated the
object changes.

6:31 As a parameter we pass delta T.

6:45 Now we describ
e our draw method of the background class. To do this, we create a counter that
runs from zero to the number of background images, which are placed on the screen. In this counter will
be done the drawing. Besides, we add conditions if the canvas is not equ
al to null.

7:52 Then we start drawing. Next, we indicate bitmap and left point according to X, and then we take
the width of bitmap and multiply by counter value "i" and add X value.

8:16 The third parameter is equal to Y and the fourth is equal to zero.
Then after the counter, we check
if the absolute value of our X is greater than the width of our image (our bitmap). Then we assign to X
value X plus the width of our bitmap.

9:02 In this way we creates the illusion that the background is endless. Next, we

describe the update
method. Here will be changed the value according to X and it will be X value that is equal to X value
minus the speed value of the ship and is multiplied by dt.

9:45 What is the speed of the ship? This is value that will be kept in the

game panel, and we'll take it
from there. Now let us open the game panel and create a variable.

10:06 We add and we set our variable in the constructor game panel. It will be equal to the screen width
and is divided by 2. We will take a width of the scree
n from the game activity and pass as additional
parameter to the constructor game panel.

11:11 New we went to game activity where the game panel is created, and now we write in there the
parameter of screen width. We are done with that, and we have the bac
kground class. Now we add
everything to the game panel and see how it works.

11:58 To do this, in the constructor game panel we initialize our background variable, and it is equal to
new background, then we choose our constructor and bitmap we get from bit
map factory and decode
the resource. The first parameter we get the resource, and the second one is our id, drawable, and
game background.

13:05 We set the width of the screen and pass the game panel, which is "this". We just created the
background instan
ce and initialized it, and now we add background draw to the methods of draw and
update. Then we pass to the parameters canvas.

13:48 Also, we create background update in the update method and pass to the parameters out delta T.
In addition, in the drawing

we add that if the game is not paused and our canvas is not equal to null,
then in this case, we will be drawing our game.

14:23 Next, in surface created method we pass to our thread value set running, true, and we start our
thread. When surface is delete
d, we have to stop our thread.

15:08 For this we create Boolean variable retry, assign true value and create the infinite loop. We try to
stop our thread, if we stopped it we assign to retry false value.

16:09 Then we'll catch interruption errors if we
will encounter them that we try to stop the thread. Now
everything is ready to run the application on the device and see how the background class works.

16:48 Let’s start the application. We click on start game and here is background motion.

17:05 Then we

click on the pause and see that the background is not stopping. Now when we click on
the pause button, we will add the status to the game that it is on the pause. To do this, we go to the
game activity “onCick listener pause click” and here is our comment

that we left.

17:49 It says that our game should be paused, and in order to do that in our game panel we put pause
menu, and then pause game, and we assign true value. Now when we click on the continue button, we
put the game panel, pause game variable is

equal to false.

18:27 Now we again start the application, next we click on start game and click on menu and we see the
background stopped. So we are done with the creation of the background class of the game. Next we
move on to the spaceship.


The eighth tutorial will give you an idea of how to create a player class and describe all its methods.
You’ll learn to work with touches on the screen, as well as create a method for defining collisions with
other objects that will allow you to create
a barrier manager and a whole new barrier class. In this
tutorial we will also learn how to draw animation correctly.

Remember this video part of the android
Empire video course, the property of

You can find more important articles o
android marketing and sales of your future game or app inside the members area!

00:03 In the last lesson, we created the game background. Today we are going to create a spaceship

00:13 The game panel class is already opened, and now we add
spaceship variable and call it the
spaceship. Then we create the spaceship class, go back to the game panel and initialize the variable.

1:03 Next, we will pass the following parameters into the spaceship class. We pass to the first
parameters the bitmap,
and it is downloaded from the resource folder. Then we set X coordinate for the
following parameters and the width of the screen for the last parameters. 2:03 Now we add the
constructor and start creating the spaceship class. Here we created the needed var
iables, such as the
bitmap, X and Y coordinates, speed, increment, and the width of the screen. Also, a bitmap array is
created that will be used for the spaceship explosion, when it will be colliding with the barriers, and
Boolean variable death.

2:55 Nex
t, in the constructor we initialized all our variables, except the array. We will create a separate
method for the array and call it “set boom animation” where we pass to the parameters the bitmap

3:53 Next, we initialize the array, which is in the
class, and we choose to create a new array from the
existing animation array. Then we add secondary variables that will be used during the drawing of
explosion animation.

4:33 Anim time variable is responsible for the playing time of the animation, and tot
al animation time is
all playing time of the animation. Num frames

is the number of frames in the animation. It will also be
set in “set boom animation”, and it will be equal to the size of our array.

5:12 Next, we'll create the draw method. This is the d
rawing method where the canvas is used by the
parameter. Now, if our spaceship is not crashed yet, we will draw our spaceship on the center and not
with the top, left and top coordinates.

6:22 For this we deduct the width from X that is divided by 2, and w
e do the same thing with Y
coordinate. As a result, our spaceship will be drawn from the center.

7:13 But if our spaceship is hit, then we calculate the index of the animation frame that we will be
showed by us. Current animation time is divided by the tot
al time, and is multiplied by the number of

7:53 If our index is less than the number of frames value, then we draw the animation frame under the
index as index. Then we choose canvas, draw bitmap, and now we our drawable download from the
array, a
nd the coordinates are calculated in the same way, and the other parameters remain the same.

8:48 We are done the draw method, and now we move on to the update method. Here will be updated
our coordinates and anim time values.

9:17 if our spaceship crashed, then we add anim time variable to dt variable.

9:46 Here we describe our spaceship motion and spaceship update in its regular state. To do this, we
need to add a vertical speed variable and height of the screen. We initialize

it in the constructor, and
also we will need the screen height variable. We add it to the constructor, and then we add new
parameter to the game panel.

11:49 We are done with that, so now we move on to the spaceship class and write updated coordinates.
en we add the screen height that is divided by 2 and is multiplied by dt to the vertical speed. Namely
the gravity force has a constant effect on the spaceship and moves it to a distance. But if the engine of
the spaceship is running and it is moving up, t
hen retroactive force has an effect on it.

13:28 Now we add our speed to Y that is multiplied by delta T. In order that our spaceship could not fly
endlessly down, we add a conditional test. If it flew away down at the height of bitmap, then it again
rs at the top.

14:20 Now there are written update and drawing, and in the game panel we can place it in draw and
update methods, so the spaceship will be drawn and updated.

14:50 Next, we add conditions to onTouchEvent method. If our event gets action down
, then it means
that our spaceship should engage its engine. Up variable is equal to true. But if we lifted a finger, then it
means that it may fall down.

16:15 Next, we need to make some changes to onTouchEvent method. We must always return true
value tha
t touching already happened. Then, when we change the vertical speed value in the spaceship
class, we only multiply by 2, but we do not divide it like we did before.

16:51 Let’s do testing for the spaceship motion on the device.

17:30 Now we click on start

game, and we see that the spaceship is moving. Then we click on menu,
pause, and Main Menu.

17:58 Then we try again to play, but the game does not work. Now we open the game activity to find
out what is the problem. Well, it happens because we do not stop

our thread. Now, after returning from
the game to the main menu, the game will start again. You can start the game again.

18:58 Next, we again return to the spaceship class to describe a couple of methods. This is a collision
finding method. This method i
s taken from the geometry, it is quite simple, and we look if a point lies at
the rectangle area. If it does, then we collided with something, and if does not, we did not collide.

19:22 Then we create a method that returns Boolean type variable, and in the

parameters we pass to it
4 points. These 4 points are corners of the rectangle. We count counterclockwise, and they are the
upper left point, upper right, lower right and lower left.

21:08 Now we create variables and locate them in exact same points of ou
r rectangle that are upper
left, upper right, bottom left, and bottom right. In order to get them, we describe a separate method.

21:40 It will be called get point. We will get them in this way; we have our center coordinates, width and
height of our bitma
p. It is not difficult to get these points, for example, in order to get the upper left
point, we find X coordinate minus width of bitmap, then Y coordinate minus the height of our bitmap.
The other points could be gotten analogically.

22:59 For convenienc
e we place the points with estimated object in the array to process them later in a

23:17 Here we added the points to the array, and now let's find the interception. We create a loop that
goes through the entire array.

25:19 Then we cleared the array

and added the points. Next, we check again for the collision. So we
described all the class methods and wrote our own spaceship class.

25:43 In the next lesson, we will create a manager that will create barriers and a barrier class.

Lesson 9

In the nint
h tutorial you’ll be taught about writing a barrier class and creating a class manager that will
deal with placement, creation and management of all game barriers.

00:02 In the last lesson, we created the spaceship class, made it to move and to respond
to a user
command. In this lesson, we will create a barrier manager and a separate barrier class.

00:26 Now we are in the game panel, and we create the barrier manager.

1:02 We create a class and add it to the game panel in the constructor. Then we will se
t the bitmap as
the parameters.

1:45 Next, we create the constructor in the class.

1:54 Now let's do the barrier manager class. Here we created all necessary variables, and we initialize
our bitmap in the class. Here is briefly about the variables, ship he
ight is the height of spaceship, and
other variables will be used at a time when we will generate our barriers and the corridor walls.

2:37 Top walls and bottom walls arrays are upper and lower walls.

2:47 Then we create set ship height method where we wil
l indicate the height of spaceship.

3:01 Next, we create set screens method, which will determine how many barriers to draw on the
screen and will allocate them.

3:21 let's create an empty barrier class and set screen method. So we wrote set screen, where
we set
the screen height variable, number of barriers that we can place on the screen, let’s to take +4 just in
case, so we will not have any problems during drawing, and we initialize the arrays.

4:13 Next, we fill the arrays from zero to the number of ba
rriers in the loop. The first parameters are set
the bitmap and the second parameters are set X and Y and width plus 200 pixels.

4:59 Then we take from bitmap width that is multiplied by "I". Why do we do this? We initialize the
barriers especially behind
the screen area, so they could appear later in front of the player. In addition
that would create the illusion that we are moving down the corridor.

5:24 Next, we will create set manager for our barrier and tell it that it is the main barrier manager, so
ur barrier could refer to its barrier manager.

5:54 Then we create all of these methods within X and Y class and create set manager method. At the
end of set screen method we have to generate random location barriers.

6:34 Let’s create a separate method f
or this. We created generate method. Now we start filling it. Here
we filled this method. Where do we get H variable? We take the half of bitmap height.

7:08 Then dl is a variable of the width of the corridor. Dpos is a variable of middle of the corridor.
New_dl is the width of the corridor that will be the end. The width of the corridor is three fifths of the

7:38 A variable inc is how much we will deduct delta L, and this is the height of the screen. In order to
get at the end a new dl value of th
e corridor that is three fifths of the screen height.

7:08 Next, we take the bitmap height and set Y value for each barrier of the top row and the bottom of
the barrier. Accordingly, we create proper methods, such as bitmap and Y.

8:48 We generated the fir
st corridor, and after the corridor will be drawn, it will be drawn in parts. The
parts that have gone to the screen will be drawn on the other side of the screen. As a result we get the

9:16 Now we create draw and update methods. In draw we indi
cate canvas, and in update we indicate
delta T. Everything is simple in draw method, and we just call the drawing that is in the array. Then we
create such method in the barrier class.

10:55 Well, we still have one more method to go. This is update method.

Also, we will go through our
arrays and call the update method. We will indicate dt in the parameter.

11:24 Then we add the game panel to the following parameters and the constructor. Now we declare a
variable in the class.

12:15 As each of the barriers w
as given the pointer to the barrier manager, and then it can easily refer
to the game panel. Therefore, we are not going to pass it.

12:38 We pass Boolean variable that indicates the upper and lower rows.

12:56 Then we create a method in the barrier and th
us add to the game panel in the constructor. Now it
remains to describe the barrier class.

13:19 The barrier class will have three variables, bitmap, X and Y coordinates. In the constructor we set
bitmap, X and Y coordinates.

14:05 Next, we add the barrie
r manager variable, in order to keep it, so it would generate us. Then we
return bitmap and set Y.

14:50 We still have left 2 methods as draw and update. Everything is simple in the draw method; we just
draw as we did the ship on center of bitmap. First, w
e set the center coordinates.

15:16 Then it remains to describe the update method. It must update the status of all the blogs, and if
any of them got outside the screen it should redraw them on the other side of the screen, making
continuous barriers.

15:55 To keep the barrier smooth, we will be set a random point to which the corridor will be directed,
namely the vector of its direction, and when it reaches this point, we choose a new point.

16:15 For this we will create Boolean variable and call it “d
oit”. We reached the target. So let’s fill the
update method. Here we described the update method, and now we tell you what we have done here.

16:40 First, we check if the barrier is still here. Just to remind you that in the barrier manager update
in a loop, namely we ask each of our barriers, whether it went outside the screen, if it did then X
is less of the screen width.

17:19 Just to remind you, this is Boolean variable If we have the top row, then it is true and we deal with
the top row, if it
is false, we deal with the bottom row.

17:42 Now we explain why is that, because first we deal with the top row, and then we set Y and deal
with the bottom row.

18:06 if we got closer to the target point by less than 50 pixels, then we put doit=frue and we

need to
generate a new point. We choose it from the screen area and subtract the corridor area and plus a
quarter of the corridor. This gives us a random number, a quarter of the corridor value, and then the
screen height minus the quarter of the corridor
, namely the edges of the corridor do not go far beyond
the edges of the screen.

19:08 If the mid
point of the corridor is less than the target point, and then we add to the center of the
corridor a random value of 15 pixels. If it is vice
versa then we su
btract that.

19:40 In this way we calculated the center of corridor, and accordingly we set Y. When we go through
the bottom row, we will have the center point of the corridor. It remains to set the value.

20:03 After that we set X, so its new position wil
l be the end of all the blocks. Namely, we look at its
current position and add the width of the block and multiply by the number of blocks.

20:35 The only thing we have left to increase X for a regular value. That is, when the barrier is moving
across the

screen, and we already know how to do it.

20:58 We assign to X, X minus BM. Then we take the speed of the ship in the gems panel and multiply by
the delta T.

21:10 So we are done with the barrier class and barrier manager. It remains only to place them on

game panel. Now we set the width and height of the screen.

21:34 We add the manager and update to drawing. Now we run the application and see how the barrier
will be drawn.

22:06 So let’s run the project.

22:40 We click on start game, here we see the
barriers, but we cannot collide with them. To deal with
that, we need to use the collision method in the ship class.

23:13 Namely, we should start collision checking in the counter, to do that we have to take the points
from the array.

23:33 We should get
a barrier from the array and use its points, so we call the arra
y. In order to make
the arrayto
give us these poi
nts, in the order that we need to

24:06 We call it temporary = new array list collection.

24:18 Now, we create get array method. Here we give

out array list and put the points. Next, we will
only work with arrays and with the class of points.

24:49 To make it short, we take this function from the ship class. They will be exactly the same as for the
barrier class as the ship class, because they
are drawn from the center of its bitmap.

25:26 So we duplicate again our get point function and we advise to take our declaration from here.

25:45 So we declared all the points, and now we have to add them to the array.

25:53 Then we create array list poin
t variable, and also we call it temp, next we initialize and add all the
points in order. The order must be kept strictly counterclockwise. First we do the top left, and then top
right, bottom right, and the bottom Left.

26:37 When we set the array, we can

return it. When we returned the array we must write this
(temp.get (0), temp.get (1), temp.get (2), temp.get (3)). As a result, our function will provide the
collision for us.

27:18 In addition, we need to check the same thing on the bottom row. Also, we
duplicate the function,
and after all the checks we clear it.

27:52 We still need to create a second array. We call it “temp 2”. Then we compose it from our lower
walls of array. Now we combine it in one condition with "or". Here goes our first check, and
then goes
the second check.

28:33 If it works, then we collided with the barrier. Now we tell the ship that it is crashed. Next, we will
do a small condition, and we will check on a collision ourselves if the ship did not crash. If we will check
when it co
llided, then we will endlessly be colliding with the barriers.

29:17 The development environment suggests that the temp 2 is not used. So we will add everywhere
the temp 2.

29:38 Finally, we advise you to add to the condition the background update and
barrier manager update

the ship did not crash. When we collide with the barrier

then we stop the barriers, background, and
the coins.

30:08 Now to show that the collision works, we put break point inside of the function, and if the ship
collided with th
e barrier, then debug stops at break point.

30:46 Debug is activated by a green beetle button.

30:56 Now let’s start and go to the screen.

31:22 There is running installation, and our game started. We started flying, and the program said it run
into the br
eak point, and it offers us to switch to debug mode. This is very useful debugging tool, but
now the important thing is that the program caught the collision with our barrier.

31:59 Now we click on No. In the next lesson, we will create a bonus class, this

is a class of coin, and also
we will make the collision reaction to the coin. It will be a positive one. When we pick the coin up, we
add points to the score panel.

Lesson 10

The 10th tutorial will show you how to create a bonus class and teach you to p
lace bonuses throughout
the game and handle how the player receives bonuses.

00:02 In the last lesson, we created the barrier manager and the separate barrier class. In this lesson, we
will create a bonus class, this is a game coin. Now our task is to
describe the class, then to add it to the
game panel and to create a method that handles the collision with the spaceship.

00:35 First we create a variable in our game panel and call it a bonus.

00:53 Then this variable will be called coin.

1:00 Next, we c
reate a bonus class and click on ok, and then we create the constructor and initialize the
bonus variable. Also, we will pass drawable and X and Y parameters to our coin.

1:33 We set the initial value of minus 200 and minus 200. Also, we draw it behind the

visibility of the
screen area. Then we create the constructor.

1:53 It is all done, we created it. Now we create the bonus class. This class will include the following
variables, such as bitmap and X and Y coordinates. In addition, we will pass the barrie
r manager.

2:22 We will do this in order to know where the corridor is now, and in what coordinates we can
generate the coin, so that the player was able to pick it up.

2:38 Let's fill the variables with the coordinates and Y. Next we'll create set barrier

manager method
where we indicate the barrier manager.

3:46 So we can always turn to the barrier manager. We create get bitmap method, it is familiar to us.

4:04 Then we copy a method from the barrier, this method returns us the array that contains all the

points. We will need that to find the collision points.

4:29 Next, we implement two methods, such as draw and update.

5:02 We pass dt value to the parameters. Everything is simple in drawing; we just draw on the center, as
we did it in the barrier class a
nd the ship class.

5:25 Here will be our update. If X went in minus for a quarter of width size, it is minus a quarter of our
screen, then X is assigned the width value of the game panel and plus the bitmap width.

6:27 Then the position is taken from the
barrier manager randomly.

6:43 Here is the barrier manager and the last thing we need now to change variable to values. Once
again we take the game panel from the barrier manager, and here we take our ship speed and multiply
by dt.

7:33 We need to make som
e changes, as in the game panel were not saved the width and height values,
so we save them now.

8:17 Then we set a type for them.

8:34 We do the same thing with the height.

8:49 Now we do some correction, we take screen width instead of get screen.

9:13 W
e remove the brackets, as it is not a method and it is a variable, and we do the same thing here.

9:23 After we are done with this, we have to set the barrier manager for the coin class and locate it at
draw and update methods in the game panel. So let’s d
o it.

9:47 Here we add set barrier manager, ok we did it.

9:58 Next, we add the coin to the drawing. Then in update is a condition, if the ship did not crash, we do
update. The same thing we do with dt, and now we're done.

10:26 Now we run it on the device

11:06 Here are the coins. Now we do the collision handling with the coin.

11:22 Next, we create new array list. Also, a point is going to be called coin_point = new array and our
method get array. Now according to the condition if the ship crashed into t
he coin, then we give a player
the certain amount of points.

12:44 At the moment we will hide the coin behind the screen. Namely, we do this, coin set X value
minus 200, it was initially, and we just hide it behind the screen, and also set Y minus 200.

12 Let’s create these methods, this.X = new X value.

13:26 Likewise we do the second method, this.Y = new Y value. Now using the same principle, we have
to pick up the coin.

14:13 Now, when we got the coin, it should disappear, and the coin disappears. If
we did not handle the
coin pickup, we would not be able to get it.

14:33 As we noticed the spaceship explodes without the animation. Most likely this happens, because
we have not downloaded an animation array, which provides the ship class.

15:00 As we did

not use set boom animation, it is naturally that there was not any animation.

15:15 Ship set boom animation, here we need to specify the animation as an array, so we create a new
array of bitmaps.

15:45 It will be a new array, and we add in it from a fold
er of resources, boom 1, boom 2, they should be
added in the order in which they will be played.

16:21 Now we set “set boom animation”. let's see how it works. We start the game, start playing, and
we will collide purposely.

16:53 We see that the developme
nt environment generated an error, and the error is in our array size.

17:07 Yep, we came out of the array size. This is handled easily. Now we have the original size of the
array in a variable, and the animation is being played to the end, so we will not
fly from the application.

17:40 The application is being installed, then we start game and see. Indeed, the application runs

18:06 In this lesson, we created the coin class and learned how to handle the ship collision with the coin

18:23 In the
next lesson, we will create win and loss menu and will learn how to handle the events, such
as calling to root game activity from thread, and we do this through the handler. Also, we will add music
and complete our application.

Lesson 11

Almost there!

the 11th tutorial, having fully completed our project, we’ll learn to handle WIN and
LOSE events, create WIN and LOSE dialogues, and use Handler for processing messages from threads.
You’ll be able to create conditions for the player’s WIN or LOSE events
, add music and graphic effects to
the game.

00:02 In this lesson, we will handle winning and losing events, create winning and losing dialogues, and
learn how to send messages from the secondary thread to the main thread.

00:23 In the first place, to ha
ndle messages from a separate thread, surface view uses a separate thread
for drawing. Then we have to create a handler in the game activity, which will catch the message,
depending on the message it will do a particular function.

01:00 So we create the ha
ndler, please note that it must be final, as it will be called by all various

1:20 Next, we rewrite handle message method where we will catch the messages that were sent from
the other threads. In order to recognize the messages, we will create
them as separate variables.

1:48 Update score variable is equal to zero. If we get zero value, then we have to update the score.

2:02 1 means that the ship is crashed, and 2 means that we lost.

2:15 We explain later why this division this is made.

2:21 Now

let’s catch the message. We need to create a condition, if message is equal to our score, then
we need to update the score. Therefore, we will create a separate function for it, such as I_get_coin.

2:55 Now we create this method in the game activity. So w
hat do we have to do in I_get_coin. First, in
the game activity we add variables that will be responsible for the collected coins and the score.

3:50 We set the initial value to zero for them, as a result we got the coin. Then we add the number of
get poin
ts to the score value for a specified number of points, at the time we have 200. We assume that
we get 200 points for each coin.

4:35 Next, we create the conditions for winning. To win we need to have the number of coins = 2. At the
moment, we set it, so
we can test later. In this case, we call I_win function.

5:08 Then we create I_win method, which we will describe later. Now let's go back to the messages.

5:23 Next, if we got the message that we crashed (death) then we have to play an animation of the
plosion. So we use the post delayed and new runnable, we send to the handler in three second delay
that we lost.

6:11 Finally, we catch the last message when we lost. In this case, we call I_lose function.

6:36 let's create this function in a class of game

activity, what should be done here we will do later.

6:56 Now, we make the score panel that displays the player’s points. We do it dynamically. Here we
added a layer of relative layout and set the background to it, then we set gravity in the center and th
size, in addition, we set the current X position, text and the font.

7:40 Now we move on to the game panel and will send the messages from the main thread. We do the
update, and here where the messages get coin and loss should be sent, we create the mess
age and send
to the handler.

8:25 Then we will use the background manager to find our panel, BM.game_panel and thread. As we did
not set the game panel, we pass to it the main game class, when we create the game panel.

9:15 Here is our game, it just was no
t saved, so we saved it, and then we create a variable and initialize

10:05 Now we can access to game and our handler. Then there is message, and we got the coin, and our
message is zero. Next, we send the message from the handler.

10:37 Also, we do
the same with the collision. We pass the death value. This value is 1. Then we set the
message and send it to the game activity.

11:03 Now it's time to add the methods, such as I_get_coin, I_lose and I_win. So we have to play the
sound when we receive the
coin, I_get_coin. To do this, we create a media player, let's call it MP, and
we create it from the resources. Then we pass to the first parameters our game, game_this, and we pass
to the second parameters the identifier to the resource.

11:56 After we set

the variable, we type to start playing our sound. In the same way, we do for the ship

12:19 For this we move on to the game panel, and in update method where we check for collision with
other barriers, and if we collided with the barrier, we ad
d a variable to the media player, and as the first
parameter we pass the game, because the game is kept in this variable.

12:46 Then we select explosion resource, and also we run the media player.

12:57 In I_lose and I_win methods, we should display winnin
g and losing dialogues. Now we prepare
XML for dialog windows.

13:16 Now we move on to the resources and layout folders. Similarly, we create a new XML and XML

13:49 Now when we created 2 XMLs for loss and win, we will place them in the game ac
tivity in
onCreate method, as we have done with other elements.

14:06 For this, at the top where we declared all the variables, we also declare winning and losing views.

14:34 Then we set these values in the on Create method. We will do it through layout i
nflator, which
was already declared and created, so we just set it.

14:55 We placed the dialogues and created XMLs, and we also assigned the listeners for the buttons to
go to the main menu in both dialogues.

15:10 Now we just need to display these dialogues when we will need to. We go into I_lose method,
here we have to stop the game and put it on pause and to display lose dialogue. We set the visible value
to invisible one, and we do the same goes for I_win m

16:03 Here we also have to stop the game and put it on pause and to display win dialogue. We set it

16:47 Now we can run the application and see how the dialogues will be displayed and the sounds will
be played.

17:00 Let’s start a new gam
e. We got one. Here a program gave us win menu. Next, we try to play, we

17:27 Now let’s move on to the music. We really need some music in your application. To do this, we
create general media player in game activity variables. This player will be r
esponsible for all playing
background music in the game activity.

17:53 Let’s call it main music. Initially, when we create a game activity, we set value media player
create. First, it will play action music in the game, the first parameter is game_this, a
nd the second
parameter is music from raw folder.

18:41 Then we select the music. Next, in order that we will not scare the user by very loud starting
music, we set volume to a value of 0.3, but you can choose at your own discretion. After that we start
he background music.

16:17 Here is another peculiarity, always turn off the background music, so that when the user quits the
application, it will not continue to play.

19:33 For this, in onStop method, we will check if the media player, main music plays n
ow, we stop it.

20:01 Now we move on to I_lose method, and here we will also check whether it plays at the moment.
Then we stop it and assign the main music value. Next, we create media player create and set the
parameters game_this, and then we select the

resource, it will be R.raw and lose. Next, we start playing
the music.

21:22 We do the same thing with I_win method. You can even just copy a piece of code and change only
the win resource. All right, we set the music for the game, and let's do it in the
main menu.

22:03 Here we create media player variable, called it main menu music. Then we initialize it in onCreate
method, and it's called like media player create, here we specify main_menu_this and the resource from
which we play the music. We choose ma

22:53 As to the playback, if we put playback in onCreate method, then music starts playing
automatically during the game change
over to the main menu, because main menu is already created.
Also, it will not be recreated, and therefore, we are not going

to place the playback in onCreate method.

23:22 However, we will create onStart method; we will be setting the volume in this method. We set the
same as 0.3 and 0.3. Then we start playing the music.

24:06 Then we will stop music in on Stop method. We will

check whether our music is played, it is
playing, and then we stop it.

24:36 Here is some correction, we will move the initialization of main menu music to onStart method, so
each time when activity starts, and the main menu would download itself with the

right music.

24:59 Well, we can run the game. We run it and we hear the music. Now we will try to win once and to
lose, accordingly, will listen to the music.

25:24 Here is playing the main music, and then here goes winning music. Now we move to the main
menu, then we click on start game and we try to lose now.

25:54 We just lost and we hear our music. That means that the music is done right.

26:03 Next, we will add one more thing in the game activity for our convenience. When we click on back
button, the
user will go to the main menu instead of pause menu, to prevent this, we will create onBack
pressed method.

26:42 In this method, we will implement the same steps that when you click on pause button. You can
copy it completely. We show the pause menu and s
et the pause.

27:12 Here is the last line, if we do not remove it, then it will return us to the menu. We remove it. Now
we can check it.

27:31 Everything will work. We click on start, and then click on back button, and we get the main menu.

27:44 Now we h
ave to take care of the animation buttons, because they look dead. When we click on
them nothing happens.

27:58 Now we will do them. We go to main menu, and here we already created onTouch listener
buttons, now it is useful to us. What do we do? We create
switch and ask the event what action is
happening now, and then we monitor the value.

28:43 if we have motion event action down when we put a finger, then it is image button, we set image
resource and indicate drawable pressed position.

29:12 Namely, when
it is pressed it changes its image. Next, if we lift a finger, then it is action up.

29:30 We must return to action up its original state, and if we simply lift the finger, namely we started
pressing it and we realized that we do not need it now, action_ou
tside, we return button to a normal

29:49 Also, if we have default value, we will return the button to the normal position. Now let's see how
it will look on the main menu.

30:32 Now we press it, we see the menu button, we are moving outside the
area, and then we press the
button and after the change
over the button goes off.

30:53 Now we have to do the same thing for each button, we need to create the same onTouch listener.
But we will do a little bit differently. We will create a class that will

inherit this onTouch listener
interface, and we will pass to it image view. It will know to which button it should change the image.

31:30 It does not take much time to write it, now let’s write it.

31:37 We will leave this part for now, and we will creat
e set onTouch listener new, and here we indicate
new touch button class, as well here we indicate image view that we need to change.

32:00 The development environment tells us that there is not such class, but we can create it.

32:07 Here we see that it in
dicates on touch listener interface, this is what we need. We click on finish,
our class has created. We now have own class, and we write the image view variable, it will be stored in
its own class.

32:33 Here we set it and create the constructor, and we s
et image view in it. After that, in on touch
method we duplicate what we created in the main menu.

33:03 We duplicated it, now we change some variables here, and here is our image. As a result, we have
a separate class.

33:25 Here we do not need that, and
there is only one line. We assigned the button; this touch listener
will change the button state.

33:40 Now run the application and see how it will work.

33:50 As you see, it works just fine. Now we set the same touch listener to all buttons. To do this, w
move to the game activity, and in onCreate method we see what buttons we have when we create all

34:23 You should note, our pause button is not image view, because it is inside. So, we need to initialize
image view variable that we will pass to tou
ch listener.

34:43 For example, this will be pause image = pause button find view by id, and now in XML pause we
see what id our picture has. We did not set it before, but we set it now.

35:15 Id is set, and now we find it by this id.

35:36 Next, we indica
te that this is image

and now when we assign to the pause button onClick
listener, we also assign set onTouch

listener, and then we indicate image view here, which we will
change when we touch our button. We do the same thing for all buttons, namely they are the continue
button and back button to the main menu.

36:19 Now we set this to the continue button and the

main menu button. Then we pass it ourselves.

37:06 Also, we need to add all that in our dialogues, such as winning and losing dialogue.

37:40 Now our application will look beautiful. Let’s start it and see how it will be working.

37:51 We start the game
and press the pause button, and then the continue button, and we are losing.
The button works, and now we won.

38:26 Here is the last little touch, when we saw the last moment, there appeared the artifacts below,
namely where the background meets with the
barriers, and these barriers came out a little bit fuzzy,
because the resource of our background is a little less than the height of the screen.

38:57 To fix it, we go to draw method in the game panel, and we fill the canvas with black color.

39:06 Now we
will not have these artifacts and everything will be displayed correctly and properly.

39:15 Let’s start the game.

39:44 It is starting and we see that there are not any artifacts in the bottom, and we won the game.

40:24 This lesson is finished. I
n the ne
xt lesson, we will publish our application on

Google Play, an
d we
consider adding it to the s

Lesson 12

The final tutorial will show how to prepare your application for submission to the store, create signing
keys for applications, export the projec
t and submit applications to Google Play.

Make sure you also check our important articles and future updates and bonuses inside the members
area at

that will help you promote the app, find traffic and get great sales!

00:03 In this
lesson, we will publish the mobile application on Google Play Store. Now we prepare the
application for downloading to Google Play. The first thing we need to do, it is to set the icon for the

00:24 This is easy to do, we just click on the pro
ject using a right button, then we select new, other, and
we open Android tab and select icon set.

00:36 Here we will be offered selection menu, and we choose launcher icon for which we do it and the
name of the project.

00:50 Then we click on next, and he
re it offers three tabs, such as image, clipart and text, we need to
choose image, and we upload the image that we want to see in the application. We can set either round
or square.

1:15 We keep the round one, we think it may bring some luck, and we click
on finish. It offers us to
replace the old icons, and we choose to replace them all.

1:42 So the icons are created automatically, each icon goes for its definition.

1:54 Now we will export our application for publishing on Google Play. To do this, we open
the file tab,
and then we select export, Android tab, and export Android application. It offers us to choose a project
that we want to export.

2:22 It asks for the key store password. If you have it, just use it, in our case we do not one, so we will
create it. To do this we choose a location where we will save it, then we save it and call it "key".

2:50 Next, we assign a password, and after you did it, just click on next.

3:05 Then you need to create an alias, you give it a name and assign the passwor
d. Next you validate it,
and you can set 25 years by default. Then we type the first and the last names, organization type, for
example, individual, your organization, city where you live, district, and a phone number.

4:53 Then we click on next, and then
we have to choose APK file that we want to sign. We go into work
space and in a folder of our project. APK file is stored in the bin by default.

5:28 Now select the folder where we save APK file, and call it “our game”. We click on finish; of course,
will not let us sign APK with such data. You have to enter your own data, and then you can only sign it.

6:05 Now our file is signed, we go into the documents and here our APK is signed for downloading.

6:28 Next, we go to the browser and
pps/publish/ website. In order to have access to
Android Development Console, you will need to register as a developer. It is not difficult, the only thing
you need to do just to pay $25.

7:01 Let's move on to the application download. Now we click on uplo
ad, we are offered to select APK
file, then we go to documents and select APC file. We download it. When the application is downloaded,
we click on save. After saving, we fill in the information on the application, then we upload screenshots,
they should b
e more than two, it is a mandatory requirement.

7:51 Next, we download the background, it downloaded.

7:58 Then we download the second one, we choose the file and click on upload. Then you can upload
the high resolution icon, promotional graphic and additi
onal images of your application. Also, we
provide a link to the promotional video and privacy policy. If we do not have it, we put a check mark not

8:41 Then you are offered to enter a title description, changes, and promotional text. In the tit
le game,
we type the title and description. The other fields are used only if it is necessary.

9:26 Then you select the application type (games), category (arcade and action), copy protection, and
content rating. We set for everyone. Next, you choose free
or paid application, it depends on you, we
choose free and countries.

10:05 Next, we indicate the website of developer, email, and phone number. Next, we select that this
application meets all the agreements and guidelines. Then we put the check mark that
the application
may be subject to U.S. laws, etc.

10:39 Next we click on save, and here we are asked that you really want to distribute it for free. After
you select it, nothing can be changed, and click on ok.

11:01 Then it says that it is necessary to ha
ve high resolution icon 512 by 512. So we fill this big icon and
click on save. Then we again agree that we understand that it's free. It is all saved.

11:27 Next, we can move to APK file, and here is the information about our APK. Also, here are two
, such as activate and remove. If you click on activate, it does not mean that you publish it, before
the publication you need to activate the APK, and it is published only for testing.

12:00 When APK is activated, and all the information about the applica
tion is entered, you need to click
on publish, and your application will be in a few hours in the store.

12:23 Next, we just wait on monthly reports, getting big money and live happily. Good luck to all and
have successful sales.