だから私はランダムな位置で毎秒スプライトを作成します。私が望むのは、スプライトが画面の中央に向けられることです。たとえば、ランダムな位置で毎秒人体を作成する場合、頭を画面の中心に向けたいと思います。ありがとう :) 私の英語でごめんなさい 私はフランス人です :/
2 に答える
0
CCPoint pos1 = [yourHuman position];
CCPoint pos2 = screenCenter;
float theta = atan((pos1.y-pos2.y)/(pos1.x-pos2.x)) * 180 * 7 /22;
if(pos1.y - pos2.y > 0)
{
if(pos1.x - pos2.x < 0)
{
[yourHuman setRotation:(-90-theta)];
}
else if(pos1.x - pos2.x > 0)
{
[yourHuman setRotation:(90-theta)];
}
}
else if(pos1.y - pos2.y < 0)
{
if(pos1.x - pos2.x < 0)
{
[yourHuman setRotation:(270-theta)];
}
else if(pos1.x - pos2.x > 0)
{
[yourHuman setRotation:(90-theta)];
}
}
これが行われます。このコードをメソッドに保持します。そしてそれを使用してください..:)これが役立つことを願っています..
于 2012-05-02T18:29:30.617 に答える
0
CGPoint screenCenter = ...; // set it manually or from device screen size
CGPoint direction = ccpSub (screenCenter, yourHuman.position);
yourHuman.rotation = CC_RADIANS_TO_DEGREE (ccpToAngle (direction));
回転角度についてはよくわからないので、必要になるかもしれません
yourHuman.rotation = -CC_RADIANS_TO_DEGREE (ccpToAngle (direction));
于 2012-05-02T14:49:23.267 に答える