Hi! I want to be able to stop my scrolling tilemap when it reaches the outer edges of the map. ie for instance if we get to the end right of the map i dont want it to scroll anymore.
I have tried to calculate how big the actual map is and tried to use the width and height of the map to check for boundaries but this doesnt appear to work.
heres all the code: the tiles are 32*32 pixels.
And here is the the function that checks the borders.
ANy help would be appreciated. I got some help on COders workshop but litterally without someone giving me the codes I doubt I'll get it right.
Thanks :)
I have tried to calculate how big the actual map is and tried to use the width and height of the map to check for boundaries but this doesnt appear to work.
heres all the code: the tiles are 32*32 pixels.
Strict Graphics 1024,768,16,60 Global tiles:TImage = LoadAnimImage("tileset.png",32,32,0,3) Global mapx:Int = 60 Global mapy:Int = 60 Global scrollx:Int = 0 ' track scrolling on x axis Global scrolly:Int = 0 ' track scrolling on y axis Global mapendx:Int = 0 Global mapendy:Int = 0 Global curtile = 0 Global map:Int[mapx,mapy] init_map() Repeat Cls placetile() update_map() scroll_map() DrawImage tiles,MouseX()/32*32,MouseY()/32*32,curtile If MouseHit(KEY_MOUSERIGHT) curtile:+1 If curtile >2 Then curtile = 0 EndIf FlushMem Flip Until KeyHit(KEY_ESCAPE) Function init_map() For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 map[x,y] = 2 mapendx:+32 mapendy:+32 Next Next End Function Function placetile() If MouseDown(KEY_MOUSELEFT) map[(MouseX()-scrollx)/32,(MouseY()-scrolly)/32] = curtile EndIf End Function Function update_map() For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 DrawImage tiles,scrollx+x*32,scrolly+y*32,map[x,y] Next Next End Function Function scroll_map() If KeyDown(KEY_LEFT) scrollx:-3 ElseIf KeyDown(KEY_RIGHT) scrollx:+3 EndIf If KeyDown(KEY_UP) scrolly:-3 ElseIf KeyDown(KEY_DOWN) scrolly:+3 EndIf End Function Function check_borders() If scrollx > 1920 * 32 Then scrollx = 1920 If scrollx < 0 Then scrollx = 0 If scrolly > 1920* 32 Then scrolly = 1920 If scrolly < 0 Then scrolly = 0 End Function
And here is the the function that checks the borders.
Function check_borders() If scrollx > 1920 * 32 Then scrollx = 1920 If scrollx < 0 Then scrollx = 0 If scrolly > 1920* 32 Then scrolly = 1920 If scrolly < 0 Then scrolly = 0 End Function
ANy help would be appreciated. I got some help on COders workshop but litterally without someone giving me the codes I doubt I'll get it right.
Thanks :)