Exemplo n.º 1
0
void Tower::onMouseMove(cocos2d::Event* _event)
{

	if(_isClosing == true || _returnFromSave == true)
    {
        _returnFromSave = false;
        return;// if we are pressing the close button, we dont want to build things!
    }

	EventMouse* e = (EventMouse*)_event;

	if(_isMovingToolPanal == true)
	{
		Vec2 tPP = _toolPanalLayer->getPosition();
		float mPPY = e->getCursorY();
		float mPPX = e->getCursorX();
		mPPY=mPPY+_mouseYOffset;

		_toolPanalLayer->setPosition(Vec2(mPPX-_windowOffsetX,mPPY-_windowOffsetY));
	}

	if(_isBuildingFloor == true)
	{
		float mPPY = e->getCursorY()+_mouseYOffset;
		float mPPX = e->getCursorX();
		createStructure(Vec2(mPPX,mPPY));
	}

    _mouseLayer->setPosition(e->getCursorX()-_currentStructureSize.width/2, _mouseYOffset + e->getCursorY() - _currentStructureSize.height/2);
}
Exemplo n.º 2
0
///Referencing previous location results in garbage values
///Use only for hover
void HelloWorld::onMouseMove(Event* event)
{
#ifdef MOUSE_DOUBLE_LISTEN_FUDGE
    mouseMoveFudge = !mouseMoveFudge;
    if(!mouseMoveFudge)
        return;
#endif
    EventMouse* e = (EventMouse*)event;
    lastCursor.x = e->getCursorX();
    lastCursor.y = e->getCursorY();
    repaintCursor();
    Protractor* p = (Protractor*)protractor;
    p->setCursorAngle(StaticHelpers::headingAngle(lastCursor - Director::getInstance()->getVisibleSize()/2));

    if(isMouseDown[0])
    {//LMB drag

    }
    if(isMouseDown[1])
    {//RMB drag

    }
    if(isMouseDown[2])
    {//MMB drag

    }

    std::stringstream ss;
    ss << "MousePosition X:";
    ss << e->getCursorX() << " Y:" << e->getCursorY();
}
Exemplo n.º 3
0
void MouseTest::onMouseMove(Event *event)
{
    EventMouse* e = (EventMouse*)event;
    std::string str = "MousePosition X:";
    str = str + tostr(e->getCursorX()) + " Y:" + tostr(e->getCursorY());
    _labelPosition->setString(str.c_str());
}
Exemplo n.º 4
0
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();
    }
}
Exemplo n.º 5
0
void Tower::onMouseDown(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;

	Vec2 tPP = _toolPanalLayer->getPosition();
	float mPPY = e->getCursorY();
	float mPPX = e->getCursorX();

	mPPY=mPPY+_mouseYOffset;

	if(mPPY < tPP.y + TOOLPANAL_HEIGHT+2 && mPPY > tPP.y-2)
		if(mPPX > tPP.x -2 && mPPX < tPP.x + TOOLPANAL_WIDTH+2){
			_isMovingToolPanal = true;
			
			_windowOffsetX = mPPX - tPP.x;
			_windowOffsetY = mPPY - tPP.y;
			return;
		}

	if(_currentStructure == OT::OTFLOOR)
	{
		_isBuildingFloor = true;//have to handle differently from other structures
	}
}
Exemplo n.º 6
0
void Tower::onMouseUp(cocos2d::Event* _event)
{
    if(_isClosing == true || _returnFromSave == true)
    {
        _returnFromSave = false;
        return;// if we are pressing the close button, we dont want to build things!
    }
    
	EventMouse* e = (EventMouse*)_event;

	if(_isMovingToolPanal == true)
	{
		_isMovingToolPanal = false;

		return; //if we are moving a window, we dont want to build things!
	}

	if(_isBuildingFloor == true)
	{
		_isBuildingFloor = false;
	}

	float mPPY = e->getCursorY()+_mouseYOffset;
	float mPPX = e->getCursorX();
    
    this->createStructure(Vec2(mPPX,mPPY));
    
}
Exemplo n.º 7
0
void GameMenu::OnMouseMove(Event *event)
{
	EventMouse *e = (EventMouse*)event;

	int x = e->getCursorX();
	int y = e->getCursorY();

<<<<<<< HEAD
Exemplo n.º 8
0
void HelloWorld::onMouseMove(Event* event) {
	EventMouse* e = (EventMouse*)event;
	CCPoint mousePosition = CCPoint(e->getCursorX(), e->getCursorY() + 640);

	auto block1 = startMenuItem->getBoundingBox();
	if (block1.containsPoint(mousePosition)) largerItem(startMenuItem, 1);
	else largerItem(NULL, 0);
}
Exemplo n.º 9
0
void GameLayer::onMouseMove(cocos2d::Event* event)
{
	EventMouse* e = (EventMouse*)event;

	auto p = Vec2(e->getCursorX(), e->getCursorY());

	auto pPlayer = dynamic_cast<LeadingMan*>(this->getChildByTag(kTagPlayer));

}
Exemplo n.º 10
0
bool SplashLayer::init() {

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

	//get Size
	Size visibleSize = Director::getInstance()->getVisibleSize();

	//change splash image here:
	auto splash = Sprite::create("Splash.png");
	splash->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	this->addChild(splash);

	auto start = Sprite::create("Splash_start.png");
	start->setPosition(Vec2(visibleSize.width / 2, 300));
	this->addChild(start);


	auto quit = Sprite::create("Splash_quit.png");
	quit->setPosition(Vec2(visibleSize.width / 2, 200));
	this->addChild(quit);


	//鼠标悬停,start按钮变大
	auto startlistener = EventListenerMouse::create();
	startlistener->onMouseMove = [=](Event* event) {
		Sprite* start = static_cast<Sprite*>(event->getCurrentTarget());
		EventMouse* mouse = static_cast<EventMouse*>(event);
		if (mouse->getCursorX() > 417 && mouse->getCursorX() < 607 &&
			mouse->getCursorY() > -484 && mouse->getCursorY() < -452) {
			if (aboveStart) {
				auto scale = ScaleTo::create(0.1f, 1.2f);
				start->runAction(scale);
				aboveStart = false;
				notAboveStart = true;
			}
		}
		else {
			if (notAboveStart) {
				auto scaleback = ScaleTo::create(0.1f, 1);
				start->runAction(scaleback);
				aboveStart = true;
				notAboveStart = false;
			}
		}
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(startlistener, start);

	//鼠标悬停,quit按钮变大
	auto quitlistener = EventListenerMouse::create();
	quitlistener->onMouseMove = [=](Event* event) {
		Sprite* quit = static_cast<Sprite*>(event->getCurrentTarget());
		EventMouse* mouse = static_cast<EventMouse*>(event);
		if (mouse->getCursorX() > 446 && mouse->getCursorX() < 578 &&
			mouse->getCursorY() > -585 && mouse->getCursorY() < -551) {
			if (aboveQuit) {
				auto scale = ScaleTo::create(0.1f, 1.2f);
				quit->runAction(scale);
				aboveQuit = false;
				notAboveQuit = true;
			}
		}
		else {
			if (notAboveQuit) {
				auto scaleback = ScaleTo::create(0.1f, 1);
				quit->runAction(scaleback);
				aboveQuit = true;
				notAboveQuit = false;
			}
		}
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(quitlistener, quit);


	//点击start按钮,场景切换进入关卡选择界面
	auto startclick = EventListenerMouse::create();
	startclick->onMouseDown = [](Event* event) {
		EventMouse* mouse = static_cast<EventMouse*>(event);
		if (mouse->getCursorX() > 417 && mouse->getCursorX() < 607 &&
			mouse->getCursorY() > -484 && mouse->getCursorY() < -452) {

			//获取当前时间作为随机数种子
			srand((unsigned int)time(nullptr));
			//生成范围为[1, 20]的随机数,20中随机动画
			int a = (rand() % 20) + 1;
			switch (a) {
			case 1:
				Director::getInstance()->replaceScene(TransitionProgressRadialCCW::create(0.5f, HomeScene::create()));
				break;
			case 2:
				Director::getInstance()->replaceScene(TransitionProgressRadialCW::create(0.5f, HomeScene::create()));
				break;
			case 3:
				Director::getInstance()->replaceScene(TransitionProgressHorizontal::create(0.5f, HomeScene::create()));
				break;
			case 4:
				Director::getInstance()->replaceScene(TransitionProgressVertical::create(0.5f, HomeScene::create()));
				break;
			case 5:
				Director::getInstance()->replaceScene(TransitionProgressInOut::create(0.5f, HomeScene::create()));
				break;
			case 6:
				Director::getInstance()->replaceScene(TransitionProgressOutIn::create(0.5f, HomeScene::create()));
				break;
			case 7:
				Director::getInstance()->replaceScene(TransitionFadeTR::create(0.5f, HomeScene::create()));
				break;
			case 8:
				Director::getInstance()->replaceScene(TransitionFadeBL::create(0.5f, HomeScene::create()));
				break;
			case 9:
				Director::getInstance()->replaceScene(TransitionFadeUp::create(0.5f, HomeScene::create()));
				break;
			case 10:
				Director::getInstance()->replaceScene(TransitionFadeDown::create(0.5f, HomeScene::create()));
				break;
			case 11:
				Director::getInstance()->replaceScene(TransitionTurnOffTiles::create(0.5f, HomeScene::create()));
				break;
			case 12:
				Director::getInstance()->replaceScene(TransitionMoveInL::create(0.5f, HomeScene::create()));
				break;
			case 13:
				Director::getInstance()->replaceScene(TransitionMoveInR::create(0.5f, HomeScene::create()));
				break;
			case 14:
				Director::getInstance()->replaceScene(TransitionMoveInT::create(0.5f, HomeScene::create()));
				break;
			case 15:
				Director::getInstance()->replaceScene(TransitionMoveInB::create(0.5f, HomeScene::create()));
				break;
			case 16:
				Director::getInstance()->replaceScene(TransitionSlideInB::create(0.5f, HomeScene::create()));
				break;
			case 17:
				Director::getInstance()->replaceScene(TransitionSlideInL::create(0.5f, HomeScene::create()));
				break;
			case 18:
				Director::getInstance()->replaceScene(TransitionSlideInR::create(0.5f, HomeScene::create()));
				break;
			case 19:
				Director::getInstance()->replaceScene(TransitionSlideInT::create(0.5f, HomeScene::create()));
				break;
			case 20:
				Director::getInstance()->replaceScene(TransitionPageTurn::create(0.5f, HomeScene::create(), true));
				break;
			default:
				log("ERROR!");
				break;
			}
		}
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(startclick, start);


	//点击quit按钮退出整个app
	auto quitclick = EventListenerMouse::create();
	quitlistener->onMouseDown = [](Event* event) {
		EventMouse* mouse = static_cast<EventMouse*>(event);
		if (mouse->getCursorX() > 446 && mouse->getCursorX() < 578 &&
			mouse->getCursorY() > -585 && mouse->getCursorY() < -551) {

			Director::getInstance()->end();
		}
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(quitclick, quit);
	
	return true;
}
Exemplo n.º 11
0
void MousePaddle::onMouseMove(Event *event) {
    EventMouse *e = (EventMouse*)event;
    this->setPosition(Point(910, e->getCursorY()));

    // std::cout << "Paddle pos: " << toString(getPosition()) << std::endl;
}