루이스이 야구장에서 당신을 얻어야한다 (인스턴스 변수를 추가하면뿐만 아니라 그 조각을 필요로하는 경우께요 알고, 초기화에있을 것입니다 만질 수) :
를
- (BOOL) ccTouchBegan: (UITouch *) touch
withEvent: (UIEvent *) event
{
_touchBeganAt = [self convertTouchToNodeSpace:touch];
_velocityChangeSpeed = 1;
}
- (void) ccTouchEnded: (UITouch *) touch
withEvent: (UIEvent *) event
{
_velocityChangeSpeed = -1;
}
- (void) update:(ccTime)delta
{
velocityThreshold = 1; //? You can tune this
distanceThreshold = 1; //? Same
_sprite.velocity += _velocityChangeSpeed;
//So it comes to a complete stop, as opposed to moving backwards
if(_sprite.velocity < velocityThreshold)
_velocityChangeSpeed = 0;
float distanceFromTouchedPoint = ABS(_sprite.position.x - _touchBeganAt.x);
if(distanceFromTouchedPoint < distanceThreshold)
_velocity = 0;
}