官术网_书友最值得收藏!

  • Box2D for Flash Games
  • Emanuele Feronato
  • 156字
  • 2021-08-05 18:44:26

Creating a circular shape

A shape is a 2D geometrical object, such as a circle or a polygon, which in this case must be convex (every internal angle must be less than 180 degrees). Remember, Box2D can only handle convex shapes.

At the moment, we are starting with the ball, so we'll create the circle:

var circleShape:b2CircleShape;
circleShape=new b2CircleShape(25/worldScale);

b2CircleShape is used to create a circular shape, and its constructor wants the radius as an argument. With the previous lines, we are creating a circle whose radius is 25 pixels, thanks to our friend—the worldScale variable. From now on, every time you want to work with pixels, you'll have to divide them by worldScale. You can also define a function called, let's say, pixelsToMeters , and call it every time you need to convert pixels to meters.

When we have a body definition and a shape, we can glue them together using a fixture.

主站蜘蛛池模板: 渭南市| 新丰县| 石阡县| 房山区| 清涧县| 南漳县| 广丰县| 道真| 尼木县| 阳新县| 依安县| 陇西县| 嘉祥县| 宁蒗| 屯留县| 余庆县| 沂源县| 长阳| 鹿邑县| 叶城县| 民乐县| 怀柔区| 峨山| 黄大仙区| 嫩江县| 高邮市| 肇源县| 新营市| 武宣县| 喜德县| 安阳县| 营山县| 竹山县| 大庆市| 吴旗县| 汉阴县| 芜湖县| 西城区| 蓝田县| 仲巴县| 南陵县|