首页 > 数据库 > mysql教程 > Cocos2dx多点触摸实例

Cocos2dx多点触摸实例

WBOY
发布: 2016-06-07 15:24:53
原创
1044 人浏览过

bool MyTouchEvent2::init() { if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()-getVisibleSize(); Vec2 origin = Director::getInstance()-getVisibleOrigin(); Label * text1 = Label::create(, Arial, 24); text1-setP

bool MyTouchEvent2::init()
{
if (!Layer::init())
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();



Label * text1 = Label::create("", "Arial", 24);
text1->setPosition(Point(400, 280));
this->addChild(text1,1,1);


Label * text2 = Label::create("", "Arial", 24);
text2->setPosition(Point(400, 200));
this->addChild(text2,1,2);


Label * text3 = Label::create("", "Arial", 24);
text3->setPosition(Point(400, 100));
this->addChild(text3,1,3);


//创建多点触摸监听器
auto listener = EventListenerTouchAllAtOnce::create();

//单击
listener->onTouchesBegan = [&](const std::vector& touchs, Event* event)
{
auto text = (Label *)this->getChildByTag(1);
int num = touchs.size();
text->setString(Value(num).asString() + "Touches:");

};

       // 移动

listener->onTouchesMoved = [&](const std::vector& touchs, Event* event)
{
auto text = (Label *)this->getChildByTag(2);
int num = touchs.size();
std::string str = Value(num).asString() + "Touches:";
for (auto & touch:touchs)
{
auto location = touch->getLocation();
str += "[touchID" + Value(touch->getID()).asString() + "]";
}
text->setString(str);

};

       // 松开

listener->onTouchesEnded = [&](const std::vector& touchs, Event* event)
{
auto text = (Label*)this->getChildByTag(3);
int num = touchs.size();
text->setString(Value(num).asString()+"Touches:");
};

      //注册监听事件
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板