我不想将触摸点围绕屏幕中心旋转180度(镜像)。我试过ccpRotateByAngle(screenCenter, touchPoint, 180),但它给了我错误的数据。
发布于 2013-03-16 18:10:40
三角学的救星:
// get your center in some way, here I'm using fixed coordinates 'cuz I'm lazy
CGPoint screenCenter = ccp(240, 160);
// this creates the vector between center and touch location
CGPoint touchPointToCenter = ccpSub(screenCenter, touchPoint);
// just add the vector to screen center and you mirrored it around center
CCPoint mirror = ccpAdd(screenCenter, touchPointToCenter);例如,假设你的触摸点是200,200:
touchPointToCenter: {240, 160} - {200, 200} = {40, -40}
mirror: {240, 160} + {40, -40} = {280, 120}镜像点是280,120。
注意:我使用的函数来自cocos2d-iphone。我假设它们也存在于cocos2d-x中。他们可能有不同的名字,我不确定。您还可以像我在示例中所做的那样“手动”运行计算。
https://stackoverflow.com/questions/15447857
复制相似问题