首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >探测火焰发动机屏幕底部的碰撞?

探测火焰发动机屏幕底部的碰撞?
EN

Stack Overflow用户
提问于 2021-09-05 20:33:17
回答 1查看 512关注 0票数 0

按照示例这里,是否有可能检测到与屏幕特定一侧(例如屏幕底部)的冲突?

颤振版本: 2.2.3

火焰版本:1.0.0-释放

onCollision方法的MyCollidable类

代码语言:javascript
复制
@override
  void onCollision(Set<Vector2> intersectionPoints, Collidable other) {
    if (other is ScreenCollidable) {
      _isWallHit = true;
      // Detect which side?
      return;
    }
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-06 09:39:25

这方面没有内置的方法,但是您可以很容易地计算出您是在与使用游戏的大小发生碰撞,并将碰撞点转换为屏幕坐标(如果您不更改缩放级别或移动相机,则无需此步骤)。

代码应该是这样的:

代码语言:javascript
复制
class MyCollidable extends PositionComponent
    with Hitbox, Collidable, HasGameRef {
  
  ...

  void onCollision(Set<Vector2> intersectionPoints, Collidable other) {
    if (other is ScreenCollidable) {
      _isWallHit = true;
      final firstPoint = intersectionPoints.first;
      // If you don't move/zoom the camera this step can be skipped
      final screenPoint = gameRef.projectVector(firstPoint);
      final screenSize = gameRef.size;
      if (screenPoint.x == 0) {
        // Left wall (or one of the leftmost corners)
      } else if (screenPoint.y == 0) {
        // Top wall (or one of the upper corners)
      } else if (screenPoint.x == screenSize.x) {
        // Right wall (or one of the rightmost corners)
      } else if (screenPoint.y == screenSize.y) {
        // Bottom wall (or one of the bottom corners)
      }
      return;
    }
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69067010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档