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


C++ Touch类代码示例

本文整理汇总了C++中Touch的典型用法代码示例。如果您正苦于以下问题:C++ Touch类的具体用法?C++ Touch怎么用?C++ Touch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1:

void Game2DStage::touchHandler(JniMethodInfo nativeTouchCallbackMInfo, std::string type, std::vector<cocos2d::Touch *> &touches){
    
    jstring jType = nativeTouchCallbackMInfo.env->NewStringUTF(type.c_str());
    
    int len = touches.size()*2;
    jfloat buf[len];
    jfloatArray arr = nativeTouchCallbackMInfo.env->NewFloatArray(len);
    
    Touch *t = NULL;
    Point p;
    
    int index = 0;
    for (auto it = touches.begin(); it!=touches.end(); it++) {
        t = (Touch*)(*it);
        p = t->getLocation();
        
        buf[index] = p.x;index++;
        buf[index] = p.y;index++;
    }
    
    nativeTouchCallbackMInfo.env->SetFloatArrayRegion(arr, 0, len, buf);
    
    nativeTouchCallbackMInfo.env->CallStaticVoidMethod(nativeTouchCallbackMInfo.classID, nativeTouchCallbackMInfo.methodID,jType,arr);
    
    nativeTouchCallbackMInfo.env->DeleteLocalRef(jType);
    nativeTouchCallbackMInfo.env->DeleteLocalRef(arr);
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: sqrtf

void QTELayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event)
{
    if(!enableFight) return;
    Touch *touch = touches.at(0);
    Vec2 delta = touch->getDelta();
    Vec2 lastPos = touch->getPreviousLocation();
    Vec2 pos = touch->getLocation();
    
    float dx = pos.x - startTouchPosition.x;
    float dy = pos.y - startTouchPosition.y;
    float dist = sqrtf(dx*dx+dy*dy);
    
    
    streak->setPosition(pos);
    //刀的判断
    dist = pos.distanceSquared(startTouchPosition);
    
    if (dist > 50) {
        //hit test monster
        bool hit = qteMonster->hittestPoint(pos);
        if (hit) {
            hitQteMonster();
        }
    }
}
开发者ID:NjAiYo,项目名称:MonsterGame,代码行数:25,代码来源:QTELayer.cpp

示例3: QObject

Touch::Touch(const Touch &t) : QObject(t.parent())
{
    fixedMiddle = t.fixedMiddle;
    setContours(t.getCvContour());
    found = t.isFound();
    id = t.getId();
}
开发者ID:mcharmas,项目名称:TouchTracer,代码行数:7,代码来源:touch.cpp

示例4: log

void PlaySceneOne::onTouchMoved(Touch* touches, Event* event) 
{
	log("touchMMMMMMMMMOOVVEDDD执行了---------------------------------------------");
	// 获取当前触摸的目标
	Touch* touch = static_cast<Touch*>(touches);
	Point locationInNodelocal = touch->getLocation();

	//log("GameObjHero::onTouchBegan::rx=%0.2f, ry=%0.2f, rw=%0.2f, rh=%0.2f, lx=%0.2f, ly=%0.2f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, locationInNode.x, locationInNode.y);
		//左侧手势 
		if (ControlrectMove.containsPoint(locationInNodelocal))
		{
			float adsxL = locationInNodelocal.x - proposL.x;
			float adsyL = locationInNodelocal.y - proposL.y;
			hero->locationInNode = locationInNodelocal;
			if (adsxL <= -50 && hero->state != 1) {	//减少手抖的影响且主角不在空中
				proposL = locationInNodelocal;
				// 设置运动状态:左移
				hero->setState(3); log("MMMMMMMMMOOOOOOOOVVVVEEEEE1");
			}
			else if (adsxL >= 50 && hero->state != 1) {
				proposL = locationInNodelocal;
				// 设置运动状态:右移
				hero->setState(4); log("MMMMMMMMMOOOOOOOOVVVVEEEEE2");
			}
		}
		//右上手势
		else if (ControlrectShot.containsPoint(locationInNodelocal)) {
			log("shotmoved");
			proposM = locationInNodelocal;////////////////////////;
			hero->archAngle = locationInNodelocal;
			hero->rotateArrow(hero->archAngle); hero->setState(7);
		}
}
开发者ID:MulticsYin,项目名称:Archer-cocos2d-x,代码行数:33,代码来源:PlaySceneOne.cpp

示例5: OnTouchPressed

void BadaAppForm::OnTouchPressed(const Control& source, 
																 const Point& currentPosition, 
																 const TouchEventInfo& touchInfo) {
	Touch touch;
	_touchCount = touch.GetPointCount();
	if (_touchCount > 1) {
		int index = getShortcutIndex();
		_shortcutIndex = (index == -1 ? 0 : index + 1);
		_shortcutTimer = g_system->getMillis();
		
		switch (_shortcutIndex) {
		case SHORTCUT_F5:
			g_system->displayMessageOnOSD(_("Game Menu"));
			break;
			
		case SHORTCUT_ESCAPE:
			g_system->displayMessageOnOSD(_("Escape"));
			break;
			
		default:
			g_system->displayMessageOnOSD(_("Swap Buttons"));
			_shortcutIndex = SHORTCUT_SWAP_MOUSE;
		}
	}	else if (getShortcutIndex() == -1) {
		pushEvent(_buttonState == LeftButton ? Common::EVENT_LBUTTONDOWN : Common::EVENT_RBUTTONDOWN,
							currentPosition);
	}
}
开发者ID:chrisws,项目名称:scummvm,代码行数:28,代码来源:form.cpp

示例6: ccTouchesMoved

void CocosDenshionTest::ccTouchesMoved(Set *pTouches, Event *pEvent)
{
    Touch* touch = (Touch*)pTouches->anyObject();

    Point touchLocation = touch->getLocation();
    float nMoveY = touchLocation.y - _beginPos.y;

    Point curPos  = _itmeMenu->getPosition();
    Point nextPos = ccp(curPos.x, curPos.y + nMoveY);

    if (nextPos.y < 0.0f)
    {
        _itmeMenu->setPosition(PointZero);
        return;
    }

    if (nextPos.y > ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
    {
        _itmeMenu->setPosition(ccp(0, ((_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
        return;
    }

    _itmeMenu->setPosition(nextPos);
    _beginPos = touchLocation;
}
开发者ID:bassarisse,项目名称:LostInCaves,代码行数:25,代码来源:CocosDenshionTest.cpp

示例7: screenToWorld

// check if the touch was on one of the flipper buttons
void PinballRUBELayer::onTouchesBegan(const std::vector<Touch *> &touches, cocos2d::Event *event)
{
    // Calling the superclass handles the mouse joint dragging for the launcher,
    // but it also allows the user to grab the ball, and zoom and pan the scene.
    // For a real application you would want to implement a better method here.
    //  RUBELayer::onTouchesBegan(touches, event);
    
    for (auto it = touches.begin(); it != touches.end(); ++it)
    {
        Touch* touch = (Touch*)*it;
        Point screenPos = touch->getLocationInView();
        b2Vec2 worldPos = screenToWorld(screenPos);
        
        CCLOG("Touch began at x: %f y: %f", screenPos.x, screenPos.y);
        
        // Make a small box around the touched point to query for overlapping fixtures
        b2AABB aabb;
        b2Vec2 d(0.001f, 0.001f);
        aabb.lowerBound = worldPos - d;
        aabb.upperBound = worldPos + d;
        
        // Query the world for overlapping fixtures (the TouchDownQueryCallback simply
        // looks for any fixture that contains the touched point)
        TouchDownQueryCallback callback(worldPos);
        m_world->QueryAABB(&callback, aabb);
        
        // if the touched fixture was one of the flipper buttons, set that touch as
        // the current touch for that button
        if (callback.m_fixture == m_leftFlipperButtonFixture)
            m_leftFlipperTouch = touch;
        if (callback.m_fixture == m_rightFlipperButtonFixture)
            m_rightFlipperTouch = touch;
    }
}
开发者ID:iSevenDays,项目名称:RUBEExamples,代码行数:35,代码来源:PinballRUBELayer.cpp

示例8: while

void SelectStage::onTouchesEnded(const vector<Touch *> & touches, Event * event)
{
    vector<Touch *>::const_iterator it = touches.begin();
    while (it != touches.end()) {
        Touch * touch = (Touch *) (* it);
        
        if (touch) {
            Point tap = touch->getLocation();
            Rect select;
            Scene * gameScene;
            
            select = _stageSun->getBoundingBox();
            if (select.containsPoint(tap)) {
                gameScene = TransitionFlipY::create(0.5f,GameLayer::scene(),TransitionScene::Orientation::RIGHT_OVER);
                Director::getInstance()->replaceScene(gameScene);
                
            } else if (!select.containsPoint(tap) &&
                       _stageSea->getBoundingBox().containsPoint(tap)) {
//                gameScene = TransitionFlipY::create(0.5f, GameLayer::scene(), TransitionScene::Orientation::RIGHT_OVER);
//                Director::getInstance()->replaceScene(gameScene);
                
            } else {
                
            }
        }
        
        it++;
    }
    
}
开发者ID:kubocker,项目名称:SpaceShooting,代码行数:30,代码来源:SelectStageLayer.cpp

示例9: while

void MainThread::run() {

  serial.blocking = true;
  serial.baud = 115200;
  serial.echo = true;

  if (serial.open() != Uart0::kOK)
    Board::reboot();

  Touch touch;
  bool touchOk = touch.setup();
  if (!touchOk) {
    serial << "Error during touch sensor setup." << Uart0::endl;
  }

  while (1) {
    if (touch.checkSensor()) {
      serial << "Touch sensor ok." << Uart0::endl;
    }
    else {
      serial << "Touch sensor error." << Uart0::endl;
    }
    sleep_ms(500);
  }
}
开发者ID:DKrepsky,项目名称:Interruptor,代码行数:25,代码来源:main_thread.cpp

示例10: executeTouchCancelledAfterLongClickHandler

void CWidgetWindow::onTouchesCancelled(const std::vector<Touch*>&touches, Event *unused_event)
{
	for(unsigned int i=0;i<touches.size(); i++)
	{
		Touch* pTouch = touches.at(i);
		map<int, __ccMULTITOUCHTARGET>::iterator mitr = m_mMultiTouchKeeper.find(pTouch->getID());
		if( mitr != m_mMultiTouchKeeper.end() )
		{
			if( mitr->second.pWidget )
			{
				if( mitr->second.pWidget->isTouchInterrupted() )
				{
					if( mitr->second.pLongClickedWidgetObject )
					{
						executeTouchCancelledAfterLongClickHandler(mitr->second.pLongClickedWidgetObject, pTouch, mitr->second.fTouchedDuration);
					}
				}
				else
				{
					mitr->second.pWidget->interruptTouchCascade(pTouch, mitr->second.fTouchedDuration);
				}
			}
			m_mMultiTouchKeeper.erase(mitr);
		}
	}
}
开发者ID:110440,项目名称:Tui-x,代码行数:26,代码来源:WidgetWindow.cpp

示例11: CCLOG

void LHScenePhysicsTransformationsDemo::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
{
    if(touches.size() < 1){
        return;
    }
    Touch* touch = touches[0];
    

    Point location = touch->getLocation();
    
    
    __Array* allPhysicalChildren = this->getGameWorldNode()->getChildrenOfType<Node*>();
    
    for(int i = 0; i < allPhysicalChildren->count(); ++i)
    {
        Node* node = (Node*)allPhysicalChildren->getObjectAtIndex(i);
        
        if(node && node->getBoundingBox().containsPoint(location))
        {
//            node->removeFromParent();//this will remove the node together with its physical body (if any)
            
            CCLOG("SETTING NODE %p TO LOCATION %f %f", node, location.x, location.y);
            node->setPosition(location);
            node->setRotation(LHUtils::LHRandomFloat(0, 360));
            node->setScaleX(LHUtils::LHRandomFloat(0.2, 1.5f));
            node->setScaleY(LHUtils::LHRandomFloat(0.2, 1.5f));
            return;
        }
    }
    //dont forget to call super
    LHScene::onTouchesBegan(touches, event);
}
开发者ID:anilgulgor,项目名称:myGame,代码行数:32,代码来源:LHScenePhysicsTransformationsDemo.cpp

示例12: AddTouchEventListener

result CCEGLView::OnInitializing(void)
{
	result r = E_SUCCESS;

	AddTouchEventListener(*this);
	Touch touch;
	touch.SetMultipointEnabled(*this, true);

    m_pKeypad = new Keypad();
    m_pKeypad->Construct(KEYPAD_STYLE_NORMAL, KEYPAD_MODE_ALPHA);
    m_pKeypad->AddTextEventListener(*this);

	Rectangle rc = GetBounds();
	if ((rc.width == 480 && rc.height == 720)
			|| (rc.width == 720 && rc.height == 480))
	{
		m_bNotHVGA = false;
		m_sSizeInPixel.width = rc.width / 1.5f;
		m_sSizeInPixel.height = rc.height / 1.5f;
	}
	else
	{
		m_bNotHVGA = true;
		m_sSizeInPixel.width = rc.width;
		m_sSizeInPixel.height = rc.height;
	}

	// calculate the factor and the rect of viewport
	m_fScreenScaleFactor =  MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
		                         (float)m_sSizeInPixel.height / m_sSizeInPoint.height);
	//CCLOG("rc.width = %d, rc.height = %d, m_fScreenScaleFactor = %f", rc.width, rc.height, m_fScreenScaleFactor);
	resize(m_sSizeInPoint.width, m_sSizeInPoint.height);

	return r;
}
开发者ID:Avnerus,项目名称:ichigo,代码行数:35,代码来源:CCEGLView_bada.cpp

示例13: screenToWorld

// Override this to find the body that was touched and remove it.
void DestroyBodyLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event)
{   
    Touch *touch = (Touch*)touches[0];
    Point screenPos = touch->getLocationInView();
    b2Vec2 worldPos = screenToWorld(screenPos);
    
    // Make a small box around the touched point to query for overlapping fixtures
    b2AABB aabb;
    b2Vec2 d(0.001f, 0.001f);
    aabb.lowerBound = worldPos - d;
    aabb.upperBound = worldPos + d;
    
    // Query the world for overlapping fixtures (the TouchDownQueryCallback simply
    // looks for any fixture that contains the touched point)
    TouchDownQueryCallback callback(worldPos);
    m_world->QueryAABB(&callback, aabb);
    
    // Check if we found something, and it was a dynamic body (could also destroy static
    // bodies but we want to keep the pinch-zoom and pan from the superclass, and it's
    // hard not to touch the ground body in this scene)
    if (callback.m_fixture && callback.m_fixture->GetBody()->GetType() == b2_dynamicBody)
    {
        b2Body* touchedBody = callback.m_fixture->GetBody();
        removeBodyFromWorld(touchedBody);
    }
}
开发者ID:dabing1022,项目名称:rock_box2d,代码行数:27,代码来源:DestroyBodyLayer.cpp

示例14: ccTouchesMoved

void BLevelMenu::ccTouchesMoved(Set *pTouches, Event *pEvent)
{
    Touch* touch = (Touch*)pTouches->anyObject();
    
    Point touchLocation = touch->getLocation();
    float nMoveY = touchLocation.y - beginPos.y;
    
    Point curPos  = itemMenu->getPosition();
    Point nextPos = Point(curPos.x, curPos.y + nMoveY);
    
    if (nextPos.y < 0.0f)
    {
        itemMenu->setPosition(Point::ZERO);
        return;
    }
    
    if (nextPos.y > ((levelCount + 1)* LINE_SPACE - visRect.size.height))
    {
        itemMenu->setPosition(Point(0, ((levelCount + 1)* LINE_SPACE - visRect.size.height)));
        return;
    }
    
    itemMenu->setPosition(nextPos);
    beginPos = touchLocation;
    s_tCurPos   = nextPos;
}
开发者ID:Ben-Cortina,项目名称:GameBox,代码行数:26,代码来源:BoundLevelMenu.cpp

示例15: CCLOG

void GLView::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, intptr_t ids[], float xs[], float ys[])
{
    intptr_t id = 0;
    float x = 0.0f;
    float y = 0.0f;
    EventTouch touchEvent;
    
    for (int i = 0; i < num; ++i)
    {
        id = ids[i];
        x = xs[i];
        y = ys[i];

        auto iter = g_touchIdReorderMap.find(id);
        if (iter == g_touchIdReorderMap.end())
        {
            CCLOG("if the index doesn't exist, it is an error");
            continue;
        }
        
        /* Add to the set to send to the director */
        Touch* touch = g_touches[iter->second];
        if (touch)
        {
            CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
            touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
                                (y - _viewPortRect.origin.y) / _scaleY);

            touchEvent._touches.push_back(touch);
            
            g_touches[iter->second] = nullptr;
            removeUsedIndexBit(iter->second);

            g_touchIdReorderMap.erase(id);
        } 
        else
        {
            CCLOG("Ending touches with id: %ld error", static_cast<long>(id));
            return;
        } 

    }

    if (touchEvent._touches.size() == 0)
    {
        CCLOG("touchesEnded or touchesCancel: size = 0");
        return;
    }
    
    touchEvent._eventCode = eventCode;
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    dispatcher->dispatchEvent(&touchEvent);
    
    for (auto& touch : touchEvent._touches)
    {
        // release the touch object.
        touch->release();
    }
}
开发者ID:boruis,项目名称:cocos2dx-lite,代码行数:59,代码来源:CCGLView.cpp


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