black smoke

Blitz3D Forums/Blitz3D Programming/black smoke

hello all, I have a quick question.
how can I make a black sprite that will still be able to fade away.

Im going for something like flac smoke in Frontlines: fuels of war where it appears in the game and then fades away

look for a sprite example in the samples folder that came with blitz
as for making it fade you need to set entityalpha mysprite.entity,1(ish)
and later in the update part of your code set it to a variable that you decrease slowly, just make sure that the variable is a float#.

What mtnhome3d said, but also make sure the image is bigger than the sprite's gradient, meaning: don't let your smoke sprite touch the borders of the image when you're drawing it, or else the in-game sprite will have some square-shaped borders.

In case you need a practical example, I just uploaded this thing I was going to use for a grenade explosion - I like doing stuff like this so I have a library of "special effects", like Screen-Fades, MotionBlur, Sprite Positioning, etc. Every sprite you see in the example was drawn by me in Photoshop 5, and I "grant you and everyone to do whatever they want with the sprites or the code". The sound effect is not mine.

Make SURE you unzip all the files in the same folder, and create a folder first, like, SmokeTest and then unzip the contents to it.

Link: http://www.freewebs.com/rafael_navega/GrenadeExplosion.rar

If you or anyone got any questions about the example, feel free to ask.

Here's an example. Import a png file to get a better idea of how it looks. Basically this creates a sprite and fades it for you.


Graphics3D 640,480
SetBuffer BackBuffer()
AppTitle "Smoke Effect Demonstration"
SeedRnd MilliSecs()

;Hopyfully this is understandable, I tried to use field names that were easily understood


Type smoke								;create a TYPE called smoke
	Field smoke_sprite					;this is simply a name for the sprite that will be loaded
	Field smoke_x						;starting x coordinate of sprite
	Field smoke_y						;same for y
	Field smoke_z						;and z
	Field smoke_alpha#					;starting alpha of the sprite, make sure it is a float #
	Field smoke_size#					;this will scale the sprite to a random # each time, make it a float also
	Field smoke_vertical_speed#			;this is how fast the sprite will rise in altitude, make float also
	Field smoke_horizontal_speed#		;this is how fast the sprite will go side to side, float #
	Field smoke_fade_speed# 			;and this is how fast the sprite will fade, make sure this is #
End Type


Global smoke_image = CreateSprite()				;for this demo, we'll use a simple flat sprite
;global smoke_image = LoadSprite("smoke.png")	;uncomment this and change smoke.png to your own sprite if you have one
SpriteViewMode smoke_image, 1					;make it always face the camera
HideEntity smoke_image							;and hide this entity


camera = CreateCamera()							;create a camera
MoveEntity camera, 0,0,-30						;move it backwards
		
;MAIN LOOP------------------------------			
While Not KeyDown(1)					;while ESC is not pressed
	user_input()						;this function gathers input from the user
	update_smoke()						;this function updates each sprite
	RenderWorld							;render the scene
	hud()								;this function displays text information to the screen
Flip 									;flip buffers
Wend
;END LOOP-------------------------------

Function user_input()
	If KeyHit(57)						;if space is hit
		
	For a = 1 To 5						;create 5 sprites
		billow.smoke = New smoke		;create a new SMOKE TYPE in a reference "container" named billow
			billow\smoke_sprite = CopyEntity(smoke_image)	;copy the preloaded hidden sprite
			billow\smoke_x = 0								;place x coords
			billow\smoke_y = 0								;and y coords
			billow\smoke_z = 0								;and z coords
			billow\smoke_alpha = 1							;start the alpha at 1
			billow\smoke_size = Rand(.3,2)					;pick a random number for scaling purposes
			billow\smoke_vertical_speed = Rnd(.05,.15)		;pick a random vertical movement number
			billow\smoke_horizontal_speed = Rnd(-.06,.06)	;pick a random horizontal movement number
			billow\smoke_fade_speed = Rnd(.01,.03)			;pick a random fade speed
			
			MoveEntity billow\smoke_sprite, billow\smoke_x, billow\smoke_y, billow\smoke_z	;move the entity to the picked coordinates
			ScaleSprite billow\smoke_sprite, billow\smoke_size, billow\smoke_size			;scale it by the randomly generated scale size
			EntityAlpha billow\smoke_sprite, billow\smoke_alpha								;and set the alpha to the picked alpha number
	Next
	End If
	
	If KeyHit(28)											;if Enter is hit
		billow.smoke = New smoke							;create a new SMOKE TYPE as above
			billow\smoke_sprite = CopyEntity(smoke_image)	;copy the image again
			billow\smoke_x = Rand(-7,7)						;place x coords
			billow\smoke_y = Rand(-7,7)						;and y coords
			billow\smoke_z = 0								;and z coords
			billow\smoke_alpha = 1							;set alpha to 1
			billow\smoke_size = Rand(4,6)					;pick a random number for scaling purposes
			billow\smoke_vertical_speed = 0					;this sprite isn't going to move, it's stationary				
			billow\smoke_horizontal_speed = 0				;same note as above line
			billow\smoke_fade_speed = .01					;set fade speed
			
			MoveEntity billow\smoke_sprite, billow\smoke_x, billow\smoke_y, billow\smoke_z	;move the entity to the picked coordinates
			ScaleSprite billow\smoke_sprite, billow\smoke_size, billow\smoke_size			;scale it by the randomly generated scale size
			EntityAlpha billow\smoke_sprite, billow\smoke_alpha	
	End If 
	
	If KeyHit(1)			;if ESC is hit
		ClearWorld			;clear the world or scene
		End					;and end the program
	End If 
			
End Function


Function update_smoke()			
	For billow.smoke = Each smoke		;for each SMOKE TYPE in the "container" billow
		billow\smoke_alpha = billow\smoke_alpha - billow\smoke_fade_speed	;adjust to the new alpha
		
		EntityAlpha billow\smoke_sprite, billow\smoke_alpha		;and SET the new alpha number
			
			If billow\smoke_alpha < 0				;if the alpha gets less than 0,
				FreeEntity billow\smoke_sprite		;we'll free the sprite
				Delete billow						;and delete it
				Exit								;and exit, there's no need to continue for this sprite, it doesn't exist anymore
			End If
			
			MoveEntity billow\smoke_sprite, billow\smoke_horizontal_speed, billow\smoke_vertical_speed,0	;and now update it's new location
			
	Next
End Function

			
Function hud()
	Text 0,0, "Press spacebar to create a rising smoke puff."
	Text 0,20,"Press Enter to create a stationary smoke burst, like a flak explosion."
	Text 0,40,"Import a smoke sprite to get a better idea of what this looks like."
End Function			


thanks for the help and the code example guys, it was helpful, although I guess I didn't word my question right, I just needed to know how to make a white smoke sprite black.

Hmm... I think fancier editors like Adobe Photoshop can probably do that with ease. I use MS Paint, and my only idea is the invert colors option. Unless, if the whole image is one color, you could use the fill tool.

Well, if you're using Photoshop, just press CTRL+I to invert the colors of the entire image. Black turns to white, blue turns to orange (opposite colors :-) ), etc. But I quite don't get what you're trying, since if you've got a white smoke sprite, it's just another tone of black (with 100% power). What's the problem in making it a little dark-gray?

I wanted to make missiles that you could see coming from farther away, plus, flack smoke generally is very dark