Page 1 of 2

Tiled - Tmx to DataSection w/example PB 5.21

Posted: Tue Aug 21, 2012 8:15 am
by J. Baker
Here's how to take map data from the app called "Tiled". The first bit of code is for converting a "*.tmx" (csv) Tiled file, to PureBasic's DataSection. That only needs slight modification for the values of your own project. The second bit of code is an example of using the "desert.tmx" example from Tiled. Just so you can see a simple working version. Just make sure that if you test it out, the tmx file has to be exported in csv which can be changed in options of Tiled. Enjoy! ;)

Download Tiled: http://www.mapeditor.org

Updated Novenber 23, 2013
Fixed an error that if there were "0's" (no tile) in the DataSection, it would bypass them and continue to the next tile information.

Tmx to DataSection...

Code: Select all

Location$ = GetHomeDirectory() + "Desktop/" ;Change this to your working directory.
File$ = "desert" ;Change this to the "*.tmx" file you are converting (without extension).
Level = 1 ;Change this value to the level you are working on.

;---Don't change the settings below this line unless noted---

Ext$ = ".tmx"
Layer = 1
NextLayer = 0 

CreateFile(1, Location$ + File$ + ".pbi")
WriteStringN(1, "Level" + Str(Level) + "Data:")
WriteStringN(1, "Data.u 40, 40, 32, 32, 1, 265, 199") ;Set this with: GameWidth, GameHeight, ClipWidthSize, ClipHeightSize, Spacing, ImageWidth and ImageHeight
WriteStringN(1, "Level" + Str(Level) + "Layer1:")

If ReadFile(0, Location$ + File$ + Ext$)
  While Eof(0) = 0
     String$ = ReadString(0)
      If FindString(String$, "<", 1) = 0
         WriteStringN(1, "Data.u " + RTrim(String$, ","))
        NextLayer = 1
      Else
        If NextLayer = 1
            Layer + 1
           NextLayer = 0
            WriteStringN(1, "Level" + Str(Level) + "Layer" + Str(Layer) + ":")
        EndIf 
      EndIf
    Wend
    CloseFile(0)
     FileSeek(1, Loc(1) - (Len("Level" + Str(Level) + "Layer" + Str(Layer) + ":") + 2))
     TruncateFile(1)
    CloseFile(1)
   MessageRequester("Congrats!","Level " + Str(Level) + " is ready to be imported!")
Else
   MessageRequester("Error!","Unable to open, " + Chr(34) + Location$ + File$ + Ext$ + Chr(34) + "!")
EndIf
Desert.tmx example...

Code: Select all

#WindowWidth = 1280
#WindowHeight = 720

Procedure TmxDrawLevel1Layer1( KeyX, KeyY)
  
  TmxRow = 0
  TmxCol = 0
  
  Restore Level1Data
   Read.u TmxGameWidth
   Read.u TmxGameHeight
   Read.u TmxClipWidth
   Read.u TmxClipHeight
   Read.u TmxSpacing
   Read.u TmxSpriteWidth
   Read.u TmxSpriteHeight
  
  Restore Level1Layer1
  
  For TmxLoadLevel = 1 To TmxGameWidth * TmxGameHeight
   Read.u TmxTile
    
    If TmxTile = 0
     TmxCol + TmxClipWidth
     If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
     EndIf
      Continue
    EndIf
    
     TmxColumns = (TmxSpriteWidth - TmxSpacing) / (TmxClipWidth + TmxSpacing)
     
     If (TmxTile % TmxColumns) = 0
       TmxLastColumn = TmxColumns
     Else
       TmxLastColumn = (TmxTile % TmxColumns)
     EndIf
     
    ClipSprite(0, ((TmxClipWidth + TmxSpacing) * TmxLastColumn) - TmxClipWidth, (TmxClipHeight + TmxSpacing) * ((TmxTile - 1) / TmxColumns) + TmxSpacing, TmxClipWidth, TmxClipHeight)

    DisplayTransparentSprite(0, TmxCol + KeyX, TmxRow + KeyY)
    
     TmxCol + TmxClipWidth
    
    If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
    EndIf
    
  Next
  
EndProcedure

UsePNGImageDecoder()
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Tiled TMX Desert Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
 OpenWindowedScreen(WindowID(0), 0, 0, #WindowWidth, #WindowHeight, 0, 0, 0, 1)
 
  CatchSprite(0, ?Pic0, #PB_Sprite_AlphaBlending)
  
Repeat
  
  Event = WindowEvent()
   ExamineKeyboard()
   FlipBuffers()
   ClearScreen(0)
   
   TmxDrawLevel1( X, Y)
   
   If KeyboardPushed(#PB_Key_Up)
     Y + 5
   ElseIf KeyboardPushed(#PB_Key_Down)
     Y - 5
   ElseIf KeyboardPushed(#PB_Key_Right)
     X - 5
   ElseIf KeyboardPushed(#PB_Key_Left)
     X + 5
   EndIf
   
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

DataSection
 Pic0:
  IncludeBinary "tmw_desert_spacing.png"
 Level1Data:
  Data.u 40, 40, 32, 32, 1, 265, 199
 Level1Layer1:
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,14,15,16,30,31,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,31,22,23,24,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,1,2,3,30,30,31,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,40,30,30,30,30,33,34,36,42,37,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,33,34,35,30,33,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,38,30,30,33,34,35,30,33,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,48,38,30,30,30,30,33,34,44,26,45,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,40,30,30,30,40,30,30,30,33,34,34,34,34,34,34,34,36,42,37,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 40,30,30,30,30,40,38,30,30,38,30,33,34,34,34,34,34,34,34,44,26,45,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,39,30,30,30,38,30,40,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,39,30,30,30,30,30,30,30,41,42,42,42,42,42,42,42,42,42,42,42,43,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 7,7,8,1,2,2,2,2,2,2,2,2,3,1,2,2,2,2,2,2,2,2,2,2,29,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 15,15,16,9,10,10,10,10,10,10,10,10,11,9,10,10,10,10,10,10,10,10,10,10,10,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 23,23,24,17,18,18,18,18,18,18,18,18,19,17,18,18,18,18,18,18,18,18,18,18,18,18,19,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,31
  Data.u 30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32
  Data.u 39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,30,33,34,34,34,34,34,34,34,34,36,42,37,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,47,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,39,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,44,26,45,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,47,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,48
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,41,42,42,42,42,42,42,42,42,42,42,42,43,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,31,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
EndDataSection

Re: Tiled - Tmx to DataSection w/example

Posted: Tue Aug 21, 2012 8:50 am
by J. Baker
TIP: When making your own game, draw all of your none collision objects in one layer. Then draw all of your collision objects, such as walls and stuff in another layer. That way, all you have to do is call collision on one sprite sheet in like your second layer or something like that. Then you just have to be creative for any "enemy" collision which shouldn't be too hard to figure out. ;)

Re: Tiled - Tmx to DataSection w/example

Posted: Tue Aug 21, 2012 9:36 am
by J. Baker
I added some basic key movements. ;)

Re: Tiled - Tmx to DataSection w/example

Posted: Tue Aug 21, 2012 6:42 pm
by Zach
Thanks for sharing, I might be able to use this down the road

Re: Tiled - Tmx to DataSection w/example

Posted: Tue Aug 21, 2012 7:32 pm
by J. Baker
Zach wrote:Thanks for sharing, I might be able to use this down the road
No problem. I hope it comes in handy for you. ;)

Re: Tiled - Tmx to DataSection w/example

Posted: Fri Aug 24, 2012 3:45 am
by J. Baker
Just playing around with a second layer. The movement for this layer has been removed just to show what is on the second layer. Not much really. Also, I updated the code to skip the "0's" in the data section, else it caused an error when displaying sprites.

Code: Select all

#WindowWidth = 1280
#WindowHeight = 720

Procedure TmxDrawLevel1Layer1( KeyX, KeyY)
  
  TmxRow = 0
  TmxCol = 0
  
  Restore Level1Data
   Read.u TmxGameWidth
   Read.u TmxGameHeight
   Read.u TmxClipWidth
   Read.u TmxClipHeight
   Read.u TmxSpacing
   Read.u TmxSpriteWidth
   Read.u TmxSpriteHeight
  
  Restore Level1Layer1
  
  For TmxLoadLevel = 1 To TmxGameWidth * TmxGameHeight
   Read.u TmxTile
    
    If TmxTile = 0
     TmxCol + TmxClipWidth
     If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
     EndIf
      Continue
    EndIf
    
     TmxColumns = (TmxSpriteWidth - TmxSpacing) / (TmxClipWidth + TmxSpacing)
     
     If (TmxTile % TmxColumns) = 0
       TmxLastColumn = TmxColumns
     Else
       TmxLastColumn = (TmxTile % TmxColumns)
     EndIf
     
    ClipSprite(0, ((TmxClipWidth + TmxSpacing) * TmxLastColumn) - TmxClipWidth, (TmxClipHeight + TmxSpacing) * ((TmxTile - 1) / TmxColumns) + TmxSpacing, TmxClipWidth, TmxClipHeight)

    DisplayTransparentSprite(0, TmxCol + KeyX, TmxRow + KeyY)
    
     TmxCol + TmxClipWidth
    
    If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
    EndIf
    
  Next
  
EndProcedure

Procedure TmxDrawLevel1Layer2( KeyX, KeyY)
  
  TmxRow = 0
  TmxCol = 0
  
  Restore Level1Data
   Read.u TmxGameWidth
   Read.u TmxGameHeight
   Read.u TmxClipWidth
   Read.u TmxClipHeight
   Read.u TmxSpacing
   Read.u TmxSpriteWidth
   Read.u TmxSpriteHeight
  
  Restore Level1Layer2
  
  For TmxLoadLevel = 1 To TmxGameWidth * TmxGameHeight
   Read.u TmxTile
   
   If TmxTile = 0
     TmxCol + TmxClipWidth
     If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
     EndIf
      Continue
   EndIf
   
     TmxColumns = (TmxSpriteWidth - TmxSpacing) / (TmxClipWidth + TmxSpacing)
     
     If (TmxTile % TmxColumns) = 0
       TmxLastColumn = TmxColumns
     Else
       TmxLastColumn = (TmxTile % TmxColumns)
     EndIf
     
    ClipSprite(0, ((TmxClipWidth + TmxSpacing) * TmxLastColumn) - TmxClipWidth, (TmxClipHeight + TmxSpacing) * ((TmxTile - 1) / TmxColumns) + TmxSpacing, TmxClipWidth, TmxClipHeight)

    DisplayTransparentSprite(0, TmxCol, TmxRow)
    
     TmxCol + TmxClipWidth
    
    If TmxCol >= TmxGameWidth * TmxClipWidth
        TmxRow + TmxClipHeight
        TmxCol = 0
    EndIf
    
  Next
  
EndProcedure

UsePNGImageDecoder()
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Tiled TMX Desert Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
 OpenWindowedScreen(WindowID(0), 0, 0, #WindowWidth, #WindowHeight, 0, 0, 0, 1)
 
  CatchSprite(0, ?Pic0, #PB_Sprite_AlphaBlending)
  
Repeat
  
  Event = WindowEvent()
   ExamineKeyboard()
   FlipBuffers()
   ClearScreen(0)
   
   TmxDrawLevel1Layer1( X, Y)
   TmxDrawLevel1Layer2( X, Y)
   
   If KeyboardPushed(#PB_Key_Up)
     Y + 5
   ElseIf KeyboardPushed(#PB_Key_Down)
     Y - 5
   ElseIf KeyboardPushed(#PB_Key_Right)
     X - 5
   ElseIf KeyboardPushed(#PB_Key_Left)
     X + 5
   EndIf
   
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

DataSection
 Pic0:
  IncludeBinary "tmw_desert_spacing.png"
 Level1Data:
  Data.u 40, 40, 32, 32, 1, 265, 199
 Level1Layer1:
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,14,15,16,30,31,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,31,22,23,24,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,1,2,3,30,30,31,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,40,30,30,30,30,33,34,36,42,37,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,33,34,35,30,33,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,38,30,30,33,34,35,30,33,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,48,38,30,30,30,30,33,34,44,26,45,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,40,30,30,30,40,30,30,30,33,34,34,34,34,34,34,34,36,42,37,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 40,30,30,30,30,40,38,30,30,38,30,33,34,34,34,34,34,34,34,44,26,45,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,39,30,30,30,38,30,40,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,39,30,30,30,30,30,30,30,41,42,42,42,42,42,42,42,42,42,42,42,43,9,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 7,7,8,1,2,2,2,2,2,2,2,2,3,1,2,2,2,2,2,2,2,2,2,2,29,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 15,15,16,9,10,10,10,10,10,10,10,10,11,9,10,10,10,10,10,10,10,10,10,10,10,10,11,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 23,23,24,17,18,18,18,18,18,18,18,18,19,17,18,18,18,18,18,18,18,18,18,18,18,18,19,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,31
  Data.u 30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32
  Data.u 39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,30,33,34,34,34,34,34,34,34,34,36,42,37,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,47,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,39,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,44,26,45,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,47,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,48
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,41,42,42,42,42,42,42,42,42,42,42,42,43,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,31,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
  Data.u 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
 Level1Layer2:
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data.u 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EndDataSection

Re: Tiled - Tmx to DataSection w/example

Posted: Fri Aug 24, 2012 8:53 am
by wilbert
When the number of tiles the map has doesn't exceed 256, you could use the .a type instead of .u .
It would consume half the space. On the other hand, map data usually isn't that big.

Re: Tiled - Tmx to DataSection w/example

Posted: Fri Aug 24, 2012 12:32 pm
by J. Baker
wilbert wrote:When the number of tiles the map has doesn't exceed 256, you could use the .a type instead of .u .
It would consume half the space. On the other hand, map data usually isn't that big.
Good point Wilbert, thanks! ;)

Re: Tiled - Tmx to DataSection w/example

Posted: Sun Jun 30, 2013 10:28 pm
by em_uk
This is excellent. I've been looking for a map creation tool for a good few days, I could have started to write my own but when reinvent the wheel. I'm keen to spend time programming the mechanics of my game :)

I tested quite a few applications, none really did what I wanted - then I just stumbled across Tiled - it looked great, had a quick look to see in anyone else had played with the software and found this post.

Thanks man!

Brilliant work :D

Re: Tiled - Tmx to DataSection w/example

Posted: Sun Jun 30, 2013 11:30 pm
by J. Baker
No problem! ;)

I had also thought about making my own "tile" application but like you said, no reason to reinvent the wheel. It was quite simple to just read the file and change it to data. :D

Re: Tiled - Tmx to DataSection w/example

Posted: Sat Nov 23, 2013 11:10 pm
by True29
hello , can anybody help .
i convert desert.tmx to pb and get this :(

Level1Data:
Data.u 40, 40, 32, 32, 1, 265, 199
Level1Layer1:
Data.u eJztmNkKwjAQRaN9cAPrAq5Yq3Xf6v9/nSM2VIbQJjEZR+nDwQZScrwztoORECLySBcIgZ7nc2y4KfyWDLx+Jb9nViNgDEwY+KioAXUgQN4+zpoCMwPmQAtoAx2CLFbA2oDEo9+hwG8DnIDtF/2K8ks086Tw2zH0uyMv7HcRr/6/EvvhnsPrsrxwX7rwU/0ODig/eV3mh3N1ld8eraWPaX6+64s9McesfrqcHfg1MpoifxcVEWjukyw+9AtFPl/I71pER3Of6j4bv7HI54s+MChhqLlPdZ/P3qMmFuo5h5NnTOhjM5tReN2yT51n5/v7J3F0vi46fk+ne7aX0i9l6If7mpufTX3f5wsqv9TAD2fJLT9VrTn7UeZnM5tR+v0LMQOHXwFnxe2/warGFRWf8QDjOLfP

have newest pb.
and use the convert tool from J. Baker.

Thanks

Re: Tiled - Tmx to DataSection w/example

Posted: Sat Nov 23, 2013 11:46 pm
by J. Baker
True29 wrote:hello , can anybody help .
i convert desert.tmx to pb and get this :(

Level1Data:
Data.u 40, 40, 32, 32, 1, 265, 199
Level1Layer1:
Data.u eJztmNkKwjAQRaN9cAPrAq5Yq3Xf6v9/nSM2VIbQJjEZR+nDwQZScrwztoORECLySBcIgZ7nc2y4KfyWDLx+Jb9nViNgDEwY+KioAXUgQN4+zpoCMwPmQAtoAx2CLFbA2oDEo9+hwG8DnIDtF/2K8ks086Tw2zH0uyMv7HcRr/6/EvvhnsPrsrxwX7rwU/0ODig/eV3mh3N1ld8eraWPaX6+64s9McesfrqcHfg1MpoifxcVEWjukyw+9AtFPl/I71pER3Of6j4bv7HI54s+MChhqLlPdZ/P3qMmFuo5h5NnTOhjM5tReN2yT51n5/v7J3F0vi46fk+ne7aX0i9l6If7mpufTX3f5wsqv9TAD2fJLT9VrTn7UeZnM5tR+v0LMQOHXwFnxe2/warGFRWf8QDjOLfP

have newest pb.
and use the convert tool from J. Baker.

Thanks
In Tiled, did you set the "Layer format:" to "CSV"?

Re: Tiled - Tmx to DataSection w/example

Posted: Sun Nov 24, 2013 12:59 am
by True29
ok ;) thank you. now he reads the correct position of images .
but he takes the wrong image.

fixed ;)
must change settings.

its easyer to make it this way.

Code: Select all

#mapsize = 40
#tilesize = 31
#tilemapsizex = 423
#tilemapsizey = 369
#spacing = 1

WriteStringN(1, "Data.u "+Str(#mapsize)+","+Str(#mapsize)+", "+Str(#tilesize)+", "+Str(#tilesize)+", "+Str(#spacing)+", "+Str(#tilemapsizex)+", "+Str(#tilemapsizey)+"") 

Re: Tiled - Tmx to DataSection w/example

Posted: Sun Nov 24, 2013 1:39 am
by J. Baker
Glad to hear it's working for you. ;)

Re: Tiled - Tmx to DataSection w/example

Posted: Sun Nov 24, 2013 1:42 am
by True29
hm had you stop the work on it ? :( a great work is this tool.
and when why ? and can you tell me wich tiled engine/map editor you use ?
Greets.

have a nice evening.