【问题标题】:andengine load angled rectangle和发动机负载成角度的矩形
【发布时间】:2014-11-12 11:30:39
【问题描述】:

我在 Gles2 中使用 AndEngine LevelLoader 来加载构成游戏墙的矩形。

<entity x="0" y="477" width="800" height="10" type="wall"/>
<entity x="800" y="477" width="240" height="10" angle="315" type="wall"/>

并使用以下代码创建矩形

Rectangle rect = new Rectangle(x, y,
            width, height, activity.getVertexBufferObjectManager());
    rect.setRotation(angle); 
    Body block = PhysicsFactory.createBoxBody(this.mPhysicsWorld, rect,
            BodyType.StaticBody, objectFixtureDef);

它有效,但我想要下面的图片演示会发生什么。是否有任何公式可以计算出矩形的起始 Y 值使其相遇,或者如何转换矩形以使其与另一个矩形相邻?

提前致谢。

【问题讨论】:

  • 您使用的是 GLES 2.0 Anchor Center?
  • 不,不是 Anchor Center,只是 GLES 2 分支。

标签: box2d andengine trigonometry


【解决方案1】:

Entity 类中,您有一个名为setRotationCenter 的函数, 您可以使用它来更改旋转实体的位置。默认情况下,它被初始化为位于实体的中心。

使用:

rect.setRotationCenter(0,0)

【讨论】:

  • 谢谢,我试过了,但现在我得到的有角度的矩形在水平方向上方浮动了一些距离 Rectangle rect = new Rectangle(x, y, width, height, activity.getVertexBufferObjectManager()); rect.setRotationCenter(0, 0); rect.setRotation(角度);
  • 另外,设置rotationCenter 并不会同时更新body,所以东西会在没有旋转的情况下从矩形的原始位置反弹。
  • 我的错,对不起.. 不是 Box2D 扩展的专家。这可能对你有帮助吗? andengine.org/forums/post24493.html#p24493
猜你喜欢
  • 1970-01-01
  • 2014-07-22
  • 1970-01-01
  • 1970-01-01
  • 2014-12-31
  • 2021-07-18
  • 2019-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多