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


C++ EventMouse::getScrollX方法代码示例

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


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

示例1: onMouseScroll

void MouseTest::onMouseScroll(Event *event)
{
    EventMouse* e = (EventMouse*)event;
    std::string str = "Mouse Scroll detected, X: ";
    str = str + tostr(e->getScrollX()) + " Y: " + tostr(e->getScrollY());
    _labelAction->setString(str.c_str());
}
开发者ID:fordream,项目名称:Snake,代码行数:7,代码来源:MouseTest.cpp

示例2: onMouseScroll

void Tower::onMouseScroll(cocos2d::Event* _event)
{
    if(_isClosing == true || _returnFromSave == true)
        return;// if we are pressing the close button, we dont want to build things!
    
	EventMouse* e = (EventMouse*)_event;

	_towerLayer->runAction(MoveBy::create(1/SCROLL_SPEED ,Vec2((-1*e->getScrollX())*SCROLL_MULTIPLIER, e->getScrollY()*SCROLL_MULTIPLIER)));
}
开发者ID:binarybird,项目名称:OpenTower,代码行数:9,代码来源:TowerScene.cpp

示例3: init


//.........这里部分代码省略.........
            break;

        case EventKeyboard::KeyCode::KEY_D:
        case EventKeyboard::KeyCode::KEY_CAPITAL_D:
            CCLOG("key D up");
            _right = false;
            break;
        case EventKeyboard::KeyCode::KEY_Q:
        case EventKeyboard::KeyCode::KEY_CAPITAL_Q:
            CCLOG("key Q up");
            _up = false;
            break;

        case EventKeyboard::KeyCode::KEY_E:
        case EventKeyboard::KeyCode::KEY_CAPITAL_E:
            CCLOG("key E up");
            _down = false;
            break;

//            case EventKeyboard::KeyCode::KEY_UP_ARROW:
//                up();
//                break;
//            case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
//                down();
//                break;
//            case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
//                left();
//                break;
//            case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
//                right();
//                break;

        default:
            break;
        }

    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(_keyboardListener, this);

    // mouse
    _mouseListener = EventListenerMouse::create();

    _mouseListener->onMouseMove = [&](Event *event) {
        if (!_isFPS) return;

        EventMouse* e = (EventMouse*)event;
        auto now = e->getLocation();
        Vec2 diff = now - _fpsAnchor;
        _fpsAnchor = now;
        _rotateY -= ROTATE_SCALE*diff.x;
        _rotateX -= ROTATE_SCALE*diff.y;
        if (_rotateX > UP_DOWN_MAX*0.5f*PI) _rotateX = UP_DOWN_MAX*0.5f*PI;
        if (_rotateX < -UP_DOWN_MAX*0.5f*PI) _rotateX = -UP_DOWN_MAX*0.5f*PI;

    };
    _mouseListener->onMouseUp = [&](Event *event) {
        EventMouse* e = (EventMouse*)event;
        switch(e->getMouseButton()) {
        case MOUSE_BUTTON_LEFT:
            break;

        case MOUSE_BUTTON_RIGHT:
            _isFPS = false;
            break;

        default:
            break;
        }
    };
    _mouseListener->onMouseDown = [&](Event *event) {
        EventMouse* e = (EventMouse*)event;
        switch(e->getMouseButton()) {
        case MOUSE_BUTTON_LEFT:
            break;

        case MOUSE_BUTTON_RIGHT:
        {
            _isFPS = true;
            _fpsAnchor = e->getLocation();
            auto ro = _camera->getRotation3D();
            CCLOG("%f,%f,%f", ro.x, ro.y, ro.z);
            break;
        }
        default:
            break;
        }
    };
    _mouseListener->onMouseScroll = [&](Event *event) {
        EventMouse* e = (EventMouse*)event;
        CCLOG("%f, %f", e->getScrollX(), e->getScrollY());
        float diff = e->getScrollY();
        Vec3 dir = _camera->getRotationQuat() * Vec3{0.f, 0.f, -1.f};
        dir.normalize();
        _camera->setPosition3D(_camera->getPosition3D() + SCALL_MOVE_SCALE * -diff * dir);
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(_mouseListener, this);

    scheduleUpdate();
    return true;
}
开发者ID:dgkae,项目名称:turnro_cube_editor,代码行数:101,代码来源:EditorScene.cpp

示例4: applicationDidFinishLaunching

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
	auto director = Director::getInstance();
	auto glview = CCQGLView::getInstance();
	//glview->setBgColor(Color4B(50, 50, 50, 255));

	director->setOpenGLView(glview);
	_mainWindow.setGLView(glview->getGLWidget());
	_mainWindow.initActionListWidget();
	_mainWindow.show();

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    auto scene = Scene::create();
	scene->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	
	scene->setContentSize(Director::getInstance()->getVisibleSize());
	//scene->setPosition(Director::getInstance()->getVisibleSize() / 2);
	QString path;
	QDir dir;
	path = dir.currentPath();
	FileUtils::getInstance()->addSearchPath(path.toStdString() + "/Resources");
	FileUtils::getInstance()->addSearchPath("D://Resources");
	auto keyboardEvent = EventListenerKeyboard::create();

	keyboardEvent->onKeyPressed = [=](EventKeyboard::KeyCode code, Event*event)
	{
		if (code == EventKeyboard::KeyCode::KEY_CTRL)
		{
			m_dragMode = true;
		}
	};

	keyboardEvent->onKeyReleased = [=](EventKeyboard::KeyCode code, Event*event)
	{
		if (code == EventKeyboard::KeyCode::KEY_CTRL)
		{
			m_dragMode = false;
		}
	};

	Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(keyboardEvent, -1);


	auto scrollEvent = EventListenerMouse::create();
	scrollEvent->onMouseScroll = [=](Event* event)
	{
		EventMouse* e = (EventMouse*)event;
		int scrollX = e->getScrollX();
		int scrollY = e->getScrollY();
		scene->setScale(scene->getScale() + (float)scrollY / 100.0f);
		Size currentSize = scene->getContentSize() * scene->getScale();
	//	scene->setScale();
	};

	auto eventListener = EventListenerTouchOneByOne::create();

	eventListener->onTouchBegan = [=](Touch*touch, Event*event)->bool{
		if (!m_dragMode)
			return false;
		return true;
	};

	eventListener->onTouchMoved = [=](Touch*touch, Event*event)
	{
		scene->setPosition(scene->getPosition() + touch->getDelta());
	};
	eventListener->setSwallowTouches(true);

	Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(eventListener, -3);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(scrollEvent, -2);
    // run
    director->runWithScene(scene);

	CCRect rect(0, 0, scene->getContentSize().width, scene->getContentSize().height);

	CCSprite* grid = CCSprite::create("grid1_16x16_new_aaa.png");

	grid->setTextureRect(rect);

	Texture2D::TexParams params = {

		GL_LINEAR,

		GL_LINEAR,

		GL_REPEAT,

		GL_REPEAT

	};

	grid->getTexture()->setTexParameters(&params);
	grid->setAnchorPoint(Vec2::ZERO);
	grid->setPosition(Vec2::ZERO);
//.........这里部分代码省略.........
开发者ID:enhhh,项目名称:cocos-tool-with-qt-demo,代码行数:101,代码来源:AppDelegate.cpp


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