cocos2d-x动作类游戏,人物排序(层次关系)

 1 void WGBattleLayer::RoleSeqencingZ()
2 {
3 int length = (int)this->vector_All_Roles_->size();
4 for (int i=0;i<length;i++)
5 {
6 for (int j=0;j<length - i - 1;j++)
7 {
8 //NO.1
9 WGRole* RoleA = this->vector_All_Roles_->at(j);
10 WGRole* RoleB = this->vector_All_Roles_->at(j + 1);
11 if (RoleA != NULL && RoleB != NULL)
12 {
13 if (RoleA->getRoleCurrentHealthPoint() > 0 && RoleB->getRoleCurrentHealthPoint() > 0)
14 {
15 CCRect tempRectA = RoleA->GetTouchRect();
16 CCRect tempRectB = RoleB->GetTouchRect();
17 //NO.2 矩形相交
18 if ( true == CCRect::CCRectIntersectsRect(tempRectA,tempRectB))
19 {
20 int A_Z = RoleA->getZOrder();
21 int B_Z = RoleB->getZOrder();
22 CCPoint A_P = RoleA->GetBottomPoint();
23 CCPoint B_P = RoleB->GetBottomPoint();
24 //NO.3 更改Z
25 if(A_P.y < B_P.y)
26 {
27 if (A_Z < B_Z)
28 {
29 this->reorderChild(RoleA,B_Z);
30 this->reorderChild(RoleB,A_Z);
31 }
32 }else{
33 if (A_Z > B_Z)
34 {
35 this->reorderChild(RoleA,B_Z);
36 this->reorderChild(RoleB,A_Z);
37 }
38 }
39 }
40 }
41 }
42 }
43 }
44 }

http://user.qzone.qq.com/418319859/blog/1325057411

posted on 2011-12-28 15:32  游戏开发:主席  阅读(2352)  评论(0编辑  收藏  举报

导航