MidHandle image
Parameters
| image - handle of the image to change |
Description
|
Moves one image's handle to the middle of the image. The handle is the point inside the picture that lines up with the x,y you pass to DrawImage. It normally sits at the top left corner, so a 50x50 image drawn at 200,200 covers 200,200 to 250,250. After MidHandle the same call centres the image on 200,200, covering 175,175 to 225,225. Centre anything you move or spin: bullets, explosions, the player, particles, a compass needle. Distances between centres are then just the distance between the positions you already store, and the sprite grows outwards rather than down-and-right when you scale it. This affects the one image you name, and every frame of it. To have images arrive centred without asking each time, switch on AutoMidHandle before you load them - but note that only applies to images loaded afterwards, so MidHandle is what you reach for on images that are already in memory. For a handle anywhere other than the centre, use HandleImage, and read the current position back with ImageXHandle and ImageYHandle. The centre is worked out with integer division, so an odd-sized image rounds down by half a pixel. The handle is also the pivot RotateImage spins around, which is another reason to centre before rotating. See also: AutoMidHandle, HandleImage, ImageXHandle, ImageYHandle, DrawImage. |
Example
; MidHandle Example ; ----------------- Graphics 640,480,0,2 SetBuffer BackBuffer() player=LoadImage("media/player.bmp") mid=0 While Not KeyDown(1) Cls ; Space toggles the handle between top-left (default) and centre If KeyHit(57) Then mid=1-mid If mid=1 Then MidHandle player ; move the handle to the image centre Else HandleImage player,0,0 ; back to the default top-left handle End If End If ; A crosshair marks the exact point the image is drawn at x=MouseX() y=MouseY() DrawImage player,x,y Color 255,255,0 Line x-10,y,x+10,y Line x,y-10,x,y+10 Text 0,0,"Move mouse Space: toggle MidHandle Esc: exit" If mid=1 Then Text 0,20,"MidHandle player - the ship is centred on the crosshair" Else Text 0,20,"Default handle 0,0 - the ship hangs below-right of the crosshair" End If Flip Wend End
Index