- 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.
- 數(shù)據(jù)產(chǎn)品經(jīng)理高效學(xué)習(xí)手冊(cè):產(chǎn)品設(shè)計(jì)、技術(shù)常識(shí)與機(jī)器學(xué)習(xí)
- 數(shù)據(jù)可視化:從小白到數(shù)據(jù)工程師的成長(zhǎng)之路
- Python數(shù)據(jù)挖掘:入門、進(jìn)階與實(shí)用案例分析
- 輕松學(xué)大數(shù)據(jù)挖掘:算法、場(chǎng)景與數(shù)據(jù)產(chǎn)品
- Test-Driven Development with Mockito
- Python數(shù)據(jù)分析、挖掘與可視化從入門到精通
- Access 2016數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用
- Hadoop大數(shù)據(jù)實(shí)戰(zhàn)權(quán)威指南(第2版)
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- HikariCP連接池實(shí)戰(zhàn)
- 爬蟲(chóng)實(shí)戰(zhàn):從數(shù)據(jù)到產(chǎn)品
- 貫通SQL Server 2008數(shù)據(jù)庫(kù)系統(tǒng)開(kāi)發(fā)
- Spring MVC Beginner’s Guide
- 利用Python進(jìn)行數(shù)據(jù)分析(原書(shū)第2版)
- AndEngine for Android Game Development Cookbook