@shipit wrote:
Basically I don't want the user to move/scale the sprite offscreen. For moving it's super easy, here's my working solution:
bool CoordsTest::onGesturePan(TGesturePan *gesture) { Vec2 delta = gesture->getTranslation(); Rect contentRect = _contentNode->getBoundingBox(); contentRect.origin += delta; if (contentRect.containsPoint(_screenMinPoint) && contentRect.containsPoint(_screenMaxPoint)) { _contentNode->setPosition(_contentNode->getPosition() + delta); } return true; }
It works great! Here's another way I tried that isn't working and I want to figure this out in case I want to add scale/rotation operations:
bool CoordsTest::onGesturePan(TGesturePan *gesture) { Vec2 delta = gesture->getTranslation(); Rect contentRect = _contentNode->getBoundingBox(); AffineTransform transform = _contentNode->getNodeToWorldAffineTransform(); transform = AffineTransformTranslate(transform, delta.x, delta.y); contentRect = RectApplyAffineTransform(contentRect, transform); if (contentRect.containsPoint(_screenMinPoint) && contentRect.containsPoint(_screenMaxPoint)) { _contentNode->setPosition(_contentNode->getPosition() + delta); } return true; }
This does not work. I think my starting transform ie
_contentNode->getNodeToWorldAffineTransform()
maybe wrong.help?! thx!
Posts: 2
Participants: 1