ios - Spritekit - How to calculate the distance between two nodes?

后端 未结 5 963
有刺的猬
有刺的猬 2020-12-14 21:19

I have two sknodes on the screen. What is the best way to calculate the distance (\'as the crow flies\' type of distance, I don\'t need a vector etc)?

I\'ve had a go

5条回答
  •  死守一世寂寞
    2020-12-14 21:56

    Pythagorean theorem:

    - (float)getDistanceBetween:(CGPoint)p1 and:(CGPoint)p2 {
        return sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2));
    }
    

提交回复
热议问题