在CocosSharp图层上添加缩放

时间:2018-01-31 10:04:19

标签: xamarin xamarin.android cocossharp

我正在Visual Studio 2017上测试CocosSharp,我想通过测试CCTouch元素列表来对CCLayer执行缩放。

此列表由CCEventListenerTouchAllAtOnce.OnTouchesBegan事件发出。

这是我的代码不起作用:

    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;
       }

我在CCLayer层添加了这样的触控器:

        var touchListener = new CCEventListenerTouchAllAtOnce();
        touchListener.OnTouchesBegan = HandleTouchBegan;
        layer.AddEventListener(touchListener);

我在触摸列表中使用2个CCTouch获取事件,但该图层未缩放。

我哪里错了? 有没有更好的方法来进行图层缩放?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我只是从这个东西开始,偶然发现了您的帖子,所以我根本不是权威。

我拿了您的代码,改用parent.sh。然后,我将#!/bin/bash /home/vagrant/setup-files/child1.sh && /home/vagrant/setup-files/child2.sh if [ $? -ne 0 ]; then # If: last exit code is non-zero echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! echo An error occurred running build scripts echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! fi 除以100,因为它和代码中的一样大。

现在,它可以放大/缩小,但是以一种奇怪的“侧向”方式进行。还有更多工作要做,但我想我会提供一些投入!