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

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.

主站蜘蛛池模板: 全州县| 叙永县| 武陟县| 昌乐县| 龙口市| 太谷县| 稻城县| 海原县| 汶川县| 抚松县| 齐齐哈尔市| 梨树县| 田东县| 紫金县| 克山县| 绵阳市| 花莲县| 孝昌县| 双柏县| 社会| 扎赉特旗| 肥城市| 社旗县| 宣威市| 宁晋县| 嫩江县| 祁门县| 井冈山市| 榕江县| 新宁县| 宜良县| 若尔盖县| 万州区| 高邑县| 海兴县| 武安市| 凤庆县| 若羌县| 昭通市| 云浮市| 扶余县|