本文整理汇总了C++中EventMouse::getLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ EventMouse::getLocation方法的具体用法?C++ EventMouse::getLocation怎么用?C++ EventMouse::getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventMouse
的用法示例。
在下文中一共展示了EventMouse::getLocation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMouseEvent
void HelloWorld::testMouseEvent()
{
auto listener = EventListenerMouse::create();
listener->onMouseDown = [&](Event* event){
log("onMouseDown");
};
listener->onMouseMove = [&](Event* event){
log("onMouseMove");
EventMouse* e = (EventMouse*)event;
touch_pos = e->getLocation();
streak->setPosition(touch_pos);
};
listener->onMouseUp = [&](Event* event){
log("onMouseUp");
};
listener->onMouseScroll = [&](Event* event){
log("onMouseScroll");
};
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
示例2: 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());
}
}
示例3: onMouseDown
void GameScene::onMouseDown(Event* ev1)
{
EventMouse* ev = (EventMouse*)ev1;
Vec2 loc = ev->getLocation();
int size = map.size();
/*for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
map.at(i + j).label->setColor(Color3B::BLUE);
Vec2 mao = (map.at(i + j)).image->getPosition();
Vec2 origin = Vec2(mao.x - 19, mao.y - 19);
Size size = Size(38.0, 38.0);
Rect rect = Rect(origin, size);
if (rect.containsPoint(loc)) {
current = map.at(i + j);
map.at(i + j).label->setColor(Color3B::RED);
return;
}
}
}*/
}
示例4: onMouseMove
void MapLayer::onMouseMove(Event *event){
if(!mapEdit)
return;
EventMouse *e = (EventMouse*)event;
Vec2 mousePos = e->getLocation();
mousePos.y = Director::getInstance()->getWinSize().height - mousePos.y;
mousePos -= CreatureLayer::GetInstance()->getPosition();
mouseX = (int)mousePos.x/TILE_SIZE;
mouseY = (int)mousePos.y/TILE_SIZE;
if(mouseX < 0 || mouseX > width-1)
mouseX = oldMouseX;
if(mouseY < 0 || mouseY > height-1)
mouseY = oldMouseY;
if(oldMouseX != mouseX || oldMouseY != mouseY){
SetNavigationString();
if(isMouseDown){
if(isEraser) {
Erase(mouseX, mouseY);
}
else{
Add(nowTile, mouseX, mouseY, 0.0f, false);
if(nowTile < 10){
}
else if(nowTile < 100){
obstacleCount++;
}
else{
objectCount++;
}
}
}
oldMouseX = mouseX;
oldMouseY = mouseY;
}
}
示例5: 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;
}
示例6: 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;
}