本文整理汇总了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");
}
}
}
示例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();
}
}
示例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轴向上 */
}
示例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();
}
示例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());
}
示例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;
}
示例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());
}
}
示例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;
}