Steering wheel
Monkey Archive Forums/Monkey Tutorials/Steering wheel
| ||
Here is a simple function, that makes a 2d steering wheel for possible racing games. I packed it with an example: http://carvertemphub.nm.ru/dls/SteeringWheel/ Function only requires mojo, but diddy version is also in the zip. It was written in the STRICT mode, but does not depend on it. 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 PS: 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) Hope this will help someone |
| ||
Cool example, would be good for a smartphone interface, thanks. |