Android游戏开发学习之引擎用法实例详解

2019-12-10 20:00:43于丽
  • shape.density=1.0f;   }  
  • shape.friction=0.0f; //设置摩擦系数   shape.restitution=0.6f; //设置能量损失率  
  • shape.setAsBox(halfWidth/RATE, halfHeight/RATE);   BodyDef bodyDef=new BodyDef(); //创建刚体描述对象  
  • bodyDef.position.set(x/RATE,y/RATE); //设置位置   Body bodyTemp=world.createBody(bodyDef); //在世界中创建刚体  
  • bodyTemp.createShape(shape); //指定刚体形状   bodyTemp.setMassFromShapes(); //设置物体质量  
  • return new MyRectColor(bodyTemp, halfWidth, halfHeight, color);  }  
  • /**   * 创建圆形物体(颜色)  
  • */  public static MyCircleColor createCircle (  
  • float x,   float y,  
  • float radius,   World world,  
  • int color   ) {  
  • CircleDef shape=new CircleDef(); //创建圆描述对象   shape.density=2; //设置密度  
  • shape.friction=0.0f; //设置摩擦系数   shape.restitution=0.95f; //设置能量损失率  
  • shape.radius=radius/RATE;//设置半径   BodyDef bodyDef=new BodyDef(); //创建刚体描述对象  
  • bodyDef.position.set(x/RATE,y/RATE); //设置位置   Body bodyTemp=world.createBody(bodyDef); //在世界中创建刚体  
  • bodyTemp.createShape(shape); //指定刚体形状   bodyTemp.setMassFromShapes(); //设置物体质量  
  • return new MyCircleColor(bodyTemp, radius, color);   }