ImageYHandle ( image )

Parameters

image - handle of the image to query

Description

Returns the y position of an image's handle, measured from the top edge of the image.

The handle is the point inside the picture that lines up with the x,y you pass to DrawImage. It is 0 on a freshly loaded image unless AutoMidHandle was on, and MidHandle or HandleImage move it.

Read it back when you need the image's real top edge on screen - for a hand-rolled bounding box, for sorting sprites by their feet, or for placing a health bar a fixed distance above a character whose handle you did not set yourself. ImageXHandle gives you the other axis.

All frames of an animated image share one handle, so there is no frame parameter.

See also: ImageXHandle, HandleImage, MidHandle, AutoMidHandle, ImageHeight.

Example

; ImageYHandle Example
; --------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

player=LoadImage("media/player.bmp")   ; a 32x36 ship sprite
mode=0

While Not KeyDown(1)

    Cls

    ; Space cycles the handle: top-left, centre, bottom-right
    If KeyHit(57) Then mode=(mode+1) Mod 3
    If mode=0 Then HandleImage player,0,0
    If mode=1 Then MidHandle player
    If mode=2 Then HandleImage player,32,36

    ; A crosshair marks the draw point; the handle decides the offset
    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: change the handle   Esc: exit"
    ; ImageYHandle reads back the handle position set above
    Text 0,20,"ImageYHandle(player)="+ImageYHandle(player)+"   ImageXHandle(player)="+ImageXHandle(player)

    Flip

Wend

End

Index