2D Toolkit Forum

2D Toolkit => Support => Topic started by: amit.r007 on June 17, 2014, 11:22:25 am

Title: Rotating Sprite on Touch and Drag
Post by: amit.r007 on June 17, 2014, 11:22:25 am
Hi Unikron,

In my 2D game I have a circular sprite which I want to rotate as per touch input. I want to rotate that 2D sprite on z- Axis, say like a 2D Car steering (x and y fixed) according to the touch and drag of a finger/thumb.

Please help me regarding the same.

Thanks,
Amit
Title: Re: Rotating Sprite on Touch and Drag
Post by: amit.r007 on June 18, 2014, 12:31:03 pm
Any thoughts on this ?? :)
Title: Re: Rotating Sprite on Touch and Drag
Post by: rakkarage on June 18, 2014, 01:33:56 pm
here is some touchScript (http://interactivelab.github.io/TouchScript/) code for panning
you could do something similar but change rotation instead of position maybe
Code: [Select]
private void HandlePanStateChanged(object s, TouchScript.Events.GestureStateChangeEventArgs e)
{
if (Utility.Paused) return;
Menu.Instance.Close();
switch (e.State)
{
case Gesture.GestureState.Began:
case Gesture.GestureState.Changed:
SimplePanGesture g = (SimplePanGesture)s;
if (g.LocalDeltaPosition != Vector3.zero)
{
GameCamera.transform.localPosition -= g.LocalDeltaPosition / GameCamera.ZoomFactor;
}
break;
case Gesture.GestureState.Ended:
Spring();
break;
}
}