Iron Mouth Lee's COCOS2DX tour of some games in the direction of control tips

Source: Internet
Author: User

An enumeration class is defined in the. h file, which contains the upper and lower left and right four directions.

Enum DIR

{

Right_dir,

Left_dir,

Up_dir,

Down_dir

}

Like the snake game, is the automatic movement, is to define a scheduled task schedule, how many seconds to move up and down about how much. However, you should first define the interaction event.

Creating Listener Objects

Auto Listener=eventlistenertouchonebyone::create ();

callback method

Listener->ontouchbegan=cccallback_2 (Gamescene::gamelogic,this);

Event distribution

_eventdispatcher->addeventlistenerwithscenegraphpriority (Listener,this);

--------------------------------------------------------------------------------------------------------------- -----------------------

if (mx>my)//move around
{
// The direction of the click is larger than the direction of the head, moving to the right, horizontally, or left.
if (Touch->getlocation (). x-10>head->col*31)
{
//Move right
head->dir=right_dir;
}
else
{

Move left
head->dir=left_dir;
}
}
else//Move up and down
{
if (Touch->getlocation (). y-10>head->row*31)
{
Move Up
head->dir=up_dir;
}
Else
{

Move Down
head->dir=down_dir;
}
}

The above should be written into the Ontouchbegan function, due to the time of the small series, not to elaborate, I hope to be useful to you.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Iron Mouth Lee's COCOS2DX tour of some games in the direction of control tips

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.