Damage Numbers

Blitz3D Forums/Blitz3D Programming/Damage Numbers

Whats My Face(Posted 2009) [#1]
How would I go about creating a sprite on the fly, in-game with numbers and such on it? The kind of thing you would use to indicate how much damage was done by the last strike or something that could be used to write how much health a creature has on a health bar sprite over his head.


Jerome Squalor(Posted 2009) [#2]
;sprite to be used
sprite = CreateSprite();

;texture to put onto the sprite
tex = CreateTexture()

;modify the texture
SetBuffer TextureBuffer(tex)

; impretty sure this can be drawimage also
Text 0,0,"Whatever you want to write"

;go back to the original buffer
SetBuffer BackBuffer()


hope this helps


Whats My Face(Posted 2009) [#3]
That worked, although it was kind of slow. Ff there is a faster way to do it that would be nice. The problem I've run into now is that although I set the texture flag to 4 so that the black parts won't be drawn the black still shows up. On top of that when I set the flag to 4 my numbers go away.


GIB3D(Posted 2009) [#4]
Use this when you first create the texture/image. It adds in alpha pixels :)
LockBuffer TextureBuffer(Texture)
For x = 0 To TextureWidth(Texture)-1
	For y = 0 To TextureHeight(Texture)-1
		WritePixelFast y , x , 0, TextureBuffer(Texture)
	Next
Next
UnlockBuffer TextureBuffer(Texture)
I'm not sure if you have to keep adding it every time you change the texture/image though. You may have to... then again you may not... trial and error.


_Skully(Posted 2009) [#5]
Use an imagefont... MUCH faster than drawtext


Whats My Face(Posted 2009) [#6]
I can't seem to draw either images or text onto the texture buffer. Is there something that needs to be done before you can draw images/text to a texture. I am capable of drawing rectangles however.


_Skully(Posted 2009) [#7]
If memory serves... Setbuffer TextureBuffer(Texture)


Whats My Face(Posted 2009) [#8]
I've already done set the buffer to the texture buffer. Anything else? Additional information: I have found that when I set the texture flag to 1 (default) I can see the text but not when its set to 2/4 or 2+1/4+1.


Kryzon(Posted 2009) [#9]
Perhaps a quad for every character in the string?

Your damage numbers function would take in a string, and create one mesh formed from different quads. From then on you can do anything you want with it (i.e: position it on top of some model, move it above very slowly while gradually decreasing the opacity of the text like most RPG\RTS games do).

You should optimize the hell out of it: use a single texture for all the characters and control with the UV coordinates to select the appropriate character you want to display for each quad.

PS: You CAN do it this way, just so you know. It's not a theory or anything, it definitely works.

EDIT: Good things about this method: characters can have any effect or antialiasing (they're from a texture) and it's fast (should you clean each mesh text after it's not being seen anymore, of course).


Nate the Great(Posted 2009) [#10]
That worked, although it was kind of slow. Ff there is a faster way to do it that would be nice. The problem I've run into now is that although I set the texture flag to 4 so that the black parts won't be drawn the black still shows up. On top of that when I set the flag to 4 my numbers go away.



to fix this, load images that say 1,2,3, etc on them and draw them to the texture buffer via draw image. This should fix the problem with the black still showing up.


Whats My Face(Posted 2009) [#11]
No matter what I do I can't seem to get it to work. When I go to draw the numbers (using text or drawimage) it works for every texture flag but 2 and 4. Then instead of making the background invisible and the text visible it makes everything invisible. I can get images to show up with the 4 texture flag by using plot and rect however.

For an example of my problem look at the following code

Texture Flag 1 (can see text):
;basic set up
Graphics3D 800,600,16,2
SetBuffer BackBuffer()
SeedRnd(MilliSecs())

;set up camera and light
cam = CreateCamera()
light = CreateLight()

;basic background
For n = 1 To 200
	cube = CreateCube()
	PositionEntity cube,Rnd(-20,20),Rnd(-20,20),Rnd(5,25)
	EntityColor cube,Rnd(0,255),Rnd(0,255),Rnd(0,255)
Next

;create a texture and a sprite it can go on
texture = CreateTexture(32,32,1)
sprite = CreateSprite()

;prep the texture by drawing it as black so the program can see through it
SetBuffer TextureBuffer(texture)
LockBuffer TextureBuffer(texture)
For x = 0 To 31
	For y = 0 To 31
		WritePixelFast x,y,0,TextureBuffer(texture)
	Next
Next
UnlockBuffer TextureBuffer(texture)

;now draw the word text on it in white
Text 0,0,"Text"
SetBuffer BackBuffer()

;actually texture the entity
EntityTexture sprite,texture

;move the camera back so we can see everything
PositionEntity cam,0,0,-5

;main loop 
While Not KeyDown(1)
	
	UpdateWorld()
	RenderWorld()
	
	Flip
Wend 


Texture Flag 4 (can't see text):
;basic set up
Graphics3D 800,600,16,2
SetBuffer BackBuffer()
SeedRnd(MilliSecs())

;set up camera and light
cam = CreateCamera()
light = CreateLight()

;basic background
For n = 1 To 200
	cube = CreateCube()
	PositionEntity cube,Rnd(-20,20),Rnd(-20,20),Rnd(5,25)
	EntityColor cube,Rnd(0,255),Rnd(0,255),Rnd(0,255)
Next

;create a texture and a sprite it can go on
texture = CreateTexture(32,32,4)
sprite = CreateSprite()

;prep the texture by drawing it as black so the program can see through it
SetBuffer TextureBuffer(texture)
LockBuffer TextureBuffer(texture)
For x = 0 To 31
	For y = 0 To 31
		WritePixelFast x,y,0,TextureBuffer(texture)
	Next
Next
UnlockBuffer TextureBuffer(texture)

;now draw the word text on it in white
Text 0,0,"Text"
SetBuffer BackBuffer()

;actually texture the entity
EntityTexture sprite,texture

;move the camera back so we can see everything
PositionEntity cam,0,0,-5

;main loop 
While Not KeyDown(1)
	
	UpdateWorld()
	RenderWorld()
	
	Flip
Wend