Hi, Alex here from rebeloper.com and in this video I am going to talk about
GitHub and Xcode 9 and how easy it is to work with them together. So without
further ado let's get started and take a look at our and resources. Of course if
you don't have any images I urge you to go ahead and go to rebeloper.com/pablo
and there you can sign up for a flat rate unlimited designs for your app.
Before we get started let's take a look at what we are going to do. First of all
we are going to create an Xcode project that we will backup to GitHub. So let's
open up Xcode and let's create a new project. Click on file, new and project.
And of course we will create a game because a game is always more exciting
than a single view application. So click on next and I will call this ...
... of course select swift for the language and
click on next. And now here comes the most important part. Let's select our
folder where we will save it and let's create a Git repository on your Mac.
Because of course you know when you create Gits you create essentially one
repository on your Mac that is local and if you want to push it up to the cloud
you can create a repository on GitHub or Bitbucket in our case we will create it
with GitHub. So important check source control and we will create
Git repository on my Mac. Click on create and finally we have created our first
project with GitHub. And if we just take a look at our example project you will
see .git hidden file here. If you do not see your hidden file then go ahead and
open up terminal this is not essential but you can do that anyway the hidden
file will be there if you see it or if you don't. Go ahead and type in this line
of code defaults right com.apple.finder Apple show of files and true, okay.
Hit return and after that relaunch finder with kill all.
And there you have it! You will see all of your hidden files here and your local
Git repository. And of course if you want to remove seeing those hidden files
just select the false version and of course relaunch finder with a kill all
finder command, okay. Now that we have that done and we can see our local Git
repository let's go ahead and create something that worth saving into this
Git repository. So go ahead and inside Xcode let's find our GameScene.swift
file and first of all let's delete everything from here.Because we will not
need this in our example project. So you should leave is our didMove (to view: )
function. Now let's get all of this and maybe just move it slightly to the left,
okay. And one last thing in our GameScene.sks file just delete this
label. Here we go let's just build and run select iPhoneX
and let's see if we broke anything at all. Now it is building up compiling and
build has succeeded, okay. Just to be on the quick side let's drag and drop these
two assets Player 1 and Player 2 into our assets Xcode assets catalog and you
will see a zombie and a crazy clown. We will use these two to add them into our
scene. So as you can see already we have some
modified files this M here means that these files were modified
and not committed, okay. To do commit them in our local Git repository go to Source
Control and click on commit. And as you can see here are all of our changed and
or modified files and let's enter a commit message. Let's say cleaned up and
added two images. So that's it and we will commit these 8 files. And as you can see
the M's have gone away because no more modified files are available in our
Xcode project, great, good stuff. Let's take a look at our simulator and it has
launched successfully as you can see here is our info label with the nodes
and the frames per second, okay. Let's go ahead and stop that and add our zombie
the Player1 PNG to our GameScene. To do that let's just create an SKSpriteNode.
Let's call this player 1 and it will be
an SKSpriteNode with a fileNamed and that will be Player
one, okay. Now that we have created our SKSpriteNode let's position it to the
center of our scene. For that lets type in player.position= CGpoint.
And let's select this one with the CGfloat and that this self.size.width
and we will select half of our width and self.size.height
and we will multiply it by 0.5 again for the height. That's it we have our
position. Now let's add our zPosition. Player 1
and zPosition equals let's say 1.0. Because it is a CGfloat. And now oh
sorry about that I can see here are some optionals. Let's
delete that and not fileNamed it should be SKNode
imageNamed. And the optional would go away okay and that is
player 1, great, good stuff. And now finally let's add it to our scene.
Let's add child player 1, okay. Let's see what happens let's build run, okay.
As you can see here we have our sprite. Not well enough for that we need to add
our anchor point to our scene and that is self.anchorPoint = CGpoint and that is
0.5 and 0.5, okay. And I will just scale this sprite down
player 1 setScale to let say half of its original size.
Let's build and run again and see what happens, okay. I believe that we have put
out let's put it in the zero CGpoint.zero now. Let's build and run again.
This is how coding works we just try it and test it out and there we have it. We have
our player 1 sprite at the center of our scene, good stuff. So we have once
again modified our GameScene.swift file so we need to commit it again.
So let's commit it.
Lets commit one file again. And as you can see the modified the M letter here again
disappeared. Now what is interesting about this is that we already
have a source control right inside Xcode 9. And if you tap on this
little icon the second icon the show the Source Control navigator then you will
see our GitHub example master and if you just unpack this and you will see our
branches our tags of course there aren't any and our remotes that I will talk
about in just a minute and if you just select our master. As you can see it is
current you have already here our commits. We have our initial
commit our cleaned up then added two images and our finally added zombie
sprite commit. And of course you can filter it like a zombie of course we
have found our added zombie sprite commit here. Okay, let's clean that out
and now, if we want to let's say work on a new feature and then we would likely
create a new branch and that is... so that we do not mess up our master branch. So
let's create a new branch here. And we will create it from the master so we may
add new features to it and that will be the crazy clown sprite. So let's create a
branch from the master, okay, And I will name the branch crazy
clown, okay. Let's create it and it is not a valid branch name maybe we
aren't allowed to add spaces. So let's create it like this, okay. And here we
have our crazyClown and Xcode already took us into this branch so we are in
this current branch now. Let's go back and add our Crazy Clown sprite and I
would just copy and paste this player 1 sprite node code and just simply
change this real quickly to player 2 and of course the imageName should
be player2 again and now I will just not position it to CG point zero. I will
just change this out ...
Okay and it should be one by the other. So the width should be self.size.width
and let's multiply by 0.33 and the height
should be self.size.height multiplied by 0.5 and the same goes for
our player 2 sprite ...
The difference is that we will add it to the right of our player 1 sprite.
Let's build and run and test this out. Oh, we need to add this parenthesis.
Let's see how this looks. For some reason they are and at the point that I wanted them
to be oh yes of course. We need to set in the GameScene.SKS to
be of the size of let's see here yep we have a very large size here. So maybe
we will just add both of them to the center again...
CGpoint let's say 100 by 100 and that will be fine by me.
Okay, let's see how it all looks now, okay. Here we are and maybe let's make this
Y to 0 and this 100 ...
Okay let's build and run and see the two players sprites one above the
other, good stuff here. So we have modified our branch and let's commit
this branch as usual. And let's say added Crazy Clown, great. Let's commit one file
and let's take a look at our Git, okay. We have added Crazy Clown and if we
wanted then we could take a look at the assistant editors that this one
let's change this. And take a look at what happened in the code. Let me just take
this out here and here are the changes that were made inside our branch. So we
have changed our player 1 position and added our player 2.
Okay, good stuff here. So one final thing I want you to take a look at is the
differences between the master and the current. As you can see the Crazy Clown
isn't inside the master. So what we can do now is merge the Crazy Clown branch
inside of master because we really like our changes. So go ahead and select
master and merge Crazy Clown into master so we are merging Crazy Clown, so we are
merging master yes merge Crazy Clown into master. So go
ahead and let's merge that and here we can help see our differences and click
on merge, okay. And inside the master now we have added the Crazy Clown. And that's it
for local Git in the next video I will talk about GitHub and how you can save
your project into the cloud and never lose it again.
Okay, hope you like this video if you liked it go ahead and click the thumbs up.