Example #1
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // Use the bounds to layout the positioning of our drawable assets
            CCRect bounds = VisibleBoundsWorldspace;

            // point to rotate around
            origin = bounds.Center;

            var originNode = new CCDrawNode();

            originNode.DrawDot(origin, 10, new CCColor4F(CCColor4B.Magenta));
            AddChild(originNode);

            PositionMonkey();

            rotateAround = new CCRotateAroundTo(2.0f, origin, 45, -1);

            // Register for touch events
            var touchListener = new CCEventListenerTouchAllAtOnce();

            touchListener.OnTouchesEnded = OnTouchesEnded;
            AddEventListener(touchListener, this);
        }
        public CCRotateAroundToState(CCRotateAroundTo action, CCNode target)
            : base(action, target)
        {
            DistanceAngle = action.DistanceAngle;

            Origin            = action.Origin;
            StartPosition     = target.Position;
            RotationDirection = action.RotationDirection;

            offsetX = StartPosition.X - Origin.X;
            offsetY = StartPosition.Y - Origin.Y;

            // Calculate the Starting Angle of the target in relation to the Origin in which it is to rotate

            // Math.Atan2 returns the mathematical angle which is counter-clockwise [-Math.PI, +Math.PI]
            StartAngle = CCMathHelper.ToDegrees((float)Math.Atan2(offsetY, offsetX));
            // Map value [0,360]
            StartAngle = (StartAngle + 360) % 360;


            // Now we work out how far we actually have to rotate
            DiffAngle = DistanceAngle - StartAngle;
            // Map value [0,360] and take into consideration the direction of rotation - CCW or CW
            DiffAngle = (DiffAngle + 360 * RotationDirection) % 360;

            theta = CCMathHelper.ToRadians(DiffAngle);
        }
        public CCRotateAroundToState(CCRotateAroundTo action, CCNode target)
            : base(action, target)
        { 
            DistanceAngle = action.DistanceAngle;

            Origin = action.Origin;
            StartPosition = target.Position;
            RotationDirection = action.RotationDirection;

            offsetX = StartPosition.X - Origin.X;
            offsetY = StartPosition.Y - Origin.Y;

            // Calculate the Starting Angle of the target in relation to the Origin in which it is to rotate

            // Math.Atan2 returns the mathematical angle which is counter-clockwise [-Math.PI, +Math.PI]
            StartAngle = CCMathHelper.ToDegrees((float)Math.Atan2(offsetY, offsetX));
            // Map value [0,360]
            StartAngle = (StartAngle + 360) % 360;


            // Now we work out how far we actually have to rotate
            DiffAngle = DistanceAngle - StartAngle;
            // Map value [0,360] and take into consideration the direction of rotation - CCW or CW
            DiffAngle = (DiffAngle + 360 * RotationDirection) % 360;

            theta = CCMathHelper.ToRadians(DiffAngle);


        }
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // Use the bounds to layout the positioning of our drawable assets
            CCRect bounds = VisibleBoundsWorldspace;

            // point to rotate around
            origin = bounds.Center;

            var originNode = new CCDrawNode();
            originNode.DrawDot(origin, 10, new CCColor4F(CCColor4B.Magenta));
            AddChild(originNode);

            PositionMonkey();

            rotateAround = new CCRotateAroundTo(2.0f, origin, 45, -1);

            // Register for touch events
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesEnded = OnTouchesEnded;
            AddEventListener(touchListener, this);
        }