Sprites

Blitz3D Forums/Blitz3D Beginners Area/Sprites

pc_tek(Posted 2008) [#1]
I am slowly coming to terms with sprites in B3d. One question has arisen which is, quite frankly, pissing me off.

Everytime I loadsprite or createsprite, the damn thing is square!. How do I make the sprite dimensions the same as the shape I am loading?


olo(Posted 2008) [#2]
you could scaleentity them to make them look how you want

e.g.
 scaleentity sprite, 0.5, 0.5, 0.5 


this will make all of the sprites dimensions 0.5 times smaller.

is this what you were looking for??


Warner(Posted 2008) [#3]
Does that work ? There is also ScaleSprite.


pc_tek(Posted 2008) [#4]
I'm experimenting with scaleentity right now, but surely this is crazy? If I loadsprite that is 100x50, I expect to see an oblong sprite - not a square with the graphic squished inside it!

Man, this is frustrating.


olo(Posted 2008) [#5]
can i see some code please..it could help me understand why it aint working


pc_tek(Posted 2008) [#6]
It's easy to try it yourself...just create a graphic that is oblong rather than square and load it in using LoadSprite()

Place it on the screen to see the result. A frigging Square!!!

Code:

Graphics3D 800,600,16,2
SetBuffer BackBuffer()

sprite = LoadSprite ("rectangle.png")
camera = CreateCamera()

PositionEntity sprite,0,0,2
While Not KeyDown(1)
Cls
RenderWorld
VWait:Flip 0
Wend
EndGraphics
End


Warner(Posted 2008) [#7]
A sprite is a white object with a texture. Textures are rescaled by default to the closest power of two. So if you try to load a texture that is 100 x 50, the texture will have a size of 128 x 64. So in the process of creating the sprite, the aspect ratio of the image gets lost.


olo(Posted 2008) [#8]
if it is a simple rectangle i would use createcube instead of loading an image and then scaling it to make it a rectangle like this:
Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;this creates the cube but i later scale it to form a rectangle

rectangle=CreateCube() ;\this creates a normal cube, without the scaling it would be a 3d cube

PositionEntity rectangle, 0,0,2

ScaleEntity rectangle, 0.3,0.6,1 ;this scales the cube so that it is long on the y axes and shorter on the x

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
While Not KeyDown(1)
Cls
RenderWorld
VWait:Flip 0
Wend
EndGraphics
End 


tell me if this helps


pc_tek(Posted 2008) [#9]
That ratio is fine (128x64), but thats not what is happening. The sprite is being scaled as a square...in the example, the sprite loaded is 100x50, whilst the display shows it as being 400x400!


pc_tek(Posted 2008) [#10]
I don't want to create 'pure 3d' objects. I am attempting to work with sprites. In fact, I have learnt more with sprites than I ever have with 3d objects such as a cube or cone. Go figure.


Warner(Posted 2008) [#11]
This function rescales the sprite when loading it. You can use it instead of LoadSprite:
Function MakeSprite(tex$, fl=1+8, p=0)

	sp = LoadSprite(tex$, fl, p)
	tex = LoadTexture(tex$)
	ScaleSprite sp, TextureWidth(tex), TextureHeight(tex)
        FreeTexture tex
	
	Return sp
	
End Function



Ross C(Posted 2008) [#12]
Yeah, unfortunatly the sprite is always created square.

All you really need to do is create sprite, then load texture(). Apply the sprite to the texture. Check the texturewidth() and textureheight() and scale accordingly :o)

I'm not sure what you mean about it being displayed 500x500. Screen pixels really don't mean much in the 3d world, unless you've set up a system to properly convert blitz units in pixel co-ords.


pc_tek(Posted 2008) [#13]
Thanks you motley lot for all your help...much appreciated!

I'm now getting a handle on things scale-wise. Jeez, what a job!

I used Ross' scaling/2...that with a mixture of positionentity gives me a rough correct size.


Nope...scratch that! *weeps in despair*


Warner(Posted 2008) [#14]
To get the exact aspect ratio, try scaling the sprite accordingly to the size of the original image:
Function MakeSprite(tex$, fl=1+8, p=0)

	sp = LoadSprite(tex$, fl, p)
	img = LoadImage(tex$)
	ScaleSprite sp, ImageWidth(img)/64.0, ImageHeight(img)/64.0
        FreeImage img
	
	Return sp
	
End Function



Ross C(Posted 2008) [#15]
Yeah, scaling the sprite is all about getting the size ratio between the width and height. Your not really going to want to scale the sprite by the pixel co-ords :o)

So if it's 64 wide x 128 high, then scale sprite:

ScaleSprite sprite,1,2


pc_tek(Posted 2008) [#16]
Cheers Ross!