How to Use cocos2d-x to make a shanty Angry Birds game DRAMA: Part 1
Note: This tutorial is based on the Tutorial "microComing from innovation, hope and smile. (I will publish it in three tutorials)
Before that, I have several requirementsDescription.
First,This is my first copy tutorial, and I will try to useCocos2d-xLaterI will useThis method avoids unnecessary copyright disputes andCocos2d-xEnthusiasts provide some resources.
Secondly, I willTest in advance to avoid difficulties in practice due to version issues.
Again, what is different from the past is that I will not translate all the original articles of Ray.Translated,ArticleAndRay is different. I will try to use my ownI think it is still a reasonable way to organize the content of the tutorial. I will pursue a simple, easy-to-understand and easy-to-use method that will allow everyone to spend the least time learning the most useful knowledge.
FinallyRelease environment description. What I will use isMac + xcode,ForMac kids shoes, vs2010 is also. Only some differences on the operation interface,CodeThere is no difference at all. This is alsoA highlight of cocos2d-x ---- cross-platform!
Okay,Let's get started!
FirstLoadCocos2d-x, there are two typesMethod. First, open your browser and enter http://www.cocos2d-x.org/projects/cocos2d-x/wiki/download. then, download cocos2d-1.0.1--0.9.1 @ Aug 17,201 1. The second method (recommended) uses Git. You can search for git usage on the Internet. Can I go to http://code.google.com/p/git-osx-installer/downloads/list without installing git? Can = 3. download the latest version. InstallGitThen, open the terminal and enter the following command:
Git clone https://github.com/cocos2d/cocos2d-x.git, then in your homeviewYou can seeCocos2d-x filesFolder. The directory result is as follows:
Then,Let's start InstallationCocos2d-x (if it is directly from the cocos2d-x Official WebsiteThe following process is the same for children's shoes. UseGit is goodYes. You do not need to download it again later. You only need to open it.Termical, then CD to the cocos2d-x objectAnd then enter the following command:Git pull is enough.Saves a lot of download time .) Installing cocos2d-x is very simple, the specific process is as follows:
1. Open terminal, then CD to the cocos2d-x directory below
2. Input ls to see what is in this directory. (This step is not required)
3. Enter./install-templates-xcode.sh-u-F and press Enter.
As shown in:
4. The following prompt is displayed:
If you are using xcode3Input3. If xcode4 is usedInput4. If both are usedDo not enter anything. Press enter. The successfully installed done is displayed! Done! As shown in:
Because I have installed xcode3 and xcode4, I choose not to enter anything and press Enter.
I have two errors here, but it doesn't matter. If you don't want to get a similar error message, you can enter sudo. /install-templates-xcode.sh, note that-u is no longer needed here,-u is installed under the user directory,-F is forced to reinstall. Below is the result diagram of entering sudo./install-templates-xcode.sh directly.
Well, the cocos2d-x has been installed, Let's enter the topic of today. First create a new project, select the cocos2d-x under the IOS category, then select cocos2d_box2d, and then click Next:
Name the projectIsCuteAPultCocos2d-x, as shown belowFigure:
Then clickClickNext, nextCurrent screen:
You can create a new fileFolder, used to save all your game projects. Here, I am usingIosgamerepository,RememberSource ControlThe selection box is removed, because I will teach you how to use it manuallyGit as the sourceCode Management. Last clickCreate,In this way, our project has been created. Run the following screenshot:
Next, I will teach you how to use gitLocalSource codeManagement. Open ternimal, then CD under your iosgamerepository directory, then CD under the CuteAPultCocos2d-x directory :( below is my operation screenshot)
Then startEnter the following command to create a newGitRepository:
Then you will see a lotOutput, and then your repository will be created. At this moment, some children's shoes may ask, "How to Make a shanzhai?Angrybirds! I want to use itMake a lot of money! ". Don't worry. Next, let me explain it to you.GitThe magical use of warehouses. Some people accidentally use itXcodeI deleted an object, but it didn't appear in the recycle bin. then I couldn't find it again. I cried and asked someone for help... Don't be afraid.Git, you no longer needI am worried about this kind of thing. First, openXcode, and then right on helloworldscene. cppKey, select Delete in the pop-up menu, and the following screen will appear:
If youSelectRemove reference only, so the file does notDelete. You can still see the folder where the project is located. Just inXcodeProject management cannot be seen. You can right-click the project name and add it. Here we select Delete, and then open the project directory to see what the situation is:
At this time, you find thatHelloworldscene. cpp really does not exist, so you can look for it in the recycle bin:
555555555555555 ..... It's empty!
Don't be afraid, we haveGit! Enable ternimal,InputGit status, yesView the status of the current Repository:
Then, do you see deleted: CuteAPultCocos2d-x/classes/helloworldscene. cppThis message indicates that you have just deleted this file. Now we need to retrieve this file. Run the following command:Git checkout CuteAPultCocos2d-x/classes/helloworldscene. cpp
Now, the deleted file is back again. Haha! Now add the file, right-click "classes", and click "add files to" cultapultcococs2d... ", Such:
ThenJust added this file.
Well, here, I just demonstrated some of the most basic git usage. , if you are interested in git , you can go online and learn more. We recommend that you see the content above the http://progit.org/book. Finally, in terminal, input git tag projecttemplate, to tag the current version. This feature allows you to download multiple versions when writing a tutorial without saving copies of each version. To obtain a tag, git checkout-B projecttemplate, then, package the file in the project to projecttemplate This version is available. If you have modified the final version later, for example, git tag final and git checkout-B final. However, remember to use git stage before each tag, git commit-m'message of this modification '. If I still don't know much about it, skip it first. In the subsequent articles, I will insert these content, and you can just follow them.
Note: Each cutWhen changing the version, it is best to disableXcode. If notOpenXcodeMay appearSchemaIn this case, you only need to disableXcode, open it again.If you are not comfortable with this command line operation method, you can downloadTower, it isGraphical useGit tool, which is very convenient to use. You can search online and find a cracked version.
OK,Now we are starting to play the cottage bird game!
I. Clear the Template
First, open helloworldscene. cpp andCode deletion:
- Void helloworld: addnewspritewithcoords (ccpoint P)
- In the helloworld: helloworld () method)Delete// Setisaccelerometerenabled (true); IThe annotation method is used here.
- Void helloworld: cctouchesended (ccset * touches, ccevent * event)
Finally, IDelete the following code:
SameDon't forget to comment out the declaration of the two functions in helloworldscene. H, as shown in:
Compile and run the program, and then we will get the following screenshot:
Next, open terminal, enter git stage *, and then enter git commit-m'clean up '.
Enter the following command:Git tag cleanup I am behindThen enter the GIT tag-L. This command is used to view all the tags. Now we have two tags. Do you still remember our previous project? click the mouse to drop down many blocks. Now we have commented out the code and deleted some of it. We need to retrieve the previous items. Next, I will show you how to use tags.
First, we turn off the project because I want to make a "time trip" and return to our previous version. Run the following commands in sequence:
1. Git checkout-B cleanup (this statement indicates creating a new branch)
2. Git status (check the status of the current repository) If the output is:
# On branch projecttemplate
Nothing to commit (working directory clean)
Then jump to step 2.
If not, enter
Git stage *
Git commit-M 'some message'
As shown in:
3. Git checkout projecttemplate
At this time, you can open the project and run it again, and you will get the following:
Then closeClosedXcode,EnterGit status:
We haven't changed anything just now, but it still shows that there are changes. The information is as follows:
Why? BecauseEvery time xcode startsAutomatically createdXcuderdataRecording,MeDon't worry about it, directlyGit stage *,
Then git commit-m'message' is ready.Yes. Remember to add the-M information.
Then git checkout cleanup, and then open the job and run it, there will be the following:
If you want to return to the previous version, you can use git stage *,
Then git checkout projecttemplate.
At this time, you can open the project and run it. You will see the project at the beginning:
After talking so much, I feel very complicated. Some processes may have some minor issues. Let me summarize the usage of git.
Git init initializes a git Repository
Git add * adds all the files (including folders) in the current directory to the repository. Git will know any modifications to the files in the repository.
Git status to view the status of the current Workspace
Git commit submits changes to the Workspace
Git tag tagname: Create a tag. If the parameter l is used to list all tags, add-D to delete the corresponding tag.
Git checkout branchname refers to switch Branch
Git branch branchname is used to create a branch named branchname.
Git checkout-B branchname is equivalent to the following two statements:
1. Git branch branchname
2. Git checkout branchname
Git stage * confirm the current modification. Only the modification can be submitted to the repository.
Git add filename to add a file to the repository
Git RM filename to delete a file
For more information about git usage, see progit.org. You can also search for git usage on the Internet.
Statement: if you do not like the command line method, we recommend that you search for the tower. Here I will show the method for cracking the Tower: http://dl.dbank.com/c0zzihyb5o.
I am very sorry, my work of the virgin cottage has become so smelly and long. If you have any questions, please leave a message to me. My git and cocos2d-x are both just getting started. We will discuss and make progress together later.
Leave a message? Please click portal!
Copyright statement: This article by Zilong Shan People (http://www.cnblogs.com/andyque) original, welcome to repost share. Please respect the work of the author. Keep this note and the author's blog link when reprinting. Thank you!