SpriteKit physicsBody applyImpulse节点失败(SpriteKit physicsBody applyImpulse node fails)

编程入门 行业动态 更新时间:2024-10-21 13:41:54
SpriteKit physicsBody applyImpulse节点失败(SpriteKit physicsBody applyImpulse node fails)

我正在尝试在触摸屏操作上创建跳转事件,但在applyImpulse之后,我的精灵会通过另一个(在屏幕底部)失败。 有些参数看起来不错,但有时会发生。

码:

[self.physicsBody applyImpulse:CGVectorMake(dx / mag * kImpuleScale,20.0f)];

I'm trying to create a jump event on touch screen action, but after applyImpulse my sprite is fails through another(which at the bottom of the screen). With some parameters everything looks good, but sometimes it happen.

Code:

[self.physicsBody applyImpulse:CGVectorMake(dx/mag*kImpuleScale, 20.0f)];

最满意答案

你可以将物理身体放在你的屏幕上,只需:

var borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame) self.physicsBody = borderBody

然后没有身体可以“逃脱”

you can put a physicsBody around your Screen simply with:

var borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame) self.physicsBody = borderBody

Then no body can "escape"

更多推荐

本文发布于:2023-04-29 12:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336366.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   physicsBody   SpriteKit   applyImpulse   fails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!