在ontouchesBegan中,touches.size()一直是1。这对多点缩放图片,三维模型来说,挺郁闷的。本文把初始值放在ontouchesMoved 中,基本解决问题,但有一小点问题,就是第一次触摸时有小范围的缩放,因为只有移动才可以得出新的距离,但是此时的距离一定不等于之前的距离。对我的项目够了,不知道其它人能不能用。
voID CocaineLayer::ontouchesMoved(const std::vector<touch*>& touches,cocos2d::Event *event) { if (touches.size() >= 2) { if (multouchesFlag) { auto t0 = touches[0]; auto t1 = touches[1]; auto location0 = t0->getLocation(); auto location1 = t1->getLocation(); _olddis = (float) sqrt((location0.x - location1.x) * (location0.x - location1.x) + (location0.y - location1.y) * (location0.y - location1.y)); multouchesFlag = false; } else { auto t0 = touches[0]; auto t1 = touches[1]; auto location0 = t0->getLocation(); auto location1 = t1->getLocation(); float newdis = (float) sqrt((location0.x - location1.x) * (location0.x - location1.x) + (location0.y - location1.y) * (location0.y - location1.y)); _scale *= newdis / _olddis; _model->setScale(_scale * 0.01f); if (_scale > 10.0f) { _scale = 10.0f; } if (_scale < 0.7f) { _scale = 0.7f; } _olddis = newdis; } }}
voID CocaineLayer::ontouchesEnded(const std::vector<touch*>& touches,cocos2d::Event *event) { multouchesFlag = true;}仅供参考 总结
以上是内存溢出为你收集整理的cocos2d-x 两点缩放全部内容,希望文章能够帮你解决cocos2d-x 两点缩放所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)