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

前端之家收集整理的这篇文章主要介绍了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) {
    @H_403_25@if(strcmp(pPropertyName,PROPERTY_TOUCH_ENABLED) == 0) {
        ((Layer *)pNode)->setTouchEnabled(pCheck);
    } @H_403_25@else @H_403_25@if(strcmp(pPropertyName,PROPERTY_ACCELEROMETER_ENABLED) == 0) {
        ((Layer *)pNode)->setAccelerometerEnabled(pCheck);
    } @H_403_25@else @H_403_25@if(strcmp(pPropertyName,PROPERTY_MOUSE_ENABLED) == 0) {
        // TODO: Not supported
        CCLOG("The property '%s' is not supported!",PROPERTY_MOUSE_ENABLED);
    } @H_403_25@else @H_403_25@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);
    } @H_403_25@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,PROPERTY_DONT_TOUCH_SWALLOW) == 0) {
        ((Layer *)pNode)->setSwallowsTouches(!pCheck);
    } @H_403_25@else @H_403_25@if(strcmp(pPropertyName,PROPERTY_TOUCH_ONE_BY_ONE) == 0) {
        ((Layer *)pNode)->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
    } @H_403_25@else @H_403_25@if(strcmp(pPropertyName,PROPERTY_KEYBOARD_ENABLED) == 0) {   
        ((Layer *)pNode)->setKeyboardEnabled(pCheck);
    } @H_403_25@else {
        NodeLoader::onHandlePropTypeCheck(pNode,ccbReader);
    }
}
原文链接:https://www.f2er.com/cocos2dx/341286.html

猜你在找的Cocos2d-x相关文章