tilemap problem

BlitzMax Forums/BlitzMax Beginners Area/tilemap problem

I change a some in your code, test this:
SetGraphicsDriver GLMax2DDriver()
Graphics 800,600,0,90

Global map:Int[1500,1500,21]
Global map_breite:Int=1499
Global map_hoehe:Int=1499
Global map_x:Int
Global map_y:Int
Global layer:Byte=10
Global scaleX:Float=1 
'#######
Global max_X:Int
Global max_map_X:Int 
Global max_map_X_subtraktion:Int 
Global min_X:Int
'#######
Global max_y:Int
Global max_map_y:Int 
Global max_map_y_subtraktion:Int 
Global min_y:Int
'#######
Global scrollX:Int
Global scrolly:Int 
'#######
Global mx2:Int
Global my2:Int 


Global tiles=LoadAnimImage("CHIPSETS/1.png",16,16,0,18*16)

While Not KeyDown(key_escape)
Cls

frames:+1     
If MilliSecs()-timer>1000 Then
fps=frames
frames=0
timer=MilliSecs()
EndIf


map_berechnung()
auf_map_malen()
map_zeichnen()


If KeyDown(key_left) Then scrollx:-1
If KeyDown(key_right) Then scrollx:+1
If KeyDown(key_up) Then scrolly:-1
If KeyDown(key_down) Then scrolly:+1

'##################################
DrawText "fps :"+fps,0,0
'#################################
DrawText "max_x :"+max_x,0,32
DrawText "min_x :"+min_x,0,48
DrawText "scrollx :"+scrollx,0,64
DrawText "max_map_X :"+max_map_X,0,80
'##################################
DrawText "max_y :"+max_y,0,112
DrawText "min_y :"+min_y,0,128
DrawText "scrolly :"+scrolly,0,144
DrawText "max_map_x :"+max_map_Y,0,160
'##################################
DrawText "mx2 :"+mx2,0,192
DrawText "my2 :"+my2,0,208

Flip
Wend
End 

Function map_berechnung()

max_X=(map_breite*16)+scrollx 
If max_X>800 Then 
max_map_X_subtraktion=max_x-800 
Else 
max_map_X_subtraktion=0
EndIf 


max_map_X=(map_breite-(max_map_X_subtraktion/16))+scrollx/16 

If max_map_X<1 Then max_map_X=0
min_X=(scrollx/16)
If min_X<0 Then min_X=0



max_y=(map_hoehe*16)+scrolly
If max_y>600 Then max_map_y_subtraktion=max_y-600
If max_y<=600 Then max_map_y_subtraktion=0
max_map_y=(map_hoehe-(max_map_y_subtraktion/16))+scrolly/16
If max_map_y<1 Then max_map_y=0
min_y=(scrolly/16)
If min_y<0 Then min_y=0
End Function 

Function auf_map_malen()

If MouseDown(1) Then map[mx2,my2,layer]=4
mx2=(MouseX()/16)-(scrollx/16) 
my2=(MouseY()/16)-(scrolly/16) 

End Function

Function map_zeichnen()

For mlayer=1 To layer
For map_x=0 To 50
For map_y=0 To 35
DrawImage tiles,(map_x*16),(map_y*16),map[map_x+scrollx,map_y+scrolly,mlayer] 
Next
Next
Next 

End Function