how to prevent showing outside of world game in cocos2dx
- by HRZ
Im trying to make a tower defence game and it can zoom in/out and scrolling over my world map.How to scroll over the game and how to restrict it to don't show outside of my map.
At below I scroll over the map by using CCCamera but i don't know how i can restrict it.
CCPoint tap = touch->getLocation();
CCPoint prev_tap = touch->getPreviousLocation();
CCPoint sub_point = tap - prev_tap;
float xNewPos, yNewPos;
float xEyePos, yEyePos, zEyePos;
float cameraPosX, cameraPosY, cameraPosZ;
// First we get the current camera position.
GameLayer->getCamera()->getCenterXYZ(&cameraPosX, &cameraPosY, &cameraPosZ);
GameLayer->getCamera()->getEyeXYZ(&xEyePos, &yEyePos, &zEyePos);
// Calculate the new position
xNewPos = cameraPosX - sub_point.x;
yNewPos = cameraPosY - sub_point.y;
GameLayer->getCamera()->setCenterXYZ(xNewPos, yNewPos, cameraPosZ);
GameLayer->getCamera()->setEyeXYZ(xNewPos, yNewPos, zEyePos);
And for zooming i used such code:
GameLayer->setScale(this->getScale() + 0.002); //zooming in