2

画面の中心を中心にタッチポイントを180度回転させたくありません(ミラーリングします)。を試しccpRotateByAngle(screenCenter, touchPoint, 180)ましたが、間違ったデータが返されました。

4

1 に答える 1

4

救助のための三角法:

// 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にも存在すると思います。名前が違うかもしれませんが、よくわかりません。例で行ったように、「手動で」計算を実行することもできます。

于 2013-03-16T10:10:40.383 に答える