Get dimensions of a sprite

BlitzMax Forums/MiniB3D Module/Get dimensions of a sprite

ima747(Posted 2009) [#1]
Seems like there should be a really obvious way to do this but all I can come up with is convoluted or wasteful.

I create a sprite with LoadSprite(), how do I go about determining the dimensions of the picture file I just gave it?

I could load the picture with bmax commands and get it's size that way but that's loading it twice just to unload one of them a second later which is going to take forever if I've got to do a lot of pictures, especially larger ones.

Can't seem to find anything in minib3d that would just tell me, so I assume I need to dig through the surface list of the sprite, and the brush on the surface, and the texture on the brush, and maybe I can get to the loaded pixmap in there to use PixmapHeight and PixmapWidth...

Any ideas or a sample I've missed somewhere?


_Skully(Posted 2009) [#2]
Well, you could load the texture and apply that to a new sprite.. this way you get the information you need from the texture. loadsprite is more a convenience function should you not need to manipulate it as I recall


ima747(Posted 2009) [#3]
Hmm I didn't know you could texture a tsprite. I was under the impression that sprites worked on a system seperate from the normal meshes so they could be batched for more speed. Perhaps I missunderstood, I'll look into loading->reading dimensions-> applying


ima747(Posted 2009) [#4]
So I went back to my first idea of digging through the sprite to find the texture. However there doesn't appear to be a texture associated with it... I can get the surface, and the brush on the surface, but never get a texture...

Local sprite:TSprite = LoadSprite("sprite.jpg")
if(sprite)
     print "- got a sprite"
                Local surf:TSurface = GetSurface(sprite, 1)
		If(surf)
			Print "Got surf"
			Local brush:TBrush = GetSurfaceBrush(surf)
			If(brush)
				Print "Got Brush"
				Local tex:TTexture = GetBrushTexture(brush)
				If(tex)
					Print "got tex" ' never gets here...
				End If
			End If
		End If
end if



ima747(Posted 2009) [#5]
Following Skully's idea I picked apart TSprite.bmx and basically re-wrote the loader in my app, but I'm still curious why I can't find the texture on a sprite either by GetEntityTexture or digging through the surface->brush->texture.

Additionally texture width and height return the loaded texture size, not the picture file dimensions. i.e. 512x256 instead of the 320x240 of the picture. So I think I might need to load the pixmap, get the dimensions then convert that to a texture then apply the texture... but I don't recall how to convert a pixmap to a texture so I gotta go digging.


ima747(Posted 2009) [#6]
search > my memory

http://blitzmax.com/Community/posts.php?topic=81493#918255

some code I wrote on another project that ran away... I need fewer hard drives and more memory.