I've just had a look and getting these kinds of things right always takes quite a lot of tweaking and refinement. You may decide in the end to use two sprites for the sling instead of one, so that you can ensure that they both appear to remain attached to the slingshot. Anyhow I've put together a very rough implementation to get you started.
SetVirtualResolution ( 1024, 768 )
// Cache Sprite
CreateSprite ( 1, LoadImage ("Cache.png") )
SetSpriteOffset ( 1, GetSpriteWidth(1), 0)
SetSpritePositionbyOffset( 1, 230, 525 )
// Slingshot Wood Sprite
CreateSprite ( 2, LoadImage ("slingshot.png") )
SetSpriteOffset ( 2, GetSpriteWidth(2), 0)
SetSpritePositionbyOffset( 2, 250, 500 )
do
if GetPointerState()
PointerX# = ScreenToWorldX(GetPointerX())
PointerY# = ScreenToWorldY(GetPointerY())
pointerToSlingX# = GetSpriteXByOffset(1) - PointerX#
pointerToSlingY# = GetSpriteYByOffset(1) - PointerY#
angle# = ATan2(pointerToSlingY#, pointerToSlingX#)
if angle# > 45.0
SetSpriteAngle(1, 65.0)
elseif angle# < -60.0
SetSpriteAngle(1, -40.0)
else
SetSpriteAngle(1, angle# + 20)
mag# = Sqrt((pointerToSlingX# * pointerToSlingX#) + (pointerToSlingY# * pointerToSlingY#))
SetSpriteSize(1, mag#, GetSpriteHeight(1))
endif
Endif
sync()
loop
This works as follows. First, we set the offset of the cache sprite so that it is in the top right hand corner (this will act as the pivot point - you could experiment with bringing this point a little further into the sprite so that it is between the two ends of the cache). Then, in the loop, we calculate the vector from the mouse to the sling with these lines.
pointerToSlingX# = GetSpriteXByOffset(1) - PointerX#
pointerToSlingY# = GetSpriteYByOffset(1) - PointerY#
This direction is the direction we want the sling to point towards. We then convert our vector to an angle of rotation as before.
angle# = ATan2(pointerToSlingY#, pointerToSlingX#)
Finally, we set the sprite's rotation. If the angle from the mouse to the sling is outside of the permitted range, we clamp the rotation and do not change the scaling.
if angle# > 45.0
SetSpriteAngle(1, 65.0)
elseif angle# < -60.0
SetSpriteAngle(1, -40.0)
If the angle is within the valid range, then we set the sprite to the angle calculated earlier and calculate the scaling. The scaling is done entirely to the width, simply by setting the width to the same size and the length of the vector.
SetSpriteAngle(1, angle# + 20)
mag# = Sqrt((pointerToSlingX# * pointerToSlingX#) + (pointerToSlingY# * pointerToSlingY#))
SetSpriteSize(1, mag#, GetSpriteHeight(1))
endif
I found that with the sprites you're using, adding 20 to the rotation makes it appear that the sling is being pulled by the mouse, but this offset will change if you change the sprite.
I hope that helps!