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

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.

主站蜘蛛池模板: 全州县| 南阳市| 波密县| 红原县| 内乡县| 河北区| 西和县| 惠东县| 沭阳县| 丰宁| 伽师县| 许昌市| 库尔勒市| 股票| 措美县| 穆棱市| 随州市| 和硕县| 车险| 明光市| 建水县| 桃园县| 徐州市| 宜城市| 合江县| 乌拉特后旗| 台北市| 壶关县| 黑龙江省| 荣成市| 繁昌县| 南昌市| 泗洪县| 陇南市| 崇阳县| 正镶白旗| 永宁县| 德保县| 克东县| 定兴县| 仪征市|