Difference between revisions of "How to point a sprite at a target"
Jump to navigation
Jump to search
(No difference)
|
Revision as of 13:57, 4 March 2020
To point a sprite at a target, use the atan function to calculate the angle in radians, then multiply by 180/pi to convert to degrees, and assign the result to the sprite's .rotation property.
Example
clear
sp = new Sprite
sp.image = file.loadImage("/sys/pics/arrows/arrow2.png")
sp.x = 480
sp.y = 320
display(4).sprites.push sp
while true // (press Control-C to exit)
sp.rotation = atan(mouse.y - sp.y, mouse.x - sp.x) * 180/pi
yield
end while