本文整理汇总了C++中EventListenerTouchOneByOne类的典型用法代码示例。如果您正苦于以下问题:C++ EventListenerTouchOneByOne类的具体用法?C++ EventListenerTouchOneByOne怎么用?C++ EventListenerTouchOneByOne使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventListenerTouchOneByOne类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
// on "init" you need to initialize your instance
bool Dialog::init()
{
//////////////////////////////
// 1. super init first
if ( !LayerColor::initWithColor(Color4B(0, 0, 0, 127)) ) {
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
m_dialog = Layer::create();
this->addChild(m_dialog);
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [] (Touch* touch, Event* e) {
return true;
};
listener->setSwallowTouches(true);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
clearLayout();
return true;
}
示例2: init
KDbool SampleLayer::init ( KDvoid )
{
if ( !Layer::init ( ) )
{
return KD_FALSE;
}
m_nMaxJump = 0;
EventListenerTouchOneByOne* pListner = EventListenerTouchOneByOne::create ( );
pListner->setSwallowTouches ( KD_TRUE );
pListner->onTouchBegan = CC_CALLBACK_2 ( SampleLayer::onTouchBegan, this );
m_pEventDispatcher->addEventListenerWithSceneGraphPriority ( pListner, this );
SimpleAudioEngine::getInstance ( )->playBackgroundMusic ( "bgm_main.mp3", KD_TRUE );
this->initBox2DWorld ( );
this->initItem ( );
this->addLevelBoundaries ( );
this->addBackground ( );
this->addFloor ( );
this->addCharacter ( );
this->schedule ( schedule_selector ( SampleLayer::step ) );
//this->schedule ( schedule_selector ( SampleLayer::collisionCheck ), 0.2f );
this->setItem ( );
return KD_TRUE;
}
示例3: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create( );
listener->setSwallowTouches( true );
listener->onTouchBegan = CC_CALLBACK_2( HelloWorld::onTouchBegan, this );
listener->onTouchMoved = CC_CALLBACK_2( HelloWorld::onTouchMoved, this );
listener->onTouchEnded = CC_CALLBACK_2( HelloWorld::onTouchEnded, this );
Director::getInstance( )->getEventDispatcher( )->addEventListenerWithSceneGraphPriority( listener, this );
sprite1 = Sprite::create( "HelloWorld.png" );
sprite2 = Sprite::create( "HelloWorld.png" );
sprite1->setPosition( Vec2( 100, 200 ) );
sprite2->setPosition( Vec2( 400, 200 ) );
sprite1->setScale( 0.1 );
this->addChild( sprite1 );
this->addChild( sprite2 );
return true;
}
示例4: 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);
}
示例5: getInstrumentChinese
void PianoLayer::onTouchEnded(Touch* touch, Event* event)
{
pauseFlag = true;
slider->setEnabled(false);
//获取可见区域尺寸
Size visibleSize = Director::getInstance()->getVisibleSize();
selection->setTexture(pic_RESOURE_PATH + "back.png");
underside = Sprite::create(pic_RESOURE_PATH + "blackBackGround.png");
underside->setPosition(visibleSize.width/2, visibleSize.height/2);
this->addChild(underside, 10);
menuBack = Sprite::create(pic_RESOURE_PATH + "kuang.png");
menuBack->setPosition(visibleSize.width/2, visibleSize.height/2);
menuSize = menuBack->getContentSize();
underside->addChild(menuBack, 5);
for(int i=1, row=0, col=0; i<9; i++)
{
Sprite* selects = Sprite::create(pic_RESOURE_PATH + "instrument.png");
sSize = selects->getContentSize();
//-----------------------------------------------------
string instrument = getInstrumentChinese(i);
Label* labels = Label::createWithTTF(instrument, fonts_RESOURE_PATH + "FZKATJW.ttf", 40, Size::ZERO, TextHAlignment::LEFT, TextVAlignment::TOP);
labels->setColor(Color3B::BLACK);
selects->addChild(labels, 2);
selects->setScale(0.9);
labels->setPosition(Point(sSize.width/2 , sSize.height/2));
selects->setPosition(Point(220 + 260*col, 300 - 80*row));
if(i%2 == 0)
{
row++;
col--;
}else
{
col++;
}
string number = StringUtils::format("%d", i);
select.insert(pair<string,Sprite*>(number, selects));
}
map<string,Sprite*>::iterator iter;
for(iter = select.begin(); iter!=select.end(); iter++)
{
int number = atoi(iter->first.c_str());
if(number == instrumentNumber)
{
iter->second->setTexture(pic_RESOURE_PATH + "yellow.png");
}
menuBack->addChild(iter->second, 1);
}
//创建单点触摸监听
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
//设置下传触摸
listener->setSwallowTouches(false);
//开始触摸时回调onTouchBegan方法
listener->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchBeganInstrument, this);
listener->onTouchEnded = CC_CALLBACK_2(PianoLayer::onTouchEndedInstrument, this);
//添加到监听器
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, underside);
}
示例6: init
bool MyEditText::init(const std::string& placehold, const std::string& fontName, float fontSize, const Size& constraintSize) {
if(!Node::init())
return false;
this->setCascadeOpacityEnabled(true);
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
//touch
EventListenerTouchOneByOne *touchEventListener = EventListenerTouchOneByOne::create();
touchEventListener->setSwallowTouches(true);
touchEventListener->onTouchBegan = [=](Touch* touch, Event* event)->bool{
if(event->getCurrentTarget() == this) {
Vec2 touchLocation = touch->getLocation();
touchLocation = this->convertToNodeSpace(touchLocation);
Rect rect;
rect.size = _contentSize;
if(rect.containsPoint(touchLocation)) {
if(m_isEnable || m_isAttachWithIME)
return true;
} else {
if(m_isAttachWithIME) {
m_textField->detachWithIME();
return true;
}
}
}
return false;
};
touchEventListener->onTouchEnded = [=](Touch* touch, Event* event) {
if(m_isEnable && event->getCurrentTarget() == this) {
m_textField->attachWithIME();
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchEventListener, this);
//textField
m_textField = MyTextField::create(placehold, fontName, fontSize);
m_textField->setContentSize(constraintSize);
m_textField->setPosition(Vec2::ZERO);
m_textField->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
m_textField->setVerticalAlignment(TextVAlignment::TOP);
m_textField->setHorizontalAlignment(TextHAlignment::LEFT);
m_textField->setOrientation(TextFieldOrientation::HORIZONTAL);
//限制宽度
m_textField->setConstraintSize(constraintSize);
m_textField->setIsUseContraintSize(true);
this->addChild(m_textField);
m_textField->setDelegate(this);
m_isAttachWithIME = false;
m_isCursorDirty = false;
m_isEnable = true;
return true;
}
示例7: setTouchEnabled
void GamePlayScene::initTouchListener() {
setTouchEnabled(true);
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(GamePlayScene::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(GamePlayScene::onTouchEnded, this);
getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1);
}
示例8: setEventHadlers
void ChatScene::setEventHadlers()
{
EventDispatcher* pDispatcher = Director::getInstance()->getEventDispatcher();
EventListenerTouchOneByOne* pEventListener = EventListenerTouchOneByOne::create();
pEventListener->setSwallowTouches(true);
pEventListener->onTouchBegan = CC_CALLBACK_2(ChatScene::onTouchBegan, this);
pEventListener->onTouchMoved = CC_CALLBACK_2(ChatScene::onTouchMoved, this);
pEventListener->onTouchEnded = CC_CALLBACK_2(ChatScene::onTouchEnded, this);
pDispatcher->addEventListenerWithSceneGraphPriority(pEventListener, this);
}
示例9: CreateListener
void GameScreen::CreateListener()
{
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(GameScreen::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(GameScreen::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(GameScreen::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(GameScreen::onTouchCancelled, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
}
示例10: 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);
}
示例11: onCreateTouchListen
EventListenerTouchOneByOne* TestTouch::onCreateTouchListen()
{
EventListenerTouchOneByOne* touchEvent = EventListenerTouchOneByOne::create();
// 当设置为 true, 则在 onTouchBegan 方法发返回 'true' 将会吃掉触控事件, 防止其他监听器使用这个事件.
touchEvent->setSwallowTouches(true);
// 高端的用法,c11中可以直接定义函数回调
// touchEvent->onTouchBegan = [](Touch* touch, Event* event){return true; };
touchEvent->onTouchBegan = CC_CALLBACK_2(TestTouch::onMyTouchBegan, this);
touchEvent->onTouchEnded = CC_CALLBACK_2(TestTouch::onMyTouchEnded, this);
touchEvent->onTouchMoved = CC_CALLBACK_2(TestTouch::onMyTouchMoved, this);
touchEvent->onTouchCancelled = CC_CALLBACK_2(TestTouch::onMyTouchCancelled, this);
return touchEvent;
}
示例12: addChild
bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add backgroundLayer
Sprite* background = Sprite::create("background.jpg");
background->setPosition(visibleSize.width / 2, visibleSize.height / 2);
addChild(background);
// create a fish sprite and run animation
// add the fish sprite to the fishLayer
fishLayer = Layer::create();
m_fish = Sprite::createWithSpriteFrameName("fish13_01.png");
Animate* fishAnimate = Animate::create(AnimationCache::getInstance()->getAnimation("fishAnimation"));
m_fish->runAction(RepeatForever::create(fishAnimate));
m_fish->setPosition(visibleSize.width / 2, visibleSize.height / 2);
fishLayer->addChild(m_fish);
// create a weapon sprite.
// add the weapon sprite to the weaponLayer
weaponLayer = Layer::create();
m_weapon = Sprite::create("CloseSelected.png");
m_weapon->setPosition(visibleSize.width / 2, 50);
weaponLayer->addChild(m_weapon);
// create a shoot button
LabelTTF *label = LabelTTF::create("Shoot", "Arial", 20);
MenuItemLabel *shootLabel = MenuItemLabel::create(label, CC_CALLBACK_1(HelloWorld::onShootClick, this));
Menu *shoot = Menu::create(shootLabel, NULL);
shoot->setPosition(visibleSize.width-40, 20);
// add layers. first add buttom layer.
addChild(weaponLayer);
addChild(fishLayer);
addChild(shoot); // the menu must be the uppest layer.
// add touch listener
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
示例13: CC_CALLBACK_1
void GamePlayingScene::initial() {
this->getPhysicsWorld()->setGravity(ParameterManager::getGravity());
this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
SetGameCacheController::getInstance()->setGameCache();
auto map = CSLoader::createNode(Constant::getLevel1MapCsdPath());
this->addChild(map,0);
//加入弓箭手
this->addChild(ArcherController::getInstance(),1);
//进度条
this->addChild(ProgressTimeController::getInstance(), 1);
//地板
this->addChild(GroundController::getInstance(),1);
//产生敌人
this->addChild(EnemyController::getInstance(),1);
//物理世界监听
auto listener = EventListenerPhysicsContact::create();
listener->onContactBegin = CC_CALLBACK_1(GamePlayingScene::onContactBegan, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
//触屏 listener
EventListenerTouchOneByOne* screenListener = EventListenerTouchOneByOne::create();
screenListener->setSwallowTouches(true);// true不向下触摸,简单点来说,比如有两个sprite ,A和 B,A在上B在下(位置重叠)
screenListener->onTouchBegan = CC_CALLBACK_2(GamePlayingScene::onTouchBegan, this);
screenListener->onTouchEnded = CC_CALLBACK_2(GamePlayingScene::onTouchEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(screenListener, this);
auto menu = Menu::create();
menu->setPosition(Vec2::ZERO);
menu->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
this->addChild(menu,1);
Size visibleSize = ParameterManager::getVisibleSize();
auto gameEndedItem = MenuItemImage::create(Constant::getGameEndedPath(), Constant::getGameEndedPath(), CC_CALLBACK_1(GamePlayingScene::ClickGameEnded, this));
gameEndedItem->setPosition(visibleSize.width, visibleSize.height);
gameEndedItem->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
menu->addChild(gameEndedItem);
auto keyboardListener = EventListenerKeyboard::create();
keyboardListener->onKeyPressed = CC_CALLBACK_2(GamePlayingScene::onKeyPressed,this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardListener,this);
}
示例14: InitGridRects
// on "init" you need to initialize your instance
bool GameScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
SonarCocosHelper::UI::AddCentredBackground( GAME_BACKGROUND_FILEPATH, this );
gridSprite = Sprite::create( GRID_FILEPATH );
gridSprite->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
this->addChild( gridSprite );
InitGridRects( );
InitGridPieces( );
for ( int x = 0; x < 3; x++ )
{
for ( int y = 0; y < 3; y++ )
{
gridArray[x][y] = EMPTY_PIECE;
}
}
turn = PLAYER_PIECE;
ai = new AI::AI( turn );
ui = new UI::UI( this );
gameState = STATE_PLAYING;
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create( );
listener->setSwallowTouches( true );
listener->onTouchBegan = CC_CALLBACK_2( GameScene::onTouchBegan, this );
listener->onTouchMoved = CC_CALLBACK_2( GameScene::onTouchMoved, this );
listener->onTouchEnded = CC_CALLBACK_2( GameScene::onTouchEnded, this );
listener->onTouchCancelled = CC_CALLBACK_2( GameScene::onTouchCancelled, this );
Director::getInstance( )->getEventDispatcher( )->addEventListenerWithSceneGraphPriority( listener, this );
return true;
}
示例15: addTouchEvent
void Plane::addTouchEvent()
{
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(false);
listener->onTouchBegan = [=](Touch* touch, Event *event) {
Plane *plane = dynamic_cast<Plane*>(event->getCurrentTarget());
assert((plane && (plane == this)));
Point screenPos = touch->getLocation();
Point pos = plane->convertToNodeSpace(screenPos);
Size s = plane->getContentSize();
Rect rect(0, 0, s.width, s.height);
if (rect.containsPoint(pos) && !Director::getInstance()->isPaused()) {
this->m_isMoving = true;
return true;
}
return false;
};
listener->onTouchMoved = [=](Touch *touch, Event *event) {
Plane *plane = dynamic_cast<Plane*>(event->getCurrentTarget());
assert((plane && (plane == this)));
Point pos = touch->getLocation();
Point pos1 = touch->getPreviousLocation();
Point diff = pos - pos1;
if (this->m_isMoving && !this->m_dead) {
Point newPos = plane->getPosition() + diff;
Size size = Director::getInstance()->getWinSize();
Size content = plane->getContentSize();
float x = fmax(content.width * 0.5, fmin(newPos.x, size.width - content.width * 0.5));
float y = fmax(content.height * 0.5, fmin(newPos.y, size.height - content.height * 0.5));
plane->setPosition(Point(x, y));
};
};
listener->onTouchEnded = [=](Touch *touch, Event *event) {
Plane *plane = dynamic_cast<Plane*>(event->getCurrentTarget());
assert((plane && (plane == this)));
this->m_isMoving = false;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}