Sprite...HELP

Blitz3D Forums/Blitz3D Beginners Area/Sprite...HELP

Mr. Slat(Posted 2006) [#1]
I'm trying to create a trasparent Sprite with a number in it .I've wrote this but it doesn't appear black.

Sprite = CreateSprite()
NTex = CreateTexture()
SetBuffer ImageBuffer(NTex)
ClsColor 0,0,0
Cls
Text 0,0, "50"
SetBuffer BackBuffer()
EntityTexture Sprite, NTex
PositionEntity Sprite, 0,0,0

I also tried "TextureFilters Ntex, 4" but i doesn't appear transparent.
What shoul I do?


b32(Posted 2006) [#2]
;( Hmm, "ImageBuffer" on a texture ? :) Anyway, I've had the same problem creating a transparent texture. The only workaround I know is to save the texture to disk and then loading it using the right flags:



Matty(Posted 2006) [#3]
I am fairly sure that if you create a texture from scratch in blitz3d and want it to have transparent regions you need to set the rgba values in the texture such that the alpha value is zero in the transparent regions. This is an often discussed point, at least I've seen it come up a fair bit. Although when a texture is loaded it treats 'black' pixels as transparent any texture you make at runtime needs to have the alpha value set to zero for the transparent pixels.

This code archive may assist somewhat:

http://blitzbasic.com/codearcs/codearcs.php?code=1013


Mr. Slat(Posted 2006) [#4]
Hey bram thanks for the advice...but SaveImage Takes a lot of time..... I've come up with EntityBlend Ntex, 3, and it dows the trick.
And Matty thanks too... Best Wishes


b32(Posted 2006) [#5]
It seems to work very nice, and it is much better than saving&loading. Thanks!


IPete2(Posted 2006) [#6]
The other way would be to just have a generic blank texture, load this in everytime you want to create a new texture(with the relevant setting) and add your number on top.


Matty(Posted 2006) [#7]
I'm not sure that would work IPete2 - I think the alpha information, which is used for masking in blitz is lost when you draw to a texture unless you specifically set the alpha values of each pixel.


Mr. Slat(Posted 2006) [#8]
Just one more Thing. Is it possible to get the sprite Width and Height. For instance, The text is drawn at 0, 0 And if I place the Sprite in the enemy position It will appear a litlle on the left, and what I wanted is to make it apeear in the middle of the texture so that the Text is drawn right in front of the enemy. What I've done is Resize the Texture to 200, 200 and draw the text at 120, 100. And it works. but I personally think that this is bad programming, and by getting the Sprite size maybe I could draw the tex in the exact middle of the Sprite. By Leng(the_Text) For instance: (SPrite_Width/2) - (Leng(Ntext)*6) ; 6 is the lenght of each Letter

Excuse for Any Inglish Mistakes eheheh (it's not my native language ya know =P)

Best Wishes


b32(Posted 2006) [#9]
If you use the Text command, it has 2 parameters to center the text:
Text 256, 256, "Hello", true, true
To get the text's width, use StringWidth() and StringHeight().
I'm not sure how to get the sprite's width, maybe it is relative to the texture's width?