Box2D V2.x中SetAsEdge的替代方法
来源:互联网 发布:淘宝退款被卖家拒绝了 编辑:程序博客网 时间:2024/05/21 17:01
// Define the ground body.
; b2BodyDef groundBodyDef
.position.Set(0, 0); // bottom-left corner groundBodyDef
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
= world->CreateBody(&groundBodyDef); groundBody
// Define the ground box shape.
; b2PolygonShape groundBox // bottom
.SetAsEdge(b2Vec2(0,FLOOR_HEIGTH/PTM_RATIO),b2Vec2(screenSize.width*2.0f/PTM_RATIO,FLOOR_HEIGTH/PTM_RATIO)); groundBox
->CreateFixture(&groundBox,0); groundBody
// top
.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO),b2Vec2(screenSize.width*2.0f/PTM_RATIO,screenSize.height/PTM_RATIO)); groundBox
->CreateFixture(&groundBox,0); groundBody
// left
.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0)); groundBox
->CreateFixture(&groundBox,0); groundBody
// right
.SetAsEdge(b2Vec2(screenSize.width*2.0f/PTM_RATIO,screenSize.height/PTM_RATIO),b2Vec2(screenSize.width*2.0f/PTM_RATIO,0)); groundBox
->CreateFixture(&groundBox,0); groundBody
Box2D v2.*中API已经移除了v1.*中的SetAsEdge方法,所以我们可以用如下方法来替换SetAsEdge方法
用b2EdgeShape 而不是 b2PolygonShape,直接用b2EdgeShape的Set方法来替换
// for the screenBorder body we'll need these values
CGSize screenSize = [CCDirector sharedDirector].winSize;
float widthInMeters = screenSize.width / PTM_RATIO;
float heightInMeters = screenSize.height / PTM_RATIO;
= b2Vec2(0, 0); b2Vec2 lowerLeftCorner
= b2Vec2(widthInMeters, 0); b2Vec2 lowerRightCorner
= b2Vec2(0, heightInMeters); b2Vec2 upperLeftCorner
= b2Vec2(widthInMeters, heightInMeters); b2Vec2 upperRightCorner
// Define the static container body, which will provide the collisions at screen borders.
; b2BodyDef screenBorderDef
.position.Set(0, 0); screenBorderDef
* screenBorderBody = world->CreateBody(&screenBorderDef); b2Body
; b2EdgeShape screenBorderShape
// Create fixtures for the four borders (the border shape is re-used)
.Set(lowerLeftCorner, lowerRightCorner); screenBorderShape
->CreateFixture(&screenBorderShape, 0); screenBorderBody
.Set(lowerRightCorner, upperRightCorner); screenBorderShape
->CreateFixture(&screenBorderShape, 0); screenBorderBody
.Set(upperRightCorner, upperLeftCorner); screenBorderShape
->CreateFixture(&screenBorderShape, 0); screenBorderBody
.Set(upperLeftCorner, lowerLeftCorner); screenBorderShape
->CreateFixture(&screenBorderShape, 0); screenBorderBody
- Box2D V2.x中SetAsEdge的替代方法
- box2d 中常用的方法
- cocos2d-x中box2d的关节
- cocos2d-x中使用box2d物理引擎时,开启debugDraw的方法
- Cocos2d-X Box2D中部分方法的重点理解
- cocos2d-x中使用box2d时的PTM_RATIO
- Cocos2d-x中Box2d示例无法运行的问题
- Cocos2d-x Box2d中实现刚体的移动
- Cocos2d-X Box2D的基本知识
- Cocos2d-x v2.1 中 setResourceDirectory() 方法不再可用
- Flex中替代cookit操作的方法
- Flex中替代cookit操作的方法
- Flex中替代cookit操作的方法
- access 中 case 的替代方法
- FireFox中替代onpropertychange事件的方法
- 在HQL语句中,替代?的方法
- Access中替代case when的方法
- Hibernate中session.connection()的替代方法
- 《Head First设计模式》 读书笔记05 工厂模式(二)
- tcp/ip详解----杂记三
- 自考——信息资源管理
- 黑马程序员----JAVA基础CSS javaScript DOM
- 新建Android AVD,点击start、launch,出现进度条后无任何反应,也没报错(可能的问题及解决方法)
- Box2D V2.x中SetAsEdge的替代方法
- hdu 1213how many tables
- HEVC学习(十六) —— SAO函数解析之四
- 改变D3D中的渲染状态---SetRenderState
- hdu 4473 Exam
- 《c和指针》笔记--trigrph
- 设计模式学习日记二(持续更新)
- Undefined symbols for architecture i386 ...
- Ado.Net项目开发教程