Last active
March 25, 2016 04:38
-
-
Save masuhajime/d30ef0e7e9041ad0bef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
auto listener = larme::eventlistener::EventListenerTouchAction::create(); | |
listener->onTouchesActionZoom = [this](float distance) { | |
this->cameraZoom += distance / 1000.0f; | |
// ここで distanceのmaxを設定したほうがいいかも・ | |
}; | |
listener->onTouchesActionPan = [this](Vec2 distance) { | |
this->cameraPosition -= distance / this->cameraZoom; | |
}; | |
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); | |
this->setCameraMask((unsigned short)cocos2d::CameraFlag::USER2, true); | |
} | |
void LayerUsagi::update(float delta) { | |
// カメラの設定 | |
auto size = Director::getInstance()->getVisibleSize(); | |
if (cameraZoom < 0.5f) { | |
cameraZoom = 0.5f; | |
} else if (1.5f < cameraZoom) { | |
cameraZoom = 1.5f; | |
} | |
Vec2 zoomOffset = Vec2::ZERO; | |
// 謎の式だがこれでおおよそ上手く動作する | |
zoomOffset -= (1 - cameraZoom)/2 * Vec2(size.width, size.height); | |
zoomOffset *= 1 / cameraZoom; | |
camera->setPosition(cameraPosition + zoomOffset); | |
camera->initOrthographic(size.width / cameraZoom, size.height / cameraZoom, -1, 1); | |
} |
Author
masuhajime
commented
Mar 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment