Another TexturePacker loader

Monkey Forums/Monkey Code/Another TexturePacker loader

Tri|Ga|De(Posted 2012) [#1]
My latest game(First Monkey Game) uses the fantomEngine (Got the book) and it uses sprite sheets. I also got TexturePacker and wanted to use it in my game. So heres some code I made.

Export your data as LibGDX in TexturePacker.

Define these fields:

	'** TexturePacker variables
	Field tpStringFromFile:String
	Field tpAllStrings:String[]
	Field tpXPos:Int
	Field tpYPos:Int
	Field tpWidth:Int
	Field tpHeight:Int


This is my GetTexturePackerData method:

	
	'** Get TexturePacker Image Data
	Method GetTexturePackerData:Void(imageName:String)
		For Local count:Int = 0 To tpAllStrings.Length()-1
			If( String(tpAllStrings[count]).ToLower() = imageName) Then
				'** Get X, Y
				Local strXY:String = tpAllStrings[count+2]
				strXY = strXY.Replace("xy:","").Trim()
				Local strXYsplit:String[] = strXY.Split(",")
				tpXPos = Int(strXYsplit[0])
				tpYPos = Int(strXYsplit[1])
				
				'** Get Width, Height
				Local strWH:String = tpAllStrings[count+3]
				strWH = strWH.Replace("size:","").Trim()
				Local strWHsplit:String[] = strWH.Split(",")
				tpWidth = Int(strWHsplit[0])
				tpHeight = Int(strWHsplit[1])
			Endif
		Next
	End

Just give it the image name you want to get and it gets the position and size.
And it fills the field we defines at the top.
BUT its easy to modify my code.

Example using the GetTexturePackerData:
		GetTexturePackerData("turretbase")
		plBase = eng.CreateImage(td_spritesheet, tpXPos, tpYPos, tpWidth, tpHeight, cw/2, ch/2)

plBase is an image create with fantomEngines CreateImage command.

@Mike Hart
If you want you can use this code in your fantomEngine.

I hope this can be useful for anybody.


MikeHart(Posted 2012) [#2]
@TriGaDe: Could you provide me a test map, I don't have Texturepacker.


Tri|Ga|De(Posted 2012) [#3]
You can get them here.

Graphics file
Text file


MikeHart(Posted 2012) [#4]
Thanks


MikeHart(Posted 2012) [#5]
Ok, implemented. Will be available in the next version.


Tri|Ga|De(Posted 2012) [#6]
Glad I could help!