大佬教程收集整理的这篇文章主要介绍了ios – Sprite Kit – 使用Impulse在角色上射击射弹,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>计算从抛射物发射器到鸟类的矢量分量@H_262_28@>标准化组件(可选)@H_262_28@>通过缩放(标准化)组件来创建矢量@H_262_28@>使用矢量向射弹施加冲动
这是一个如何做到这一点的例子
// Calculate vector components x and y CGFloat dx = bird.position.x - launcher.position.x; CGFloat dy = bird.position.y - launcher.position.y; // Normalize the components CGFloat magnitude = sqrt(dx*dx+dy*dy); dx /= magnitude; dy /= magnitude; // Create a vector in the direction of the bird CGVector vector = CGVectorMake(strength*dx,strength*dy); // Apply impulse [projectile.physicsBody applyImpulse:vector];
迅速
// Calculate vector components x and y var dx = bird.position.x - launcher.position.x var dy = bird.position.y - launcher.position.y // Normalize the components let magnitude = sqrt(dx*dx+dy*dy) dx /= magnitude dy /= magnitude // Create a vector in the direction of the bird let vector = CGVector(dx:strength*dx,dy:strength*dy) // Apply impulse projectile.physicsBody?.applyImpulse(vector)
以上是大佬教程为你收集整理的ios – Sprite Kit – 使用Impulse在角色上射击射弹全部内容,希望文章能够帮你解决ios – Sprite Kit – 使用Impulse在角色上射击射弹所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。