WEB开发网
开发学院图形图像Flash Erase Box: the tutorial 阅读

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 beginnersSo I will only comment the changes:Line 14: Creatin

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:

本文示例源代码或素材下载

上一页  1 2 

Tags:Erase Box the

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接