Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag and drop for CCSprite in xcode
    primarykey
    data
    text
    <p>In my application i have used CCSprites. They are defines in the proper format and ccTouchesBegan functions properly. Then I added the codes for drag and drop. they are</p> <pre><code>- (void)selectSpriteForTouch:(CGPoint)touchLocation { CCSprite * newSprite = nil; NSMutableArray *movableSprites=[[NSMutableArray alloc] initWithObjects:Tocken1,Tocken2,Tocken3]; for (CCSprite *sprite in movableSprites) { if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) { newSprite = sprite; break; } } if (newSprite != selSprite) { [selSprite stopAllActions]; [selSprite runAction:[CCRotateTo actionWithDuration:0.1 angle:0]]; CCRotateTo * rotLeft = [CCRotateBy actionWithDuration:0.1 angle:-4.0]; CCRotateTo * rotCenter = [CCRotateBy actionWithDuration:0.1 angle:0.0]; CCRotateTo * rotRight = [CCRotateBy actionWithDuration:0.1 angle:4.0]; CCSequence * rotSeq = [CCSequence actions:rotLeft, rotCenter, rotRight, rotCenter, nil]; [newSprite runAction:[CCRepeatForever actionWithAction:rotSeq]]; selSprite = newSprite; } } - (CGPoint)boundLayerPos:(CGPoint)newPos { CGSize winSize = [CCDirector sharedDirector].winSize; CGPoint retval = newPos; retval.x = MIN(retval.x, 0); retval.x = MAX(retval.x, -background.contentSize.width+winSize.width); retval.y = self.position.y; return retval; } - (void)panForTranslation:(CGPoint)translation { if (Tocken1) { CGPoint newPos = ccpAdd(Tocken1.position, translation); Tocken1.position = newPos; } else { CGPoint newPos = ccpAdd(self.position, translation); self.position = [self boundLayerPos:newPos]; } } - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; CGPoint oldTouchLocation = [touch previousLocationInView:touch.view]; oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation]; oldTouchLocation = [self convertToNodeSpace:oldTouchLocation]; CGPoint translation = ccpSub(touchLocation, oldTouchLocation); [self panForTranslation:translation]; } </code></pre> <p>now when i click on the sprite the program gets terminated with the following error code.</p> <p>2012-02-23 10:12:47.377 whoonu[3574:207] <em>*</em> Assertion failure in -[WhooseitView ccTouchBegan:withEvent:], /Users/sandeepkuttiyatur/Documents/Dropbox/ibiz_completed_apps/WhoonuV9/CatRace/libs/cocos2d/CCLayer.m:259</p> <p>2012-02-23 10:12:47.378 whoonu[3574:207] <em>*</em> Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Layer#ccTouchBegan override me'</p> <pre><code>*** Call stack at first throw: ( 0 CoreFoundation 0x02c23b99 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x02d7340e objc_exception_throw + 47 2 CoreFoundation 0x02bdc238 +[NSException raise:format:arguments:] + 136 3 Foundation 0x02674e37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 whoonu 0x00033873 -[CCLayer ccTouchBegan:withEvent:] + 179 5 whoonu 0x0008efa7 -[CCTouchDispatcher touches:withEvent:withTouchType:] + 1255 6 whoonu 0x0008fb6f -[CCTouchDispatcher touchesBegan:withEvent:] + 111 7 whoonu 0x00091a21 -[EAGLView touchesBegan:withEvent:] + 113 8 UIKit 0x007db324 -[UIWindow _sendTouchesForEvent:] + 395 9 UIKit 0x007bccb4 -[UIApplication sendEvent:] + 447 10 UIKit 0x007c19bf _UIApplicationHandleEvent + 7672 11 GraphicsServices 0x03236822 PurpleEventCallback + 1550 12 CoreFoundation 0x02c04ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 13 CoreFoundation 0x02b65807 __CFRunLoopDoSource1 + 215 14 CoreFoundation 0x02b62a93 __CFRunLoopRun + 979 15 CoreFoundation 0x02b62350 CFRunLoopRunSpecific + 208 16 CoreFoundation 0x02b62271 CFRunLoopRunInMode + 97 17 GraphicsServices 0x0323500c GSEventRunModal + 217 18 GraphicsServices 0x032350d1 GSEventRun + 115 19 UIKit 0x007c5af2 UIApplicationMain + 1160 20 whoonu 0x000bceaf main + 127 21 whoonu 0x00001ed5 start + 53 22 ??? 0x00000001 0x0 + 1 </code></pre> <p>) terminate called after throwing an instance of 'NSException' </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload