If you want to center the text then add half the width of the image to its x coordinate and subtract half the pixel width of the text to get the appropriate x value; The y value for the text will be the ycoord of the image plus the image's height plus however much padding you want.
EDIT: Here's a rough example. Notice that the text is treated as if it were a bitmap font, which is what you'll inevitably end up using.Graphics 640,480,0,2
SetBuffer BackBuffer()
Const AVATAR_WIDTH% = 64
Const AVATAR_HEIGHT% = 128
Const FONT_WIDTH% = 12
Const FONT_HEIGHT% = 12
MakeAvatar("Sarah")
MakeAvatar("John")
MakeAvatar("Zed")
MakeAvatar("JJ")
MakeAvatar("X")
Color 100,255,100
While Not KeyHit(1)
DrawAllAvatars()
Text 10,10,"Left Mouse Button To Delete Avatars..."
Flip True
Cls
If MouseHit(1) DeleteAvatar()
Wend
End
Global Avatar_Count% = 0
Type TAvatar
Field piccy%
Field name$
End Type
Function MakeAvatar(name_arg$)
Color 100+Rand(155),100+Rand(155),100+Rand(155)
Rect 0,0,AVATAR_WIDTH,AVATAR_HEIGHT
newAvatar.TAvatar = New TAvatar
newAvatar\name = name_arg
newAvatar\piccy = CreateImage(AVATAR_WIDTH,AVATAR_HEIGHT)
GrabImage newAvatar\piccy,0,0
Cls
Avatar_Count = Avatar_Count+1
End Function
Function DeleteAvatar()
If Avatar_Count = 0 Return
Local avatarToDelete.TAvatar = First TAvatar
FreeImage avatarToDelete\piccy
Delete avatarToDelete
Avatar_Count=Avatar_Count-1
End Function
Function DrawAllAvatars()
If Avatar_Count = 0 Return
Local xSpace% = GraphicsWidth()/(Avatar_Count+1)
Local currentAvatarIndex% = 1
For currentAvatar.TAvatar = Each TAvatar
DrawBlock currentAvatar\piccy,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-AVATAR_HEIGHT-10-FONT_HEIGHT
DrawName(currentAvatar\name,(currentAvatarIndex*xSpace)-(AVATAR_WIDTH*.5),GraphicsHeight()-10-FONT_HEIGHT)
currentAvatarIndex = currentAvatarIndex+1
Next
End Function
Function DrawName(string_arg$, xPos_arg%, yPos_arg%)
Local pixelWidth% = Len(string_arg)*FONT_WIDTH
Local centeredX% = (xPos_arg+(AVATAR_WIDTH*.5)) - (pixelWidth*.5)
For currentCharIndex = 0 To Len(string_arg)
Text centeredX+(currentCharIndex*FONT_WIDTH),yPos_arg,Mid(string_arg,currentCharIndex+1,1)
Next
End Function
|