0
如何将精灵移动到x轴上的触摸点增加velocity.x。触摸时间越长,速度越高,那么当触摸到某个范围或用户松开手指时,再次减慢速度?将精灵移动到触摸点增加速度触摸得越长
我有一个播放器类设置的速度值,它是在更新方法中更新,不知道如何获得触摸方法所需的行为?
干杯,
刘易斯
如何将精灵移动到x轴上的触摸点增加velocity.x。触摸时间越长,速度越高,那么当触摸到某个范围或用户松开手指时,再次减慢速度?将精灵移动到触摸点增加速度触摸得越长
我有一个播放器类设置的速度值,它是在更新方法中更新,不知道如何获得触摸方法所需的行为?
干杯,
刘易斯
这应该让你在球场(实例变量,并添加它是可触摸将在init,还是让我知道,如果你需要的片段以及):
- (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;
}