Level editor.
BlitzMax Forums/BlitzMax Beginners Area/Level editor.
| ||
Hey, I'm having an issue with some code for a level editor, everything worked fine until I tried to put in the ability for it to load a previously saved file. After that the array for drawing the tiles on the screen decided it didn't need to work anymore. For Local y:Int = 0 To mapy-1 For Local x:Int = 0 To mapx-1 Local Backtile:Int = map[x,y,0] If Backtile > -1 Then DrawImage img_tiles:TImage,(x*tsize)-scn_left,(y*tsize) - scn_top,Backtile Next Next It works if I take off the last "Backtile" and replace it with pretty much any number or other variable I've found, but then of course it draws only the tile associated with that number, or the drawn tile changes as the variable changes. This is the full code: |
| ||
Hiya, When you're saving the file you're saving the 4 values before the map data :- WriteInt fileout,mapx WriteInt fileout,mapy WriteInt fileout,mapz WriteInt fileout,tsize When loading them back in you're only loading back in 3 before the map data :- If file <> Null Then mapx = ReadInt(file) mapy = ReadInt(file) mapz = ReadInt(file) tsize = ReadInt(file) ' <--------- This was missing Else mapx = 75 mapy = 50 mapz = 4 EndIf Because you have tsize as Const BMax will probably complain about this, so either don't save it or make it a variable. Also, you're not closing the file after loading the data :- If file <> Null Then For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 For Local z:Int = 0 To mapz-1 map[x,y,z] = ReadInt(file) Next Next Next CloseFile file '<-------------- Don't forget to close Else For Local x:Int = 0 To mapx-1 For Local y:Int = 0 To mapy-1 For Local z:Int = 0 To mapz-1 map[x,y,z] = -1 Next Next Next EndIf Have fun :D Last edited 2012 |
| ||
Perfect! Thank you very much! |