News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Help w/ Maps.

Started by ionias, September 14, 2006, 08:34:32 PM

Previous topic - Next topic

ionias

Well I've run into my first problem. :) I've been tinkering around with the maps and cameras I can get them to work great w/ the examples. However, it is when I try to move my map creation and loading into a Function that I run into trouble. Let me show a quick example:

This works:


`_______________________________________________________________________________
` Map Editing routine.
`_______________________________________________________________________________

CreateCamera 1
LimitCamera 1,True
LimitCameraBounds 1,0,0,2100,2100
CaptureToScene
MyMap = GetFreeMap()
CreateMap MyMap, 1
MapImage_Tiles = LoadNewImage("graphics\map1_tiles.png")
MakeMapGFX MyMap, MapImage_Tiles, Tile_W, Tile_H, 16, RGB(197,252,78)
CreateLevel MyMap, 1, 100, 200

Do
     DrawMap MyMap,1,0,0
     DrawCamera 1 
     Sync
Loop


This however doesn't work: :(


`_______________________________________________________________________________
` Map Editing routine.
`_______________________________________________________________________________

CreateCamera 1
LimitCamera 1,True
LimitCameraBounds 1,0,0,2100,2100
CaptureToScene
MyMap = Build_Map("map1_tiles")

Do
     DrawMap MyMap,1,0,0
     DrawCamera 1 
     Sync
Loop

End

`_______________________________________________________________________________
Function Build_Map(MapToBuild$)
      MyMap = GetFreeMap()
      CreateMap MyMap, 1
      MapImage_Tiles = LoadNewImage("graphics\" +MapToBuild$+ ".png")
      MakeMapGFX MyMap, MapImage_Tiles, 32, 32, 16, RGB(197,252,78)
      CreateLevel MyMap, 1, 100, 200
EndFunction TheNewMap


I have no idea why? I also tried using LoadMapGFX with a .bmp file and the same result. Help me out please, what am I doing wrong?

kevin

 Try this,  it looks like your not returning the "MyMap" variable out of the function. 


`_______________________________________________________________________________
` Map Editing routine.
`_______________________________________________________________________________

CreateCamera 1
LimitCamera 1,True
LimitCameraBounds 1,0,0,2100,2100
CaptureToScene
MyMap = Build_Map("map1_tiles")

Do
     DrawMap MyMap,1,0,0
     DrawCamera 1 
     Sync
Loop

End

`_______________________________________________________________________________
Function Build_Map(MapToBuild$)
      MyMap = GetFreeMap()
      CreateMap MyMap, 1
      MapImage_Tiles = LoadNewImage("graphics\" +MapToBuild$+ ".png")
      MakeMapGFX MyMap, MapImage_Tiles, 32, 32, 16, RGB(197,252,78)
      CreateLevel MyMap, 1, 100, 200
EndFunction MyMap


ionias

Thanks, I got it to work now. However, I get an error when I use the LoadMapGfx command saying the blocks can't be loaded? I have no problem with the MakeMapGfx command. I wanted to use the LoadMapGfx to save the time and effort of loading and image and then loading it into the map. Is there something I'm missing?  :-\

Again this works below: (MapToBuild$ = "defaulttiles.png")


Function Build_Map(MapToBuild$)
` Create a map.
MapToBuild = GetFreeMap()
CreateMap MapToBuild, 1

` Load the .png file to convert to map tiles.
MapImage_Tiles = Load_Image(MapToBuild$)
MakeMapGFX MapToBuild, MapImage_Tiles, 32, 32, 16, RGB(197,252,78)

             ` Create the level 1 in the map.
CreateLevel MapToBuild, 1, 100, 200
EndFunction MapToBuild


But this doesn't work, strange. (MapToBuild$ = "defaulttiles.bmp")


Function Build_Map(MapToBuild$)
` Create a map.
MapToBuild = GetFreeMap()
CreateMap MapToBuild, 1

` Load the .bmp file to convert to map tiles.
LoadMapGFX MapToBuild$, MapToBuild, 32, 32, 16, RGB(197,252,78)

             ` Create the level 1 in the map.
CreateLevel MapToBuild, 1, 100, 200
EndFunction MapToBuild

kevin

  The problem with LoadMapGFX is that it's very fussy about the bitmap your loading.   From memory it expects the bitmap to be 24bit, but a lot of paint packages seem to save BMP's as 32bit.  Which it doesn't seem to like.  For now, i'd use the first method. 


Big C.

yes, i had the same problem wir LoadMapGFX...

Do you have look at my TileLoader? See here... Maybe it could help you..

ionias

QuoteThe problem with LoadMapGFX is that it's very fussy about the bitmap your loading.   From memory it expects the bitmap to be 24bit, but a lot of paint packages seem to save BMP's as 32bit.  Which it doesn't seem to like.  For now, i'd use the first method. 

Aha ha! I was going crazy trying to figure out what I was doing wrong. Glad I posted here. Thanks for the answer. :)

QuoteDo you have look at my TileLoader? See here... Maybe it could help you..

Yes, I did see that. I wanted to build one from scratch on my own to teach myself about how PB handles maps etc... But thanks, I'll keep that page bookmarked.