flashing sprites

Blitz3D Forums/Blitz3D Beginners Area/flashing sprites


I don't want to control a timer in the main code for each sprite manually. (I don't know how many sprites there will be..) I would like each sprite has an independent flashing behaviour.


Use types, then you won't need to know how many in advance and the flashing can be handled 'manually automatically', if you follow. Quick example that you can surely improve upon:

Graphics3D 800,600,0,2
cam=CreateCamera()
SetBuffer BackBuffer()


Type flashyStar
	Field sprite
	Field flashCount
	Field flashIncrement
End Type
currentFlashyStar.flashyStar=Null

flashyStarTex=CreateTexture(64,64)
Oval 4,4,60,60,True
CopyRect 0,0,64,64,0,0,BackBuffer(),TextureBuffer(flashyStarTex)


For i=0 To 99
	currentFlashyStar=New flashyStar
	currentFlashyStar\sprite=CreateSprite()
	currentFlashyStar\flashCount=Rand(0,99)
	currentFlashyStar\flashIncrement=Rand(1,5)
	EntityTexture currentFlashyStar\sprite,flashyStarTex
	PositionEntity currentFlashyStar\sprite,Rnd(-100,100),Rnd(-100,100),100
Next

While Not KeyHit(1)

updateStars()

RenderWorld
Flip
Wend

Function updateStars()
	For currentFlashyStar.flashyStar=Each flashyStar
		currentFlashyStar\flashCount=currentFlashyStar\flashCount+currentFlashyStar\flashIncrement
		If currentFlashyStar\flashCount>99 Then currentFlashyStar\flashCount=currentFlashyStar\flashCount-100
		If currentFlashyStar\flashCount>49
			HideEntity	currentFlashyStar\sprite
		Else
			ShowEntity currentFlashyStar\sprite
		EndIf
	Next	
End Function