Touch Handling in Cocos2D 3.x( 4)

Source: Internet
Author: User

Touch Handling in Cocos2D 3.x( 4)

Create a touch Lifecycle

Let's improve our app. Isn't it better if players can touch the screen and drag and drop a hero to a specified position?

To accomplish this, we must use all the touch events provided by Cocos2d 3.0:

TouchBegan: Call touchMoved when you touch the screen: Call touchEnded when you move your finger on the screen: Call touchCancelled when you stop the screen: it is called when the user still touches the screen but some other problems stop your node from processing the touch event (e.g. when the touch moves beyond the boundary of your node ).

Our new hero placement algorithm will work as follows:

When a user touches the screen, a hero will be generated. When the user moves his finger on the screen, the hero will also move. Once the user's finger leaves the screen, the hero will be placed at the last touch of his finger.

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.