HandleImage image,x,y
Parameters
|
image - handle of the image to change x - x position of the new handle, measured from the left of the image y - y position of the new handle, measured from the top of the image |
Description
|
Moves an image's handle to any point you choose. The handle is the spot inside the image that lines up with the x,y you pass to DrawImage. It starts at the top left corner, 0,0, so a 50x50 image drawn at 200,200 covers 200,200 to 250,250. Move the handle and the whole image shifts relative to where you draw it. MidHandle covers the common case of centring; this command is for everything else. Put the handle at the feet of a character so you can position it by its ground contact, at the muzzle of a gun so a spawned bullet lines up, at the pivot of a swinging arm, or at the base of a tree so it sorts correctly against the floor. Coordinates are in pixels from the top left, and they are not clamped to the image - a handle outside the bounds is legal and just offsets the drawing further. The change applies to every frame of an animated image at once, and it sticks with the image until you change it again. Read it back with ImageXHandle and ImageYHandle. The handle also acts as the pivot for RotateImage and the centre for ScaleImage, so set it before you transform an image rather than after. See also: MidHandle, AutoMidHandle, ImageXHandle, ImageYHandle, DrawImage. |
Example
; HandleImage Example ; ------------------- Graphics 640,480,0,2 SetBuffer BackBuffer() player=LoadImage("media/player.bmp") ; a 32x36 ship sprite hx=0 hy=0 While Not KeyDown(1) Cls ; Arrow keys move the handle point around inside the image If KeyDown(203) And hx>0 Then hx=hx-1 If KeyDown(205) And hx<32 Then hx=hx+1 If KeyDown(200) And hy>0 Then hy=hy-1 If KeyDown(208) And hy<36 Then hy=hy+1 ; HandleImage sets the point the image is drawn from HandleImage player,hx,hy ; The ship is always drawn AT the crosshair - watch it shift DrawImage player,320,240 Color 255,255,0 Line 310,240,330,240 Line 320,230,320,250 Text 0,0,"Arrow keys: move the image handle Esc: exit" Text 0,20,"HandleImage player,"+hx+","+hy Flip Wend End
Index