There is a small boat and four buttons: left, right, up, down. How to press the button to turn the ship once in the appropriate direction?

tried through object:rotate(deltaAngle) , it turns out that each time you press the button, the ship turns again, which I do not need

It is possible to set a fixed turn like "I will press the button up, and then again, but you will turn to the north position for the first time, and you will ignore the second time, you will already turn north"?

    2 answers 2

    When turning, remember the position. The next time you press the button, see the position, and if it is not the one you need, ignore it.

      If the ship is an object, then it must be set to the property "Direction". And draw already depending on this property. The arrows only need to set this value (1,2,3 or 4). Then draw. You can create 4 initially rotated objects (pictures) and use them or rotate one object from the initial state by the required number of degrees.

      • And how to set this property, it is possible in more detail? - NekoDev
      • So far, I have come up with only two new solutions: 1. instead of four checks for each button, set four values ​​of the angle (angleLeft, angleRight, etc.), and then just insert the buttons into the function; 2. write a new function with checks in general - ship:aniRotate(direction) , where direction is one of the four directions. - NekoDev
      • Yes, you can not ask such trifles here, after all, SO deals with solutions and errors that are difficult to handle yourself. - Mike V.
      • Thank you, but at first I really could not figure out how to implement it. I'll highlight the first answer as correct and get it over with. - NekoDev