Small man (Bill man) Personal Original, welcome to reprint, reprint please indicate the address, small man (Bill man) column address http://blog.csdn.net/bill_man
Starting from this article, we will start a simple NLP game instance. This article describes how to build and build basic scenarios. The results are as follows:
It simply displays the map and the main character, moves the main character, and moves the corresponding angle of view. First, let's look at the scenario initialization function init. The Code is as follows:
The first step is to define a background. The background image we use is the parallaxtest image in the test example. Like test, we increase the background by 1.5 times and work with the map size, then read our map. the tmx file, add the map to the scenario, and then obtain the protagonist Genie and add the genie to the map. Then, some initialization tasks are performed to allow touch screens, you can call update every frame to set the direction of the protagonist to 0.
The following is a touch screen operation. The basic operation is very simple. Click to move the main character from the left to the right, click to move to the right of the main character, and click to stop moving the main character. The Code is as follows:
As described earlier, vmove is set based on the touch screen position and the main character position. The specific motion is implemented in the update function. The Code is as follows:
As previously set, each frame of the main character is moved by 1 multiplied by vmove. The vmove we set previously. If it is stopped by 0, it means it is not moved. If it is set to-1, it is subtracted, add when set to 1, and then move the angle of view with the main character. This has been introduced before, but the following code is slightly different:
It is to determine whether the map has exceeded the boundary. If the boundary is exceeded, the map is not moved.
If there are any errors, I hope you can correct them more.
Next continue simple action game