Tiled - Tmx to DataSection w/example PB 5.21

Advanced game related topics
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Tiled - Tmx to DataSection w/example PB 5.21

Post 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
Last edited by J. Baker on Sun Nov 24, 2013 1:50 am, edited 4 times in total.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post by J. Baker »

I added some basic key movements. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Zach
Addict
Addict
Posts: 1656
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Tiled - Tmx to DataSection w/example

Post by Zach »

Thanks for sharing, I might be able to use this down the road
Image
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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
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,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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
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
Last edited by J. Baker on Sat Nov 23, 2013 11:39 pm, edited 1 time in total.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Tiled - Tmx to DataSection w/example

Post 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.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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! ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Tiled - Tmx to DataSection w/example

Post 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
----

R Tape loading error, 0:1
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
True29
User
User
Posts: 64
Joined: Sun Feb 03, 2013 1:50 am

Re: Tiled - Tmx to DataSection w/example

Post 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
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post 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"?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
True29
User
User
Posts: 64
Joined: Sun Feb 03, 2013 1:50 am

Re: Tiled - Tmx to DataSection w/example

Post 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)+"") 
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Tiled - Tmx to DataSection w/example

Post by J. Baker »

Glad to hear it's working for you. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
True29
User
User
Posts: 64
Joined: Sun Feb 03, 2013 1:50 am

Re: Tiled - Tmx to DataSection w/example

Post 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.
Post Reply