Erase Box: the tutorial
2009-10-30 00:00:00 来源:WEB开发网This is a modified version of Emanuele’s script: Box2D: tutorial for the absolute beginners
So I will only comment the changes:
Line 14: Creating a variable to keep track of the number of boxes created.
Line 40: Defining the_box as a sensor.
Lines 41 and 45: Setting up the userData for both sensors, so Box2D will be able to distinguish between them and other bodies.
Line 63: Setting the randomly generated box userData to the variable “i” (that keeps track of the number of boxes created).
Line 67: Increasing “i”
Lines 73 to 86: Setting up the contact listener:
73: Checking if m_contactList is not null.
75: Defining variable contact.
77 and 82: m_conctactList will also check for contact between boxes. This will make sure that it will only execute the lines below on the bodies that we want.
78: Tracing the box userdata (”i” at the time it was created)
83 and 84: Defining body2 as the second object in contact and then destroying it. It is also possible to add “&& contact.GetShape2().GetBody().GetUserData() == 5” to the if function, so it will only execute on the fifth body, i.e.
It is also possible to create non-0-density boxes as sensors, and attach them to bodies, but this is for another tutorial :) »
This is the result:
本文示例源代码或素材下载
- ››Box制作完整台灯过程解析
- ››TheServerSide网站2009年最热文章
- ››The Netron Project For vb.net
- ››The engine behind Splitter Flash game : workin...
- ››The engine behind Splitter Flash game – first...
- ››Erase Box: the tutorial
- ››The engine behind Splitter Flash game – new A...
- ››Box2D joints: Gear Joints
- ››Box2D breakout prototype
- ››Box2D platform engine alternative
- ››The Standard C Library for Linux
- ››The File System(文件系统)
更多精彩
赞助商链接