我想创建一个游戏,我想根据触摸移动CCSprite
(眼球图像)。
像眼球一样应该按照我的触摸方向移动,但要移动到特定区域。我是Cocos2d
的新人,所以我不知道如何实现这一目标。
所以任何人都可以帮助我在touchesMoved
答案 0 :(得分:1)
您必须实施ccTouchMoved
方法
- (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;
}