コード行を書き、スプライトを選択してドラッグできますが、ドラッグするとすぐにマウスカーソルから数ピクセル離れてしまい、その後は制御できますが、マウスから数ピクセル離れていますcursos ..変換に何か問題があるようです。CGPoint
または、わかりません。それは私のコードです
- (void)selectSpriteForTouch:(CGPoint)touchLocation {
CCSprite * newSprite = nil;
for (CCSprite *sprite in movableSprites) {
if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {
newSprite = sprite;
NSLog(@"palieciau");
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;
}
}
- (BOOL)ccMouseDown:(NSEvent*)event {
CCSprite * newSprite = nil;
CGPoint clickLocation = [[CCDirector sharedDirector] convertEventToGL:event];
for (CCSprite *sprite in movableSprites) {
if (CGRectContainsPoint(sprite.boundingBox, clickLocation)) {
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;
}
}
- (void)panForTranslation:(CGPoint)translation {
if (selSprite) {
CGPoint newPos = ccpAdd(selSprite.position, translation);
selSprite.position = newPos;
} else {
}
}
-(BOOL)ccMouseDragged:(NSEvent *)event {
CGPoint point = [[CCDirector sharedDirector] convertEventToGL:event];
CGPoint mouseLocation = [self convertToNodeSpace:point];
CGPoint translation = ccpSub(point, oldMouseLocation_);
[self panForTranslation:translation];
oldMouseLocation_ = point;
}