我试图在Cocos2d-x中移植像素完美碰撞检测,原始版本是为Cocos2D制作的,可以在这里找到:http://www.cocos2d-iphone.org/forums/topic/pixel-perfect-collision-detection -使用色混/
这是我的Cocos2d-x版本的代码
bool CollisionDetection::areTheSpritesColliding(cocos2d::CCSprite *spr1, cocos2d::CCSprite *spr2, bool pp, CCRenderTexture* _rt) {
bool isColliding = false;
CCRect intersection;
CCRect r1 = spr1->boundingBox();
CCRect r2 = spr2->boundingBox();
intersection = CCRectMake(fmax(r1.getMinX(),r2.getMinX()), fmax( r1.getMinY(), r2.getMinY()) ,0,0);
intersection.size.width = fmin(r1.getMaxX(), r2.getMaxX() - intersection.getMinX());
intersection.size.height = fmin(r1.getMaxY(), r2.getMaxY() - intersection.getMinY());
// Look for simple bounding box collision
if ( (intersection.size.width>0) && (intersection.size.height>0) ) {
// If we're not checking for pixel perfect collisions, return true
if (!pp) … Crashlytics给了我以下的堆栈跟踪.崩溃不一致.在所有iOS 9设备上都会发生,但很少发生.无法找出问题的根源.在我拥有的任何设备上都没有发生过,过去3天一直试图崩溃.
Crashed: com.apple.main-thread
0 cherish 0x10014ee18 specialized PersonalizeViewController.collectionView(UICollectionView, cellForItemAtIndexPath : NSIndexPath) -> UICollectionViewCell (PersonalizeViewController.swift:159)
1 cherish 0x1001497f0 @objc PersonalizeViewController.collectionView(UICollectionView, cellForItemAtIndexPath : NSIndexPath) -> UICollectionViewCell (PersonalizeViewController.swift)
2 UIKit 0x188aef3a8 <redacted> + 432
3 UIKit 0x188311adc <redacted> + 4628
4 UIKit 0x18830c808 <redacted> + 228
5 UIKit 0x1882a81e4 <redacted> + 656
6 QuartzCore 0x185c3a994 <redacted> + 148
7 QuartzCore 0x185c355d0 <redacted> + 292
8 QuartzCore 0x185c35490 <redacted> + 32
9 QuartzCore 0x185c34ac0 <redacted> + 252
10 QuartzCore 0x185c34820 <redacted> + 500 …Run Code Online (Sandbox Code Playgroud)