I'm testing CocosSharp on Visual Studio 2017, I want to perform a zoom on a CCLayer by testing a List of CCTouch elements.
This list is sended by a CCEventListenerTouchAllAtOnce.OnTouchesBegan event.
Here is my code that doesn't work :
private void HandleTouchBegan(List<CCTouch> touches, CCEvent touchEvent)
{
if (touches.Count == 2)
{
CCTouch t1 = touches[0];
CCTouch t2 = touches[1];
CCPoint Loc1 = t1.LocationOnScreen;
CCPoint Loc2 = t2.LocationOnScreen;
CCPoint PreviousLoc1 = t1.PreviousLocationOnScreen;
CCPoint PreviousLoc2 = t2.PreviousLocationOnScreen;
double CurrentDistance = Math.Sqrt(Math.Pow(Loc1.X - Loc2.X, 2.0f) + Math.Pow(Loc1.Y - Loc2.Y, 2.0f));
double PreviousDistance = Math.Sqrt(Math.Pow(PreviousLoc1.X - PreviousLoc2.X, 2.0f) + Math.Pow(PreviousLoc1.Y - PreviousLoc2.Y, 2.0f));
double Delta = CurrentDistance - PreviousDistance;
layer.ScaleX += (float)Delta;
layer.ScaleY += (float)Delta;
}
I added the touch listener like this on the CCLayer layer:
var touchListener = new CCEventListenerTouchAllAtOnce();
touchListener.OnTouchesBegan = HandleTouchBegan;
layer.AddEventListener(touchListener);
I get the event with 2 CCTouch in the touches list, but the layer isn't scaled.
Where am I wrong ? Is there a better way to do this layer zoom ?
Thank You for your help.