Hello
I'm not quite sure what you want to accomplish,
but here is my code where I have assumed that you want to rotate your sprite
around its own axis, while moving the mouse around ?? !!
// Project: SpriteAngleTest_forum
// Created: 2015-07-25
// from an Forum question, 17july 2015.
// < http://forum.thegamecreators.com/?m=forum_view&t=214944&b=41 >
/* This assumes that the inquirer want to rotate the the sprite around its center point,
when he moves the mouse or his finger(smartphone) around on the screen !?
*/
// set window properties
SetWindowSize( 1280, 800, 0 )
SetDisplayAspect(16.0/10.0) // Everything converts to percentage values.
local spr
local PX#
local PY#
local state = 0
local dx#, dy#, angle#
spr = CreateSprite(0)
SetSpritePosition(spr,15,70)
SetSpriteSize(spr,20,3)
do
PX# = GetPointerX()
PY# = GetPointerY()
if GetSpritehitTest(spr,PX#,PY#) = 1
state = 1
endif
if state = 1 and GetPointerState() = 1
dx# = PX# - (getspritex(spr) + 10) // calculate x coord distance
// getSpriteX(spr) + 10 to get the center
// of the sprite.
dy# = PY# - (GetSpriteY(spr) + 1.5) // calculate Y coord distance.
angle# = ATan2(dy#, dx#) // returns the angle in degrees.
SetSpriteAngle(spr, angle#)
else
state = 0
endif
Sync()
loop