gpt4 book ai didi

iphone - 在cocos2d中平滑拖动Sprite - iPhone

转载 作者:行者123 更新时间:2023-12-03 18:52:55 25 4
gpt4 key购买 nike

我已经实现了对 Sprite 对象的拖动,如下所示..

-(BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch * touch = [touches anyObject];
CGPoint location = [[Director sharedDirector] convertCoordinate: [touch locationInView:touch.view]];
[diskSprite setPosition:ccp(location.x , location.y )];
return kEventHandled;
}

但是这个拖拽并不顺利......当我用拇指快速拖动对象时,该对象会从路径中离开。

谢谢

最佳答案

可能有点晚了,但我正在寻找类似的东西。我发现这个很棒的教程解释了一切: http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d

- (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);
CGPoint newPos = ccpAdd(mySpriteToMove.position, translation);
mySpriteToMove.position = newPos;
}

关于iphone - 在cocos2d中平滑拖动Sprite - iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2020752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com