mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
clicking on the minimap moves the camera
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "minimapButton.h"
|
||||
#include "map.h"
|
||||
|
||||
#include <node.h>
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
MinimapButton::MinimapButton(Vector3 pos, Vector2 size, string ip) : Button(pos, size, "minimap", "", -1, true, ip){
|
||||
content = new Node();
|
||||
rectNode->attachChild(content);
|
||||
}
|
||||
|
||||
MinimapButton::~MinimapButton(){
|
||||
}
|
||||
|
||||
void MinimapButton::update(){
|
||||
Button::update();
|
||||
}
|
||||
|
||||
void MinimapButton::onClick(){
|
||||
Vector2 clickPos = getCursorPos();
|
||||
float posXRatio = (clickPos.x - pos.x) / size.x;
|
||||
float posYRatio = (clickPos.y - pos.y) / size.y;
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
Vector3 mapSize = Map::getSingleton()->getMapSize();
|
||||
cam->setPosition(Vector3(mapSize.x * (-.5 + posXRatio), cam->getPosition().y, mapSize.z * (-.5 + posYRatio)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user