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

  • 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.

主站蜘蛛池模板: 穆棱市| 茶陵县| 万源市| 天祝| 田东县| 朝阳市| 竹北市| 沂南县| 达日县| 聊城市| 阿合奇县| 大竹县| 宜良县| 棋牌| 周口市| 隆德县| 图们市| 鄯善县| 环江| 原平市| 泰兴市| 苍南县| 新化县| 钦州市| 三台县| 盐源县| 建水县| 长治县| 巴彦淖尔市| 禹州市| 分宜县| 兴隆县| 岗巴县| 六枝特区| 永顺县| 津南区| 永州市| 闸北区| 斗六市| 华蓥市| 兴安盟|