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


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

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


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

示例1: onMouseDown

void HelloWorld::onMouseDown(Event* event)
{
#ifdef MOUSE_DOUBLE_LISTEN_FUDGE
    mouseDownFudge = !mouseDownFudge;
    if(!mouseDownFudge)
        return;
#endif
    EventMouse* e = (EventMouse*)event;
    isMouseDown[e->getMouseButton()] = true;
    std::stringstream ss;
    ss << "Mouse Down ";
    ss << e->getMouseButton();

    if(e->getMouseButton() == 1)
    {
        if(!getChildByName("animtest"))
        {
            auto s = new O3Sprite("", true);
            addSprite(s);
            s->addAnimation("idle", "animtest", 9, 12);
            s->setAnimation("idle");
            s->playAnimation();
            s->setName("animtest");
        }
        else
        {
            removeChildByName("animtest");
        }
    }
}
开发者ID:dare0021,项目名称:October3rd,代码行数:30,代码来源:HelloWorldScene.cpp

示例2: onMouseUp

void LCBattleScene::onMouseUp(Event *event)
{
    EventMouse* e = (EventMouse*)event;
    //world->setGravity(Point(0 ,-98));
    //world->setSpeed(1);
//    Vect vct = world->getGravity();
//    float speed = world->getSpeed();
    // right clicked move hero
    if(e->getMouseButton() == 1) {
        // retain screen double length
        //Point pos = CCDirector::getInstance()->convertToGL(Point(e->getCursorX(), e->getCursorY()));//glLocation, origin(0,0)
        //pos.y = CCDirector::getInstance()->getWinSize().height - pos.y / 2;
        //CCLOG("%f %f", pos.x, pos.y);

        //Point origin = hero->getrootObj()->getPosition();

        //CCLOG("%f %f", origin.x, origin.y);

        //Point convertedToNodeLocation = backGround->convertToNodeSpace(pos);

        //Point p = getPointInMap();
        hero->actionWalk(this, backGround->convertToNodeSpace(Point(e->getCursorX(), e->getCursorY())));
    } else if(e->getMouseButton() == 0) {
        hero->actionAttack();
    }
}
开发者ID:rotonlin,项目名称:Fighter,代码行数:26,代码来源:fighter.cpp

示例3: onMouseDown

void BaseScene::onMouseDown(Event* event){
	cocos2d::log("down");	
	EventMouse * e = (EventMouse*)event;
	if(e->getMouseButton() == 0) cocos2d::log("left mouse");
	else if(e->getMouseButton() == 1) cocos2d::log("right mouse");
	else if(e->getMouseButton() == 2) cocos2d::log("middle mouse");

	/* 都是获取当前点坐标,但e->getDelta()左上角是原点,y轴向下;
	/* e->getCursorX(), e->getCursorY()左上角是原点,y轴向上  */
}
开发者ID:yinglang,项目名称:DemoWork,代码行数:10,代码来源:BaseScene.cpp

示例4: onMouseUp

void HelloWorld::onMouseUp(Event* event)
{
#ifdef MOUSE_DOUBLE_LISTEN_FUDGE
    mouseUpFudge = !mouseUpFudge;
    if(!mouseUpFudge)
        return;
#endif
    EventMouse* e = (EventMouse*)event;
    isMouseDown[e->getMouseButton()] = false;
    timeSinceLastMouseUp = 0;
    std::stringstream ss;
    ss << "Mouse Up detected, Key: ";
    ss << e->getMouseButton();
}
开发者ID:dare0021,项目名称:October3rd,代码行数:14,代码来源:HelloWorldScene.cpp

示例5: onMouseUp

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

示例6: init

bool MouseScene::init()
{
	if (!Layer::init())
	{
		return false;
	}

	auto listener = EventListenerMouse::create();
	listener->onMouseDown = [](cocos2d::Event* event)
	{
		try
		{
			EventMouse* mouseEvent = dynamic_cast<EventMouse*>(event);
			mouseEvent->getMouseButton();
			std::stringstream message;
			message << "Mouse event: Button: " << mouseEvent->getMouseButton() << "pressed at point (" << mouseEvent->getLocation().x << ", " << mouseEvent->getLocation().y << ")";
			MessageBox(message.str().c_str(), "Mouse Event Details");
		}
		catch (std::bad_cast& e)
		{
			//not sure what kind of event you passed us cocos, but it was a wrong one
			return;
		}
	};
	listener->onMouseMove = [](cocos2d::Event* event){
		// Cast Event to EventMouse for position details like above
		cocos2d::log("Mouse moved event");
	};

	listener->onMouseScroll = [](cocos2d::Event* event){
		cocos2d::log("Mouse wheel scrolled");
	};

	listener->onMouseUp = [](cocos2d::Event* event){
		cocos2d::log("Mouse button released");
	};

	_eventDispatcher->addEventListenerWithFixedPriority(listener, 1);

	return true;
}
开发者ID:mittal-himanshu,项目名称:SpaceShooterRedux,代码行数:41,代码来源:MouseScene.cpp

示例7: mouseClick

void WorldScene::mouseClick(cocos2d::Event* event, Player* player) {
	CCLOG("mouse");
	CCLOG("Category %x", player->getPhysicsBody()->getCategoryBitmask());
	CCLOG("Collision %x", player->getPhysicsBody()->getCollisionBitmask());
	if (player->getArrow() > 0) {
		Vec2 loc = player->getPosition();
		CCLOG("%d", player->getArrow());
		EventMouse* mouseEvent = dynamic_cast<EventMouse*>(event);
		mouseEvent->getMouseButton();
		//auto pro = Sprite::create("CloseNormal.png");
		auto pro = Projectile::create();
		pro->setPosition(loc);

		this->addChild(pro, 1);
		//pro->setPosition(mouseEvent->getLocation().x, this->getContentSize().height-mouseEvent->getLocation().y);
		if (player->getMode() == 'a') {
			pro->setMode('a');
			Vec2 offset = mouseEvent->getLocation();
			offset.y = this->getContentSize().height - offset.y;
			offset -= player->getPosition();
			offset.normalize();

			auto deg = atan(offset.x / offset.y) * 180 /3.14;
			if (offset.y<0) {
				deg += 180;
			}
			CCLOG("%f", deg);

			auto target = offset*1000 + player->getPosition();
			auto rotate = RotateBy::create(0, deg);
			auto shoot = MoveTo::create(2.0f, target);
			auto remove = RemoveSelf::create();
			pro->runAction(Sequence::create(rotate, shoot, remove, nullptr));
			player->setArrow(player->getArrow() - 1);
		}
		else {
			pro->setMode('b');
			auto shoot = MoveBy::create(2.0f, Vec2(0, 500));
			auto remove = RemoveSelf::create();
			pro->runAction(Sequence::create(shoot, remove, nullptr));
			player->setArrow(player->getArrow() - 4);
		}
		
		
		setArrow(player->getArrow());
	}
}
开发者ID:miciltjandra,项目名称:rekrutmen-labpro,代码行数:47,代码来源:WorldScene.cpp

示例8: 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


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