예제 #1
0
void HelloWorld::onEnter()
{
    Layer::onEnter();

    auto dispatcher = Director::getInstance()->getEventDispatcher();

    auto keyListener = EventListenerKeyboard::create();
    keyListener->onKeyPressed = CC_CALLBACK_2(HelloWorld::onKeyPressed, this);
    keyListener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);
    dispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);

    auto mouseListener = EventListenerMouse::create();
    mouseListener->onMouseMove = CC_CALLBACK_1(HelloWorld::onMouseMove, this);
    mouseListener->onMouseUp = CC_CALLBACK_1(HelloWorld::onMouseUp, this);
    mouseListener->onMouseDown = CC_CALLBACK_1(HelloWorld::onMouseDown, this);
    mouseListener->onMouseScroll = CC_CALLBACK_1(HelloWorld::onMouseScroll, this);
    dispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);

    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

#ifdef MOUSE_DOUBLE_LISTEN_FUDGE
    mouseDownFudge = false;
    mouseUpFudge = false;
    mouseMoveFudge = false;
    mouseScrollFudge = false;
#endif
    isMouseDown[0] = false;
    isMouseDown[1] = false;
    isMouseDown[2] = false;
    typeKeyCandidates.clear();
}
예제 #2
0
bool StageLayer::init()
{
	LayerColor* shadow = LayerColor::create(Color4B(0,0,0,128));
	
	shadow->setPosition(-540,-960);

	this->addChild(shadow,-2);

	bg = Sprite::create("dialog_background.png");

	bg->setPositionY(100);

	this->addChild(bg);

	auto title = Sprite::create("situ_title.png");

	title->setPositionY(350);

	this->addChild(title);

	list = MyListView::create();

	list->stagelayer = this;

	for(int i=0;i<20;i++)
	{
		char str[100];

		sprintf(str,"scoll%d",i+1);

		list->add_option(StringData::getInstance()->get_string(str));
	}

	list->page = -1;

	this->addChild(list);

	back_btn = Sprite::create("chess_go_back.png");
	
	back_btn->setPosition(-2600,350);

	this->addChild(back_btn);

	this->setPosition(540,960);
	
	auto dispatcher = Director::getInstance()->getEventDispatcher();
	auto touchListener = EventListenerTouchOneByOne::create();
	touchListener->setSwallowTouches(true);
	touchListener->onTouchBegan = CC_CALLBACK_2(StageLayer::onTouchBegan,this);
	touchListener->onTouchMoved = CC_CALLBACK_2(StageLayer::onTouchMoved,this);
	touchListener->onTouchEnded = CC_CALLBACK_2(StageLayer::onTouchEnded, this);
	dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
	
	auto keyListener = EventListenerKeyboard::create();
	keyListener->onKeyReleased = CC_CALLBACK_2(StageLayer::onKeyReleased, this);
	dispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);

	return true; 
}
예제 #3
0
bool Control::init()
{
    if (Layer::init())
    {
        // Initialise instance variables
        _state=Control::State::NORMAL;
        setEnabled(true);
        setSelected(false);
        setHighlighted(false);

        auto dispatcher = Director::getInstance()->getEventDispatcher();
        auto touchListener = EventListenerTouchOneByOne::create();
        touchListener->setSwallowTouches(true);
        touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this);
        touchListener->onTouchMoved = CC_CALLBACK_2(Control::onTouchMoved, this);
        touchListener->onTouchEnded = CC_CALLBACK_2(Control::onTouchEnded, this);
        touchListener->onTouchCancelled = CC_CALLBACK_2(Control::onTouchCancelled, this);
        
        dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
        
        return true;
    }
    else
    {
        return false;
    }
}
예제 #4
0
void Transmigration::onEnter()
{
    Layer::onEnter();
    
    Size size = Director::getInstance()->getVisibleSize();
    setContentSize(size);
    ui::Helper::doLayout(this);
    
    _updateLocalization();

    auto menu = getChildByName("menu");
    auto yes = menu->getChildByName<ui::Button*>("yesButton");
    yes->addTouchEventListener(CC_CALLBACK_2(Transmigration::_pushYesButton, this));
    auto no = menu->getChildByName<ui::Button*>("noButton");
    no->addTouchEventListener(CC_CALLBACK_2(Transmigration::_pushNoButton, this));

    _getDiamondNum = menu->getChildByName<ui::TextBMFont*>("getDiamondNum");
    _getDiamondNum->setString(StringUtils::format("x %d", WorldManager::getInstance()->getDiamondNumInTransmigration()));
    
    // タッチイベントの設定
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(Transmigration::onTouchBegan, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #5
0
파일: GameScene.cpp 프로젝트: caigehui/rush
bool GameScene::init() {
    
    if (!Layer::init()) {
        return false;
    }
    //加入背景
    BackgroundManager::getInstance()->addGameEntity(this);
    schedule([this](float delay){
        BackgroundManager::getInstance()->update(delay,this);
    }, "gameRun");
    BackgroundManager::getInstance()->stopAllActions();
    //加入Hero
    HeroManager::getInstance()->addHero(this);
    
    // 获取事件分发器
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    // 创建单点触摸监听器
    auto listener = EventListenerTouchOneByOne::create();
    // 让监听器绑定事件处理函数
    listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan,this);
    listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved,this);
    listener->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded,this);
    // 将事件监听器添加到事件调度器
    dispatcher->addEventListenerWithSceneGraphPriority(listener,this);
    
    return true;
}
예제 #6
0
void AniTest::runThisTest()
{
    Director::getInstance()->replaceScene(this);
    initAni();
    
    // Add Touch Listener
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = [=](Touch* touch, Event* event){
        
        m_armature->stopAllActions();
        Point touchPoint = touch->getLocation();
        Point heroPoint = m_armature->getPosition();
        
        Point deltaPoint = touchPoint - heroPoint;
        
        float time = sqrt(deltaPoint.x * deltaPoint.x + deltaPoint.y * deltaPoint.y) * 0.002;
        ActionInterval *action = cocos2d::MoveBy::create(time, deltaPoint);
        FiniteTimeAction *actionCallBack = CallFuncN::create(CC_CALLBACK_1(AniTest::setNormal, this));
        m_armature->runAction(Sequence::create(action, actionCallBack, NULL));
        setRun();
        
        if(deltaPoint.x < 0){
            m_armature->setRotation3D(Vertex3F(0, 180, 0));
        }else
        {
            m_armature->setRotation3D(Vertex3F(0, 0, 0));
        }
        return true;
    };

    
    dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
}
예제 #7
0
bool PauseScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

    auto center = Point(Director::getInstance()->getVisibleSize()) / 2;
    auto blkout = Sprite::create("img/game_popup_blkout.png");
    blkout->setPosition(center);
    auto popup = Sprite::create("img/game_popup_bg.png");
    popup->setPosition(center);
    addChild(blkout);
    addChild(popup);

    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = [](Touch* touch, Event* event) { return true; };
    listener->onTouchMoved = [](Touch* touch, Event* event) {};
    listener->onTouchEnded = [](Touch* touch, Event* event) {
        Director::getInstance()->popScene();
    };
    listener->onTouchCancelled = [](Touch* touch, Event* event) {};
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    return true;
}
예제 #8
0
// 添加碰撞检测
void GameScene::addContactEvent()
{
	auto dispatcher = this->getEventDispatcher();
	auto listener = EventListenerPhysicsContact::create();
	listener->onContactBegin = CC_CALLBACK_1(GameScene::onContactBegin, this);
	dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #9
0
FrameworkScene::FrameworkScene()
    : bTouchHappened_(false)
    , active_button_(nullptr)

    , touch_x_(0)
    , touch_y_(0)

    , bReleaseHappened_(false)
    , bWasPressed_(false)

    , higher_z_order_(-1)
    , curr_target_z_order_(-1)

    , bButtonClick_(false)

    , delayControlEnabled(true)
    , sumDelta(0)

{
    vec_buttons_.clear();

    initDelayControl();

    auto listener = EventListenerTouchOneByOne::create();

    listener->onTouchBegan = CC_CALLBACK_2(FrameworkScene::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(FrameworkScene::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(FrameworkScene::onTouchEnded, this);
    listener->onTouchCancelled = CC_CALLBACK_2(FrameworkScene::onTouchCancelled, this);

    auto dispatcher = this->getEventDispatcher();
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    this->scheduleUpdate();
}
예제 #10
0
bool WelcomeScene::init()
{
	if (!Scene::init())
	{
		return false;
	}
	mNextScene = MainScene::create();
	mNextScene->retain();
	for (int i = 0; i < NUMBG; ++i)
	{
		mTextures[i] = TextureCache::getInstance()->addImage("uiComponent/welcomeImage" + std::string{ (char)('0' + i) } +".png");
	}
	//init
	mWelcomeBg = Sprite::createWithTexture(mTextures[0]);
	mWelcomeBg->setPosition(
		Director::getInstance()->getWinSize().width / 2,
		Director::getInstance()->getWinSize().height / 2
		);
	mWelcomeBg->setOpacity(0);
	addChild(mWelcomeBg);
	auto fadein = FadeIn::create(0.3);
	auto delay = DelayTime::create(1);
	auto fadeout = FadeOut::create(0.7);
	auto jumpFunc = CallFunc::create(CC_CALLBACK_0(WelcomeScene::jumpToNextScene, this));
	auto sequence = Sequence::create(fadein, delay, fadeout, NULL);
	auto sequenceR = Sequence::create(
		DelayTime::create(0.5),
		sequence,
		CallFunc::create(CC_CALLBACK_0(WelcomeScene::changeTexture, this,mTextures[1])),
		sequence,
		jumpFunc,
		NULL
		);
	//actions
	//final action
	mWelcomeBg->runAction(sequenceR);

	mKeyboardListener = EventListenerKeyboard::create();
	mKeyboardListener->onKeyReleased = CC_CALLBACK_2(WelcomeScene::onKeyReleased, this);
	mTouchListener = EventListenerTouchOneByOne::create();
	mTouchListener->onTouchBegan = [](Touch * touch, Event * event)->bool{return true; };
	mTouchListener->onTouchEnded = CC_CALLBACK_2(WelcomeScene::onTouchEnded, this);
	auto dispatcher = Director::getInstance()->getEventDispatcher();
	dispatcher->addEventListenerWithSceneGraphPriority(mTouchListener, this);
	dispatcher->addEventListenerWithSceneGraphPriority(mKeyboardListener, this);
	return true;
}
예제 #11
0
// 添加触摸事件
void GameScene::addTouchEvent()
{
	auto dispatcher = this->getEventDispatcher();
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);
	dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #12
0
void Niwatori::initEventListener()
{
    auto eventDispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(Niwatori::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(Niwatori::onTouchEnded, this);
    eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #13
0
void Soldier::addTouch()
{
	auto dispatcher = this->getEventDispatcher();
	listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(Soldier::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(Soldier::onTouchMoved, this);
	listener->onTouchEnded = CC_CALLBACK_2(Soldier::onTouchEnded, this);
	dispatcher->addEventListenerWithSceneGraphPriority(listener, this->soldierSprite);
}
예제 #14
0
void MaskShaderEffect::enableTouchCtrl(bool enable)
{
	if (enable) {
		auto dispatcher = Director::getInstance()->getEventDispatcher();
		auto listener = EventListenerTouchOneByOne ::create();
		listener->onTouchBegan = CC_CALLBACK_2(MaskShaderEffect::onTouchBegan, this);
		dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	}
}
void CustomEventDispatchingPerfTest::generateTestFunctions()
{
    TestFunction testFunctions[] = {
        { "custom-scenegraph",    [=](){
            auto dispatcher = Director::getInstance()->getEventDispatcher();
            if (_quantityOfNodes != _lastRenderedCount)
            {
                auto listener = EventListenerCustom::create("custom_event_test_scenegraph", [](EventCustom* event){});
                
                // Create new nodes listen to custom event
                for (int i = 0; i < this->_quantityOfNodes; ++i)
                {
                    auto node = Node::create();
                    node->setTag(1000 + i);
                    this->addChild(node);
                    this->_nodes.push_back(node);
                    dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node);
                }
                
                _lastRenderedCount = _quantityOfNodes;
            }
            
            EventCustom event("custom_event_test_scenegraph");
            
            CC_PROFILER_START(this->profilerName());
            dispatcher->dispatchEvent(&event);
            CC_PROFILER_STOP(this->profilerName());
        } } ,
        { "custom-fixed",    [=](){
            auto dispatcher = Director::getInstance()->getEventDispatcher();
            if (_quantityOfNodes != _lastRenderedCount)
            {
                auto listener = EventListenerCustom::create("custom_event_test_fixed", [](EventCustom* event){});
                
                for (int i = 0; i < this->_quantityOfNodes; ++i)
                {
                    auto l = listener->clone();
                    this->_fixedPriorityListeners.push_back(l);
                    dispatcher->addEventListenerWithFixedPriority(l, i+1);
                }
                
                _lastRenderedCount = _quantityOfNodes;
            }
            
            EventCustom event("custom_event_test_fixed");
            
            CC_PROFILER_START(this->profilerName());
            dispatcher->dispatchEvent(&event);
            CC_PROFILER_STOP(this->profilerName());
        } } ,
    };
    
    for (const auto& func : testFunctions)
    {
        _testFunctions.push_back(func);
    }
}
예제 #16
0
bool OptionLayer::init(){
    if(Layer::init()){
        auto dispatcher = Director::getInstance()->getEventDispatcher();
        auto listener = EventListenerTouchAllAtOnce::create();
        listener->onTouchesBegan = CC_CALLBACK_2(OptionLayer::onTouchesBegan,this);
        dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
        return true;
    }
    else return false;
};
void CharacterDiceSprite::_setupTouchListener() {
  auto touchListener = EventListenerTouchOneByOne::create();
  touchListener->setSwallowTouches(true);
  touchListener->onTouchBegan = CC_CALLBACK_2(CharacterDiceSprite::_onTouchBegan, this);
  touchListener->onTouchMoved = CC_CALLBACK_2(CharacterDiceSprite::_onTouchMoved, this);
  touchListener->onTouchEnded = CC_CALLBACK_2(CharacterDiceSprite::_onTouchEnded, this);
  
  auto dispatcher = Director::getInstance()->getEventDispatcher();
  dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
}
예제 #18
0
GameObjHero::GameObjHero()
{
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(GameObjHero::onTouchBegan,this);
    listener->onTouchMoved = CC_CALLBACK_2(GameObjHero::onTouchMoved,this);
    listener->onTouchEnded = CC_CALLBACK_2(GameObjHero::onTouchEnded,this);
    listener->setSwallowTouches(true);//不向下传递触摸
    dispatcher->addEventListenerWithSceneGraphPriority(listener,this);
}
예제 #19
0
void StageSelect::onEnterTransitionDidFinish()
{
    Layer::onEnterTransitionDidFinish();
	L("StageSelect::onEnterTransitionDidFinish");
    
	auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher();
    auto listener = cocos2d::EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(StageSelect::onTouchBegan, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #20
0
void TouchListener::KeyBoard(KeyInputEvent::KeyInputPressed pressed,
                                 KeyInputEvent::KeyInputReleased released,
                                 Node* target){
    auto listener = EventListenerKeyboard::create();
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    
    listener->onKeyPressed = pressed;
    listener->onKeyReleased = released;
    
    dispatcher->addEventListenerWithSceneGraphPriority(listener, target);
}
예제 #21
0
void TapInfo::onEnter()
{
    LayerColor::onEnter();
    this->setOpacity(100);
    
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(TapInfo::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(TapInfo::onTouchEnd, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #22
0
void BattleFieldUI::showVictoryUI()
{//show the victory UI when win
	//diable AI

	//color layer
	auto layer = LayerColor::create(Color4B(10, 10, 10, 150));
	layer->ignoreAnchorPointForPosition(false);
	layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0));
	//add victory
	auto victory = Sprite::createWithSpriteFrameName("victory.png");
	victory->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3));
	victory->setScale(0.1);
	layer->addChild(victory, 1);
	layer->setGlobalZOrder(100);
	victory->setGlobalZOrder(100);
	//victory runaction
	auto action = EaseElasticOut::create(ScaleTo::create(1.5, 1));
	victory->runAction(action);

	auto listener = EventListenerTouchOneByOne::create();
	//touch event
	listener->onTouchBegan = [](Touch*, Event*)
	{
		return true;
	};
	listener->onTouchEnded = [this](Touch*, Event*)
	{
		//clear GlobalVaribals
		HeroPool.clear();
		DragonPool.clear();
		SlimePool.clear();
		RatPool.clear();
		BossPool.clear();
		PigletPool.clear();

		HeroManager.clear();
		MonsterManager.clear();
		GameMaster::reset();

		//stop schedule
		currentLayer->unscheduleUpdate();
		Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer);
		//stop sound
		experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM);
		//replace scene
		Director::getInstance()->replaceScene(ChooseRoleScene::createScene());
	};
	victory->setCameraMask(2);
	auto eventDispatcher = layer->getEventDispatcher();
	eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer);

	addChild(layer);
}
예제 #23
0
//不添加这个虚函数,在init中设置
// setTouchEnabled(true);
// setTouchMode(kCCTouchesOneByOne);
//还是能用的
void SceneGame::onEnter()
{
	Layer::onEnter();

	auto listener = EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);

	listener->onTouchBegan = CC_CALLBACK_2(SceneGame::onTouchBegan, this);

	auto dispatcher = Director::getInstance()->getEventDispatcher();

	dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
예제 #24
0
void GameFatherLayer::onEnter()
{
	Layer::onEnter();
	auto listener=EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);
	listener->onTouchBegan=CC_CALLBACK_2(GameFatherLayer::onTouchBegan,this);
	listener->onTouchMoved=CC_CALLBACK_2(GameFatherLayer::onTouchMoved,this);
	listener->onTouchEnded=CC_CALLBACK_2(GameFatherLayer::onTouchEnded,this);

	auto eventdispatcher=Director::getInstance()->getEventDispatcher();
	eventdispatcher->addEventListenerWithSceneGraphPriority(listener,getChildByTag(mROLE_TAG));

}
예제 #25
0
void HeroSprite::onEnterTransitionDidFinish() {
	Sprite::onEnterTransitionDidFinish();

	auto eventDispatcher = Director::getInstance()->getEventDispatcher();

    auto keyListener = EventListenerKeyboard::create();
    keyListener->onKeyPressed = CC_CALLBACK_2(HeroSprite::onKeyPressed, this);
    keyListener->onKeyReleased = CC_CALLBACK_2(HeroSprite::onKeyReleased, this);
    eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);

    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = CC_CALLBACK_2(HeroSprite::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(HeroSprite::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(HeroSprite::onTouchEnded, this);
    eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

	auto contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(HeroSprite::onContactBegin, this);
	contactListener->onContactPreSolve = CC_CALLBACK_2(HeroSprite::onContactPreSolve, this);
	contactListener->onContactPostSolve = CC_CALLBACK_2(HeroSprite::onContactPostSolve, this);
	eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);
}
void AnalogStick::startStick()
{
    auto stick = (Sprite*)this->getChildByTag((int)TagForStickPart::tag_stick);
    stick->setVisible(true);
    auto outer = (Sprite*)this->getChildByTag((int)TagForStickPart::tag_outer);
    outer->setVisible(true);

    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan     = CC_CALLBACK_2(AnalogStick::onTouchBegan, this);
    touchListener->onTouchMoved     = CC_CALLBACK_2(AnalogStick::onTouchMoved, this);
    touchListener->onTouchEnded     = CC_CALLBACK_2(AnalogStick::onTouchEnded, this);
    dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
}
예제 #27
0
bool SGSkirmishInfo::init()
{
  if (!Layer::init()) {
    return false;
  }
  // add touch event handler:
  auto dispatcher = Director::getInstance()->getEventDispatcher();
  __event_listener = EventListenerTouchOneByOne::create();
  __event_listener->onTouchBegan = CC_CALLBACK_2(SGSkirmishInfo::onTouchBegin, this);
  __event_listener->setSwallowTouches(true);
  dispatcher->addEventListenerWithSceneGraphPriority(__event_listener,this);
  return true;
  return true;
}
예제 #28
0
	bool GameScene::init()
	{
		if( !CCLayer::init() )
			return false;

#define KEY_MAP(name) EventKeyboard::KeyCode::KEY_##name
		mKeyMap[KEY_MAP(LEFT_SHIFT)] = Key::Player1_Scratch;
		mKeyMap[KEY_MAP(Z)] = Key::Player1_1;
		mKeyMap[KEY_MAP(S)] = Key::Player1_2;
		mKeyMap[KEY_MAP(X)] = Key::Player1_3;
		mKeyMap[KEY_MAP(D)] = Key::Player1_4;
		mKeyMap[KEY_MAP(C)] = Key::Player1_5;
		mKeyMap[KEY_MAP(F)] = Key::Player1_6;
		mKeyMap[KEY_MAP(V)] = Key::Player1_7;

		mKeyMap[KEY_MAP(RIGHT_SHIFT)] = Key::Player2_Scratch;
		mKeyMap[KEY_MAP(M)] = Key::Player2_1;
		mKeyMap[KEY_MAP(K)] = Key::Player2_2;
		mKeyMap[KEY_MAP(COMMA)] = Key::Player2_3;
		mKeyMap[KEY_MAP(L)] = Key::Player2_4;
		mKeyMap[KEY_MAP(PERIOD)] = Key::Player2_5;
		mKeyMap[KEY_MAP(SEMICOLON)] = Key::Player2_6;
		mKeyMap[KEY_MAP(SLASH)] = Key::Player2_7;

		mKeyMap[KEY_MAP(F3)] = Key::SpeedDown;
		mKeyMap[KEY_MAP(F4)] = Key::SpeedUp;
#undef KEY_MAP

		for(auto it = mKeyMap.begin(); it != mKeyMap.end(); it++)
		{
			mKeyState[it->second] = Key::KEY_UP;
		}

		scheduleOnce(schedule_selector(GameScene::start), .0f);
		scheduleUpdate();

		auto keyListener = EventListenerKeyboard::create();
		keyListener->onKeyPressed = CC_CALLBACK_2(GameScene::onKeyDown, this);
		keyListener->onKeyReleased = CC_CALLBACK_2(GameScene::onKeyUp, this);

		auto dispatcher = Director::getInstance()->getEventDispatcher();

		dispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
		dispatcher->addCustomEventListener(Event::BpmEvent::CHANGED, CC_CALLBACK_1(GameScene::onBpmChanged, this));
		dispatcher->addCustomEventListener(Event::JudgeEvent::JUDGE, CC_CALLBACK_1(GameScene::onJudge, this));

		return true;
	}
예제 #29
0
bool MainLayer::init()
{
	if (!Layer::init())
		return false;
	_angle = 0.0f;

	auto dispatcher = Director::getInstance()->getEventDispatcher();
	auto listener = EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);
	listener->onTouchBegan = CC_CALLBACK_2(MainLayer::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(MainLayer::onTouchMoved, this);
	listener->onTouchEnded = CC_CALLBACK_2(MainLayer::onTouchEnded, this);
	dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	initLayer();
	return true;
}
예제 #30
0
bool TouchTest::init()
{
	if (!Layer::init())
	{
		return false;
	}
	log("++++++++++++++");
	auto dispatcher = Director::getInstance()->getEventDispatcher();
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(TouchTest::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(TouchTest::onTouchMoved, this);
	listener->onTouchEnded = CC_CALLBACK_2(TouchTest::onTouchEnded, this);
	listener->setSwallowTouches(true);//不向下传递触摸  
	dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
	return true;
}