Rotation of a line

I have already spent few hours and I just cannot figure it out.
How is Rotation implemented on a CCDrawNode, for example a simple line.

Let's say we have that line:

myObject.DrawLine(from: new CCPoint(5, 5),
                                to: new CCPoint(25, 5),
                                lineWidth: 1,
                                lineCap: CCLineCap.Round,
                                color: myColor);

Now I would like to rotate that line, let's say 45 degrees to the right (so positive value), like a rotating propeller (angle in the middle):

myObject.RotationY = 45;

But what happens now is that the line is being rotated on a big circle, changing the Y position (the value itself does not change).
What am I doing wrong here?

Answers

  • ThomasJKThomasJK Member ✭✭
    edited October 2018

    I did some additional tests and this is very strange.

    myObject.AnchorPoint

    doesn't change anything, the anchor for the rotation is the invisible extension of the line up to the bounding scene size.

    Rotation and RotationY - I cannot see any difference

    Am I completely nuts, is this how it should behave?

    Any comments? I've spent another hours on doing sin() and cos() to move the line back to the desired position to make it look like it is rotating around the middle of the line.

    There must be an easier solution for that, I hope.

  • Junior_OliveiraJunior_Oliveira USMember ✭✭

    Good night, late reply,

    See if help:

    myObject.DrawLine(from: new CCPoint(5, 5),
    to: new CCPoint(25, 5),
    lineWidth: 1,
    lineCap: CCLineCap.Round,
    color: myColor);

    public void Rotation(bool clockWise)
            {
                CCRotateBy rotate;
                if (clockWise)
                {
                    rotate = new CCRotateBy(0f, 90f);
                    rotation += 90;
                    if (rotation >= 360) rotation = 0;
                }
                else
                {
                    rotate = new CCRotateBy(0f, -90f);
                    if (rotation == 0) rotation = 360;
                    rotation -= 90;
                }
                myObject.RunAction(rotate);
            }
    
Sign In or Register to comment.