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