Cocos2d-x game instances (23)-simple action games (1)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.