• 2dx解析cocosbuilder中使用layer时的缺陷


    2dx解析cocosbuilder中使用layer时的缺陷

    cocos2d-x 3.7

    cocosbuilder中的layer通常会用到触摸属性:

    但是在2dx解析布局文件的时候,却很多属性都没解析:

    #define PROPERTY_TOUCH_ENABLED "isTouchEnabled"
    #define PROPERTY_ACCELEROMETER_ENABLED "isAccelerometerEnabled"
    #define PROPERTY_MOUSE_ENABLED "isMouseEnabled"
    #define PROPERTY_KEYBOARD_ENABLED "isKeyboardEnabled"
    
    void LayerLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) {
        if(strcmp(pPropertyName, PROPERTY_TOUCH_ENABLED) == 0) {
            ((Layer *)pNode)->setTouchEnabled(pCheck);
        } else if(strcmp(pPropertyName, PROPERTY_ACCELEROMETER_ENABLED) == 0) {
            ((Layer *)pNode)->setAccelerometerEnabled(pCheck);
        } else if(strcmp(pPropertyName, PROPERTY_MOUSE_ENABLED) == 0) {
            // TODO: Not supported
            CCLOG("The property '%s' is not supported!", PROPERTY_MOUSE_ENABLED);
        } else if(strcmp(pPropertyName, PROPERTY_KEYBOARD_ENABLED) == 0) {
            // TODO: Not supported
            CCLOG("The property '%s' is not supported!", PROPERTY_KEYBOARD_ENABLED);
            // This comes closest: ((Layer *)pNode)->setKeypadEnabled(pCheck);
        } else {
            NodeLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, ccbReader);
        }
    }
    

    最常用的ONE_BY_ONE和SwallowsTouches都没有解析,这样使用cocosbuilder编辑的那些属性还有什么用呢

    下面是修改后的解析函数:

    #define PROPERTY_DONT_TOUCH_SWALLOW "dontTouchSwallow"
    #define PROPERTY_TOUCH_ONE_BY_ONE "touchOneByOne"
    #define PROPERTY_TOUCH_ENABLED "touchEnabled"
    #define PROPERTY_ACCELEROMETER_ENABLED "accelerometerEnabled"
    #define PROPERTY_MOUSE_ENABLED "mouseEnabled"
    #define PROPERTY_KEYBOARD_ENABLED "keyboardEnabled"
    
    void LayerLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) {
        if(strcmp(pPropertyName, PROPERTY_TOUCH_ENABLED) == 0) {
    		((Layer *)pNode)->setTouchEnabled(pCheck);
    	} else if(strcmp(pPropertyName, PROPERTY_DONT_TOUCH_SWALLOW) == 0) {
    		((Layer *)pNode)->setSwallowsTouches(!pCheck);
    	} else if(strcmp(pPropertyName, PROPERTY_TOUCH_ONE_BY_ONE) == 0) {
    		((Layer *)pNode)->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
        } else if(strcmp(pPropertyName, PROPERTY_ACCELEROMETER_ENABLED) == 0) {
            ((Layer *)pNode)->setAccelerometerEnabled(pCheck);
        } else if(strcmp(pPropertyName, PROPERTY_MOUSE_ENABLED) == 0) {
            // TODO: Not supported
            CCLOG("The property '%s' is not supported!", PROPERTY_MOUSE_ENABLED);
        } else if(strcmp(pPropertyName, PROPERTY_KEYBOARD_ENABLED) == 0) {   
    		((Layer *)pNode)->setKeyboardEnabled(pCheck);
        } else {
            NodeLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, ccbReader);
        }
    }
    
  • 相关阅读:
    var、let、const的区别
    StringBuilder/StringBuffer源码阅读笔记
    Java String类源码阅读笔记
    超过三十岁就不适合写代码了?看看国外程序员怎么说
    Kubernetes笔记(五):了解Pod(容器组)
    Java安全之Javassist动态编程
    Java安全之Commons Collections1分析(三)
    Java安全之Commons Collections1分析(二)
    Java安全之Commons Collections1分析(一)
    Java安全之URLDNS链
  • 原文地址:https://www.cnblogs.com/songcf/p/4763797.html
Copyright © 2020-2023  润新知