android - PhysicsWorld.setGravity(重力);

标签 android box2d andengine

enter image description here

好吧,我正在使用 andengine 和 box2d 扩展 你看,我的物体从地面(红色矩形)飞到相机的屋顶(黄色),我不明白这是怎么回事

这是我的代码的一部分,

@Override
public EngineOptions onCreateEngineOptions() {
    final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);

}

还有这个

@Override
protected Scene onCreateScene() {

    this.mEngine.registerUpdateHandler(new FPSLogger());

    this.mScene = new Scene();
    this.mScene.setBackground(new Background(256, 256, 256));

    this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GRAVITY_EARTH),false);
    this.mScene.registerUpdateHandler(this.mPhysicsWorld);

最佳答案

我认为您只需要像这样使用 -SensorManager.GRAVITY_EARTH:

this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, -SensorManager.GRAVITY_EARTH),false);

在 AndEngine AnchorCenter 分支中,您必须使用负值作为重力,以使您的物理对象下落,因为坐标系已更改。

关于android - PhysicsWorld.setGravity(重力);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673850/

相关文章:

java - 安卓/Java : Using EditText/getText to change public class string variable

java - Google 回合制匹配自定义匹配 UI

android - Android应用程序关闭/设置为后台时如何执行后台任务?

iphone - Apple A5 和 Apple A6 CPU 之间的浮点确定性

actionscript-3 - 将凹多边形分解为凸多边形

cocos2d-iphone - 将旋转角度转换为 Box2D 脉冲

android - Andengine Sprite 奇怪的行为

android - EditText 和 TabHost 不喜欢对方

android - 运行android应用程序时出现java.lang.UnsatisfiedLinkError

android - 想要获得 Sprite Touch 但不在透明区域