Steering Wheel


Tweet monkey-x code-archives miscellaneous
(Posted 6 months ago) RonTek

Here is a simple function, that makes a 2d steering wheel for possible racing games.

Author: StoneFaceEXE

Notes:

  1. It is best to use images with even resolutions (e.g. 100x100)
  2. It automatically sets the handle of an image to MidHandle and calculates touch hits corresponding to resolutions of the image.
  3. It returns int values from -180 to 180

Syntax:

  • DrawWheel(A,B,C)
  • A - Image of the wheel
  • B,C - X and Y where the wheel must be drawn(Note that your image will be mid handled)
Function DrawWheel:Int(ImageHandle:Image, xl:Int = DeviceWidth() / 2, yl:Int = DeviceHeight() / 2)
    Local angle:Int
    If TouchX() > xl - ImageHandle.Width() / 2 And TouchX() < xl + ImageHandle.Width() / 2
        If TouchY() > yl - ImageHandle.Height() / 2 And TouchY() < yl + ImageHandle.Height() / 2
            If TouchDown() Then angle = ATan2(xl - TouchX(), yl - TouchY())
        Endif
    Endif
    ImageHandle.SetHandle(ImageHandle.Width() / 2, ImageHandle.Height() / 2)
    DrawImage(ImageHandle, xl, yl, angle, 1, 1)
    Return angle
End Function

Reply To Topic (minimum 10 characters)

Please log in to reply