com.badlogic.gdx.physics.box2d.Body.setAwake()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中com.badlogic.gdx.physics.box2d.Body.setAwake()方法的一些代码示例,展示了Body.setAwake()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.setAwake()方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:setAwake

Body.setAwake介绍

[英]Set the sleep state of the body. A sleeping body has very low CPU cost.
[中]设置身体的睡眠状态。睡眠体的CPU成本非常低。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public boolean touchDown (int x, int y, int pointer, int newParam) {
  // translate the mouse coordinates to world coordinates
  testPoint.set(x, y, 0);
  camera.unproject(testPoint);
  // ask the world which bodies are within the given
  // bounding box around the mouse pointer
  hitBody = null;
  world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);
  // if we hit something we create a new mouse joint
  // and attach it to the hit body.
  if (hitBody != null) {
    MouseJointDef def = new MouseJointDef();
    def.bodyA = groundBody;
    def.bodyB = hitBody;
    def.collideConnected = true;
    def.target.set(testPoint.x, testPoint.y);
    def.maxForce = 1000.0f * hitBody.getMass();
    mouseJoint = (MouseJoint)world.createJoint(def);
    hitBody.setAwake(true);
  } else {
    for (Body box : boxes)
      world.destroyBody(box);
    boxes.clear();
    createBoxes();
  }
  return false;
}

代码示例来源:origin: libgdx/libgdx

@Override
public boolean touchDown (int x, int y, int pointer, int button) {
  // translate the mouse coordinates to world coordinates
  camera.unproject(testPoint.set(x, y, 0));
  // ask the world which bodies are within the given
  // bounding box around the mouse pointer
  hitBody = null;
  world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f);
  if (hitBody == groundBody) hitBody = null;
  // ignore kinematic bodies, they don't work with the mouse joint
  if (hitBody != null && hitBody.getType() == BodyType.KinematicBody) return false;
  // if we hit something we create a new mouse joint
  // and attach it to the hit body.
  if (hitBody != null) {
    MouseJointDef def = new MouseJointDef();
    def.bodyA = groundBody;
    def.bodyB = hitBody;
    def.collideConnected = true;
    def.target.set(testPoint.x, testPoint.y);
    def.maxForce = 1000.0f * hitBody.getMass();
    mouseJoint = (MouseJoint)world.createJoint(def);
    hitBody.setAwake(true);
  }
  return false;
}

代码示例来源:origin: libgdx/libgdx

player.setAwake(true);

代码示例来源:origin: MovingBlocks/box2d-editor

@Override
  public void onEvent(int type, BaseTween<?> source) {
    if (idx < ballModels.length) {
      ballModels[idx].setAwake(true);
      ballModels[idx].setActive(true);
      idx += 1;
    }
  }
}).repeat(-1, 0.1f).start(tweenManager);

代码示例来源:origin: dsaltares/libgdx-cookbook

@Override
public boolean touchDown (int x, int y, int pointer, int button) {
  // Mouse coordinates to world coordinates
  viewport.getCamera().unproject(point.set(x, y, 0));
  
  if(button == Input.Buttons.RIGHT) {
    hitBody = null;
    
    // Check if a interactive body has been right-clicked
    world.QueryAABB(callback, point.x - 0.0001f, point.y - 0.0001f, point.x + 0.0001f, point.y + 0.0001f);
    
    if (hitBody == groundBody) hitBody = null;
    
    // if we hit an interactive body we create a new mouse joint
    // and attach it to the hit body.
    if (hitBody != null) {
      MouseJointDef def = new MouseJointDef();
      def.bodyA = groundBody;
      def.bodyB = hitBody;
      def.collideConnected = true;
      def.target.set(point.x, point.y);
      def.maxForce = 1000.0f * hitBody.getMass();
      mouseJoint = (MouseJoint)world.createJoint(def);
      hitBody.setAwake(true);
    }
  }
  return false;
}

代码示例来源:origin: lycying/c2d-engine

@Override
public boolean touchDown (int x, int y, int pointer, int newParam) {
  if(world == null)return false;
  // translate the mouse coordinates to world coordinates
  testPoint.set(Engine.screenToWorld(x, y).scl(1/Box2dObject.RADIO));
  // ask the world which bodies are within the given
  // bounding box around the mouse pointer
  hitBody = null;
  world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);
  // if we hit something we create a new mouse joint
  // and attach it to the hit body.
  if (hitBody != null) {
    MouseJointDef def = new MouseJointDef();
    def.bodyA = fixBody;
    def.bodyB = hitBody;
    def.collideConnected = true;
    def.target.set(testPoint.x, testPoint.y);
    def.maxForce = 1000.0f * hitBody.getMass();
    mouseJoint = (MouseJoint)world.createJoint(def);
    hitBody.setAwake(true);
    
    return true;
  } 
  return false;
}

代码示例来源:origin: dsaltares/libgdx-cookbook

private Body createSharpObject() {
  ChainShape chainShape = new ChainShape();
  
  chainShape.createLoop(new Vector2[] {
      new Vector2(.0f, .375f), 
      new Vector2(.125f, .125f), 
      new Vector2(.375f, 0f),
      new Vector2(.125f, -.125f),
      new Vector2(0, -.375f),
      new Vector2(-.125f, -.125f),
      new Vector2(-.375f, 0f),
      new Vector2(-.125f, .125f),});
  
  BodyDef chainBodyDef = new BodyDef();
  chainBodyDef.type = BodyType.KinematicBody;
  chainBodyDef.bullet = true;
  chainBodyDef.position.set(SCENE_WIDTH*.5f, SCENE_HEIGHT*.5f);
  Body chainBody = world.createBody(chainBodyDef);
  chainBody.createFixture(chainShape, 0.8f);
  chainShape.dispose();
  
  chainBody.setAwake(true);
  
  return chainBody;
}

代码示例来源:origin: dsaltares/libgdx-cookbook

hitBody.setAwake(true);

相关文章