当前位置: 首页>>代码示例>>C++>>正文


C++ Director::getEventDispatcher方法代码示例

本文整理汇总了C++中Director::getEventDispatcher方法的典型用法代码示例。如果您正苦于以下问题:C++ Director::getEventDispatcher方法的具体用法?C++ Director::getEventDispatcher怎么用?C++ Director::getEventDispatcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Director的用法示例。


在下文中一共展示了Director::getEventDispatcher方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddEventListenerSprite

void SpriteManager::AddEventListenerSprite(Sprite* sp)
{
	//添加到监听器
	Director *director = Director::getInstance();
	(director->getEventDispatcher())->addEventListenerWithSceneGraphPriority(listenerTouch->clone(), sp);
	listenerTouch->retain();
}
开发者ID:ns-xlz,项目名称:ns-xlz-cocos,代码行数:7,代码来源:SpriteManager.cpp

示例2: registerEventHandlers

void GameLayer::registerEventHandlers() {
    Director* director = Director::getInstance();
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    
    eventListener->onTouchEnded = [=](Touch* touch, Event* event){
        if (!getAcceptInput()) {
            return;
        }
        
        Vec2 position = m_tileLayer->convertTouchToNodeSpace(touch);
        for (auto iterator = m_tileLayer->getChildren().begin(); iterator != m_tileLayer->getChildren().end(); iterator++) {
            auto child = *iterator;
            GameTileView* gameTileView = dynamic_cast<GameTileView*>(child);
            if(gameTileView->getBoundingBox().containsPoint(position)) {
                if (gameTileView->getGameTile()->getCanMove()) {
                    doSelectGameTileView(gameTileView);
                }
                break;
            }
            
        }
    };
    
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    eventListener->onTouchMoved = [](Touch* touch, Event* event){};
    eventListener->onTouchCancelled = [](Touch* touch, Event* event){};
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, m_tileLayer);
}
开发者ID:newcl,项目名称:connect,代码行数:33,代码来源:game_layer.cpp

示例3:

Node::Node(void)
: _rotationX(0.0f)
, _rotationY(0.0f)
, _scaleX(1.0f)
, _scaleY(1.0f)
, _vertexZ(0.0f)
, _position(Point::ZERO)
, _skewX(0.0f)
, _skewY(0.0f)
, _anchorPointInPoints(Point::ZERO)
, _anchorPoint(Point::ZERO)
, _contentSize(Size::ZERO)
, _additionalTransformDirty(false)
, _transformDirty(true)
, _inverseDirty(true)
// children (lazy allocs)
// lazy alloc
, _ZOrder(0)
, _parent(nullptr)
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
, _tag(Node::INVALID_TAG)
// userData is always inited as nil
, _userData(nullptr)
, _userObject(nullptr)
, _shaderProgram(nullptr)
, _orderOfArrival(0)
, _running(false)
, _visible(true)
, _ignoreAnchorPointForPosition(false)
, _reorderChildDirty(false)
, _isTransitionFinished(false)
, _updateScriptHandler(0)
, _componentContainer(nullptr)
#if CC_USE_PHYSICS
, _physicsBody(nullptr)
#endif
, _displayedOpacity(255)
, _realOpacity(255)
, _displayedColor(Color3B::WHITE)
, _realColor(Color3B::WHITE)
, _cascadeColorEnabled(false)
, _cascadeOpacityEnabled(false)
{
    // set default scheduler and actionManager
    Director *director = Director::getInstance();
    _actionManager = director->getActionManager();
    _actionManager->retain();
    _scheduler = director->getScheduler();
    _scheduler->retain();
    _eventDispatcher = director->getEventDispatcher();
    _eventDispatcher->retain();
    
    ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
    _scriptType = engine != nullptr ? engine->getScriptType() : kScriptTypeNone;

    kmMat4Identity(&_transform);
    kmMat4Identity(&_inverse);
    kmMat4Identity(&_additionalTransform);
}
开发者ID:ccppluagopy,项目名称:cocos3.0_extention,代码行数:59,代码来源:CCNode.cpp

示例4: registerHandler

void GameLayer::registerHandler(Node* node, std::function<void(Touch*, Event*)> onTouchEnded) {
    Director* director = Director::getInstance();
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    eventListener->onTouchEnded = onTouchEnded;
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, node);
}
开发者ID:newcl,项目名称:connect,代码行数:13,代码来源:game_layer.cpp

示例5: registerEventListener

void Hero::registerEventListener()
{
	Director *director = Director::getInstance();
	EventDispatcher *eventDispatcher = director->getEventDispatcher();

	EventListenerCustom *customEventListener = EventListenerCustom::create("slide", CC_CALLBACK_1(Hero::onSlide, this));
	eventDispatcher->addEventListenerWithFixedPriority(customEventListener, 1);

	customEventListener = EventListenerCustom::create("jump", CC_CALLBACK_1(Hero::onJump, this));
	eventDispatcher->addEventListenerWithFixedPriority(customEventListener, 1);

	customEventListener = EventListenerCustom::create("right", CC_CALLBACK_1(Hero::onRight, this));
	eventDispatcher->addEventListenerWithFixedPriority(customEventListener, 1);

	customEventListener = EventListenerCustom::create("left", CC_CALLBACK_1(Hero::onLeft, this));
	eventDispatcher->addEventListenerWithFixedPriority(customEventListener, 1);
}
开发者ID:lmk378,项目名称:ProtoType,代码行数:17,代码来源:Hero.cpp

示例6: init

bool IdleLayer::init() {
    if(!LayerColor::init()) {
        return false;
    }
    
    Director* director = Director::getInstance();
    Vec2 visibleOrigin = director->getVisibleOrigin();
    Size visibleSize = director->getVisibleSize();
    
    setContentSize(visibleSize);
    
    GameLayer* gameLayer = GameLayer::create(IDLE);
    gameLayer->getUiLayer()->setVisible(false);
    addChild(gameLayer);
    
//    gameLayer->setColor(Color3B::RED);
    
    Widget* idleForeground = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/idle_foreground.json");
    Node* background = idleForeground->getChildByName("background");
    background->setContentSize(visibleSize);
    
    Text* touchToStart = dynamic_cast<Text*>(idleForeground->getChildByName("touchToStart"));
    touchToStart->setString(LANG->getLang("touch_to_start"));
    touchToStart->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    touchToStart->runAction(RepeatForever::create(Blink::create(1, 1)));

    addChild(idleForeground);
    
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    eventListener->onTouchEnded = [=](Touch* touch, Event* event){
        auto scene = MainMenuLayer::createScene();
        director->replaceScene(scene);
    };
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, touchToStart);
    
    CallFunc* connectAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty() && gameLayer->getAcceptInput()) {
            auto path = game->getRandomPath();
            if(path) {
                auto front = path->getPath().front();
                auto back = path->getPath().back();
                gameLayer->doConnect(front->getX(), front->getY(), back->getX(), back->getY());
            }

        }
    });
    
    CallFunc* shuffleAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty()) {
            if (rand()%10 == 0) {
                gameLayer->doShuffle();
            }
        }
    });
    
    runAction(RepeatForever::create(Sequence::create(DelayTime::create(1.5), connectAction, shuffleAction, NULL)));
    
    return true;
}
开发者ID:newcl,项目名称:connect,代码行数:68,代码来源:idle_layer.cpp


注:本文中的Director::getEventDispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。