首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何镜像CGPoint

如何镜像CGPoint
EN

Stack Overflow用户
提问于 2013-03-16 17:53:32
回答 1查看 670关注 0票数 2

我不想将触摸点围绕屏幕中心旋转180度(镜像)。我试过ccpRotateByAngle(screenCenter, touchPoint, 180),但它给了我错误的数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-16 18:10:40

三角学的救星:

代码语言:javascript
复制
// 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:

代码语言:javascript
复制
touchPointToCenter: {240, 160} - {200, 200} = {40, -40}
mirror: {240, 160} + {40, -40} = {280, 120}

镜像点是280,120。

注意:我使用的函数来自cocos2d-iphone。我假设它们也存在于cocos2d-x中。他们可能有不同的名字,我不确定。您还可以像我在示例中所做的那样“手动”运行计算。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15447857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档