zoukankan      html  css  js  c++  java
  • cocos2d-x之为label添加事件监听器,单点触摸

    cocos2d-x之为label添加事件监听器,单点触摸

    在bool HelloWorld::init()

     1 //获取可见区域的大小
     2     Size visibleSize = Director::getInstance()->getVisibleSize();
     3     //定义一个文本,显示内容
     4     auto label = LabelTTF::create("Chick me", "Courier", 30);
     5     //定义label的位置
     6     label->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
     7     addChild(label);//将label添加进去
     8     //EventListenerTouchOneByOne表示一个接一个的触发,每次触摸只能监听到一个触摸点
     9     auto listener = EventListenerTouchOneByOne::create();
    10     //onTouchBegan表示开始触摸的事件
    11     listener->onTouchBegan = [](Touch *t, Event *e){
    12         
    13         log("onTouchBegan");
    14         
    15         return false;
    16     };
    17     //getEventDispatcher获取事件的派发器,
    18     //addEventListenerWithSceneGraphPriority(事件, 节点);添加事件监听器
    19     Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, label);
  • 相关阅读:
    sshpass做秘钥分发,ansible做自动化运维工具
    Day7 面向对象和类的介绍
    R-aggregate()
    R-seq()
    R-ts()
    R-ets()
    python-无联网情况下安装skt-learn
    python-线性回归预测
    python-matplotlib-ERROR
    python-pyhs2
  • 原文地址:https://www.cnblogs.com/dudu580231/p/4375215.html
Copyright © 2011-2022 走看看