Home  >  Article  >  Database  >  cocs2d

cocs2d

WBOY
WBOYOriginal
2016-06-07 15:00:301601browse

在cocos2d-x中利用box2d开发游戏的时, world提供的debugdraw是一个很便捷的功能。但是使用时经常有人遇到,照着box2dtest中的做了,确看不到显示结果的情况。实际上并不是没有画出来,而是world-DrawDebugData();的结果被我们的背景或者sprite图片给遮盖了

    在cocos2d-x中利用box2d开发游戏的时, world提供的debugdraw是一个很便捷的功能。但是使用时经常有人遇到,照着box2dtest中的做了,确看不到显示结果的情况。实际上并不是没有画出来,而是world->DrawDebugData();的结果被我们的背景或者sprite图片给遮盖了。

    因为在cocos2d-x中画图,是有z-order的概念的,我们addChild默认用了z-order=0, 而DrawDebugData在z-order=0的最底层画图,所以就被遮盖了。

    遇到这种情况,有两种办法:

     1 把背景图片或者其他sprite图片去掉

     2 在加入背景和sprite时,设置其z-order小于0,例如:this->addChild(bg,-1);

     个人推荐第二种方式。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn