滚动与物理相结合将我的精灵移出屏幕(Scrolling combined with physics moves my sprite out of the screen)

编程入门 行业动态 更新时间:2024-10-24 22:20:05
滚动与物理相结合将我的精灵移出屏幕(Scrolling combined with physics moves my sprite out of the screen)

我正在用SpriteKit实现一个侧滚动游戏:

只要我的精灵停留在屏幕中间,我就会移动精灵

当精灵到达屏幕的左侧或右侧时,我正在移动关卡而不是我的精灵:

这非常有效,除非我的精灵与另一个对象发生碰撞。 在这种情况下,水平(由我的代码触发)和精灵(由物理引擎触发)被移动,精灵移动到屏幕外:

我试图阻止从物理引擎施加的冲动。 这没效果。

知道如何处理这个吗?

谢谢Stefan

I'm implementing a side scrolling game with SpriteKit:

As long as my sprite stays in the middle of the screen, I'm moving the sprite

When the sprite reaches the left or the right part of the screen, I'm moving the level instead of my sprite:

This works quite well, unless my sprite collides with another object. In that case the level (triggered by my code) and the sprite (triggered by the physics engine) are moved and the sprite moves outside the screen:

I tried to stop the impulse which is applied from the physics engine. This hasn't worked.

Any idea how to handle this?

Thanks Stefan

最满意答案

我想通过“移动关卡”你的意思是移动背景视图。

你为什么不只有一个你的精灵移动的区域与你的背景大小相同? 您可以滚动以保持精灵可见而不会干扰物理逻辑和其他对运动的操纵。

I suppose by "moving the level" you mean moving the background view.

Why don't you just have an area in which your sprite moves that is the same size as your background? You can scroll to keep the sprite visible without disturbing the logic of physics and other manipulation of the movement.

更多推荐

本文发布于:2023-08-06 05:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:移出   屏幕   物理   精灵   Scrolling

发布评论

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

>www.elefans.com

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