Track scaled layer?

Hey guys,

I’ve implemented pinch-zoom with pan on a Layer. So far so good. But I want to restrict the drag/scaling to the viewport ie

Director::getInstance()->getWinSize();

I can restrict when the layer is unzoomed, that’s pretty simple. But I can’t figure out how to convert a point on the scaled layer to node space because:

Layer->getPosition();

is always the same for any scale.

I’m using TGestureRecognizer. Is there a recipe or technique I am missing?

Thanks a lot!

I solved it. Mostly I had to figure out what cocos2d-x was doing since I am coming from MVC UI world. I assumed that by specifying scale or translate on a node eg Layer or DrawNode or even Sprite, I could read out the position or contentSize and know where the object is in the view port. But it is not so.

The cocos2d-x scene tree has nodes. The model for each node is it’s initial coordinates, size, scale etc. And translation, scaling, rotation etc gets eventually stored into bunch of matrix operations. When each node is rendered into the viewport, the scene tree is walked and every node includes it’s parents transforms and the cumulative matrix operations along with initial set of vertices are given to OpenGL.

OpenGL then applies the transforms to vertices and out comes the animations or whatever else you were trying to do. In my case, I am trying to restrict a translated/scaled layer to the phone viewport, using the viewport as an inverse bounding box.

For this to happen, I can’t read values from the layer because it’s always the same. Duh!! The way I solved it was by maintaining a Rect, total translation, and current scale of the target layer. Then at each touch input, I calculate the future position of the rect against the bounding box. The equations are pretty simple but boy it took some time getting to them :smile:

I’ll post the code after I get some sleep!