Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera problems on STLayerPanZoom #2

Open
paulocoutinhox opened this issue Dec 19, 2023 · 1 comment
Open

Camera problems on STLayerPanZoom #2

paulocoutinhox opened this issue Dec 19, 2023 · 1 comment

Comments

@paulocoutinhox
Copy link
Owner

paulocoutinhox commented Dec 19, 2023

Hi,

We have a great camera class STLayerPanZoom. But have some problems:

  • Mouse scroll don't zoom out, variable _zoomWaitTimer freeze on same value
  • Add support for joystick zoom (L1/L2 or R1/R2)
  • There is a lot of comments/todos that need be checked
  • When use with animated param = true, it break

Thanks.

@stevetranby
Copy link

One possible note is the PanZoomLayer (and STPanZoomLayer), when combined with the CameraManager class, is that the panning and zooming are all done through moving and scaling the root layer (the _panZoomLayer).

NOTES:

  • SCALE_LARGE is a float value based on screen resolution compared to design resolution
  • PanZoomLayer delegate receives callbacks for touches
  • kCameraZoomInMap - game-specific value for default zoom
  • kTagPanZoomLayer - tag for quick access to the specific layer
  • setPositionZ(-3) and addChild( ... , -3) - these are related to rendering order, and are probably game-specific
  • anchorpoint ZERO - this is personal preference, I prefer bottom-left origins for maps, whereas I prefer center or non-corner anchor/origin for sprites (to allow rotating about the anchor)
// MARK: Setup PanZoomLayer -

// Pan Zoom Touch
if(panZoomLayer) {
    panZoomLayer->removeFromParent();
}

// setup touch layer
{
    panZoomLayer = STLayerPanZoom::create();
    panZoomLayer->setPosition(Vec2::ZERO);
    panZoomLayer->setMinScale(.1f * SCALE_LARGE); 
    panZoomLayer->setMaxScale(2.f * SCALE_LARGE);
    panZoomLayer->setScale(kCameraZoomInMap * SCALE_LARGE);
    panZoomLayer->setDelegate(this);
    panZoomLayer->setAnchorPoint(Vec2::ZERO);
    panZoomLayer->setTag(kTagPanZoomLayer);
    panZoomLayer->setPositionZ(-3);
    addChild(panZoomLayer, -3);
}

// attach map
tileMap->setTag(kTagTileMap);

panZoomLayer->addChild(tileMap);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants