DrawImageRect !

BlitzMax Forums/BlitzMax Beginners Area/DrawImageRect !

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Could you test it. Here i can't display correctly the second character ! Maybe an error into my code, but i can't find it !!! Thanks for your help !

Graphics 800,600

Type TFont

	Field x : Int[255]
	Field y : Int[255]
	Field w : Int[255]
	Field hImage:Timage
	
	Const CTE_NBRE_CARACTERES = 50	

	Function Charger_police:TFont(FileName$)
	
		Local i:Int
		Local ValeurAscii:Int
		Local Caractere$
		
		Local f:TFont = New TFONT
		
		For i=0 To CTE_NBRE_CARACTERES - 1
			
			ReadData Caractere$
			Valeur_ascii = Asc (Caractere$)
						
			ReadData f.x[Valeur_ascii]
			ReadData f.y[Valeur_ascii]
			ReadData f.w[Valeur_ascii]

		Next
		
		f.hImage = LoadImage (FileName$)
		
		Return f
		
	End Function

	Function DrawImageRect(img:TImage, x#, y#, rx#, ry#, rw#, rh#)
		SetViewport x, y, rw, rh
		DrawImage img, x - rx, x - ry
		
		SetViewport 0, 0, GraphicsWidth(), GraphicsHeight()
	End Function
		
	Method Afficher_texte (Texte$, PosX, PosY)
	
		Local i:Int
		Local Caractere : String
		Local aw = 0
		For i=0 To Len(Texte$)- 1
			
			CodeAscii = Texte$[i]
			lx = x [CodeAscii]
			ly = y [CodeAscii]
			lw = w [CodeAscii]
			
			DrawImageRect (hImage, PosX+aw,PosY,lx,ly,64,64)

			aw = aw + lw + 5
		
		Next
	
	End Method
		
		
End Type

Local f:TFONT

f = TFont.Charger_police ("media/bada.png")
While Not KeyDown(KEY_ESCAPE)
	f.Afficher_texte ("HELLO", 100, 100)
	Flip
Wend

	
' Symbo, x, y, width			
DefData "!",0,0,22
DefData "-",64,0,25
DefData "#",128,0,32
DefData "$",192,0,23
DefData "%",256,0,34
DefData "&",320,0,29
DefData "'",384,0,15
DefData "(",448,0,21
DefData ")",0,64,21
DefData "*",64,64,21
DefData "+",128,64,17
DefData ",",192,64,17
DefData "-",256,64,17
DefData ".",320,64,13
DefData "/",384,64,32
DefData "0",448,64,26
DefData "1",0,128,18
DefData "2",64,128,26
DefData "3",128,128,24
DefData "4",192,128,23
DefData "5",256,128,23
DefData "6",320,128,24
DefData "7",384,128,23
DefData "8",448,128,27
DefData "9",0,192,26
DefData "A",64,192,25
DefData "B",128,192,24
DefData "C",192,192,24
DefData "D",256,192,25
DefData "E",320,192,22
DefData "F",384,192,22
DefData "G",448,192,25
DefData "H",0,256,26
DefData "I",64,256,16
DefData "J",128,256,22
DefData "K",192,256,26
DefData "L",256,256,18
DefData "M",320,256,33
DefData "N",384,256,26
DefData "O",448,256,26
DefData "P",0,320,24
DefData "Q",64,320,26
DefData "R",128,320,24
DefData "S",192,320,23
DefData "T",256,320,21
DefData "U",320,320,25
DefData "V",384,320,23
DefData "W",448,320,31
DefData "X",0,384,28
DefData "Y",64,384,24
DefData "Z",128,384,27


Png file :