这段是b2Island.as的方法..
//if (minSleepTime >= b2Settings.b2_timeToSleep)
这个是BOX2D原来的判定...
b2Settings.b2_timeToSleep指向的值是0.5
minSleepTime 是根据时间步的值来增加的..
如果只有一个刚体..时间步是1/24的话..即使要休眠也达不到0.5的要求..
b2Settings.b2_timeToSleep的意思是最小休眠时间....
不过0.5一样还有问题...
于是我就把这段函数改了下..
增加了两句:
var needSleep:Boolean = true;
needSleep = contactsOkay && needSleep;
并把判定改为:
minSleepTime >= step.dt && needSleep
这样位置修正也没问题..也可以休眠了
1
Report(contactSolver.m_constraints);
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
if
(allowSleep)
{
6![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
8![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
var minSleepTime:Number = Number.MAX_VALUE;
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
12![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
var linTolSqr:Number = b2Settings.b2_linearSleepTolerance * b2Settings.b2_linearSleepTolerance;
14![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
var angTolSqr:Number = b2Settings.b2_angularSleepTolerance * b2Settings.b2_angularSleepTolerance;
16![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
18![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
for (i = 0; i < m_bodyCount; ++i)
20![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
b = m_bodies[i];
24![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
if (b.m_invMass == 0.0)
26![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
28![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
continue;
30![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
}
32![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
34![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
if ((b.m_flags & b2Body.e_allowSleepFlag) == 0 ||
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
b.m_angularVelocity * b.m_angularVelocity > angTolSqr ||
38![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
b2Math.b2Dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr)
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
b.m_sleepTime = 0.0;
44![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
minSleepTime = 0.0;
46![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
}
48![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
else
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
52![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
b.m_sleepTime += step.dt;
54![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
minSleepTime = b2Math.b2Min(minSleepTime, b.m_sleepTime);
56![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
}
58![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
}
60![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
if (minSleepTime >= step.dt && needSleep)
63![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
for (i = 0; i < m_bodyCount; ++i)
67![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
69![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
b = m_bodies[i];
71![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
if ( b.m_sleepTime >= step.dt)
73![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
75![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
b.m_flags |= b2Body.e_sleepFlag;
77![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
b.m_linearVelocity.SetZero();
79![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
b.m_angularVelocity = 0.0;
81![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
}
83![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
}
85![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
上面的代码还是有点问题,改了后.会无缘无故的漂浮..
但是可以增加是否有碰撞..就可以解决无缘无故的漂浮..
..我给BODY类加了一个碰撞属性..
碰撞时改为TRUE..
然后睡眠时再判定是不是有碰撞..
具体代码我就不贴了..