Firstly, division is slow, so when halving use multiplication:
* .5 instead of
/ 2.
As of rotation in 2d, you need to use
Atanfull to find the angle between 2 points. Here's an example of what you want using it:
// setup globals for reuse
global screenHalfWidth as integer
global screenHalfHeight as integer
screenHalfWidth = screen width() * .5
screenHalfHeight = screen height() * .5
// create image 128x128
cls rgb(255,0,0)
get image 1,0,0,128,128,1
cls
// postion sprite in the middle offseting the centre point of the sprite by half of image size
sprite 1, screenHalfWidth, screenHalfHeight, 1
offset sprite 1, 64, 64
do
// find the relative mouse position from the sprite
curMouseX = mousex() - sprite x(1)
curMouseY = mousey() - sprite y(1)
// return the ang between 2 points
angle = atanfull( curMouseY, curMouseX )
// apply angle to sprite
rotate sprite 1, angle
sync
loop
I suggest looking into atanfull or atan2 on the interwebs for further information or look into 2d rotations via Google. Even if it's written in a different language, it's relatively easy to port to DBP.