物理编辑器不允许缩放精灵(Andengine)

时间:2014-05-09 05:56:27

标签: android andengine sprite physics game-physics

在我的游戏中,我使用了物理编辑器作为精灵。我将它缩放到像这样的大尺寸

 sprite.setScale(screenwidth/20 / sprite.getWidth());

并将它添加到像这样的物理体

 Body = PhysicsFactory.createBoxBody(physicsWorld, sprite, BodyType.DynamicBody, FIXTURE_DEF);

现在在游戏中,精灵在缩放时看起来很大,但附着在它上面的物理体很小。(没有像缩放那样增加尺寸)。

那么现在该做些什么来扩展身体本身。 请给我一些想法。

1 个答案:

答案 0 :(得分:0)

  1. 首先,将以下fixture定义插入onPopulateScene()方法:

    FixtureDef BoxBodyFixtureDef =
    PhysicsFactory.createFixtureDef(20f, 0f, 0.5f);
    
  2. 接下来,放置以下代码,创建三个矩形及其对应的代码 在上一步的夹具定义之后的实体:

    Rectangle staticRectangle = new Rectangle(cameraWidth /
    2f,75f,400f,40f,this.getVertexBufferObjectManager());
    staticRectangle.setColor(0.8f, 0f, 0f);
    mScene.attachChild(staticRectangle);
    PhysicsFactory.createBoxBody(mPhysicsWorld, staticRectangle,
    BodyType.StaticBody, BoxBodyFixtureDef);
    
    Rectangle dynamicRectangle = new Rectangle(400f, 120f, 40f, 40f,
    this.getVertexBufferObjectManager());
    dynamicRectangle.setColor(0f, 0.8f, 0f);
    mScene.attachChild(dynamicRectangle);
    Body dynamicBody = PhysicsFactory.createBoxBody(mPhysicsWorld,
    dynamicRectangle, BodyType.DynamicBody, BoxBodyFixtureDef);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
    dynamicRectangle, dynamicBody);
    
    Rectangle kinematicRectangle = new Rectangle(600f, 100f,
    40f, 40f, this.getVertexBufferObjectManager());
    kinematicRectangle.setColor(0.8f, 0.8f, 0f);
    mScene.attachChild(kinematicRectangle);
    Body kinematicBody = PhysicsFactory.createBoxBody(mPhysicsWorld,
    kinematicRectangle, BodyType.KinematicBody, BoxBodyFixtureDef);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
    kinematicRectangle, kinematicBody);
    
  3. 最后,在上一步的定义之后添加以下代码来设置 我们的运动体的线性和角速度:

  4.   

    kinematicBody.setLinearVelocity(-2f,0f);
      kinematicBody.setAngularVelocity((float)( - Math.PI));