Object "flicker"when deleted

Blitz3D Forums/Blitz3D Beginners Area/Object "flicker"when deleted

Valgar(Posted 2004) [#1]
Hallo to all.
I have a piece of code that allow me to create object and move them across the screen following a path that i load from a file.
Those object fire at the player that is controlled by the mouse.
Each object (player,enemy bullet,enemy,player bullett) are a separate type.
And when an object is deleted i play a small explosion anim.
My problem is that when i shoot a enemy all is ok,but when the enemy axplode i see ALL other object of the same type flicker (like for a fraction of a second they disappear and appear)!
If explode an alien...ALL alien flicker(it seems that the flicker don't afect other types...).
I use a function to move all alien,a separate function to move enemy bulle,and so on for the other movement.
Each movement is in this manner "for a.alieno = each alieno".
The code for the collision is inside the bullet move function (if i put elsewere the collision don't work...don't know why)and works in this manner "for a.bullet = each bullet------move bullet for a.alieno = each alieno----calculate collision----if collision delete a----exit (to prevent error)----next----next".
Someone know if the flicker is caused in my method of doing collision?(in every demo that i made with collision i see this effect....sometimes smaller and somethimes [like with this demo...] very annoying).
Thanks.


Rob Farley(Posted 2004) [#2]
Are you in 2D or 3D?


Valgar(Posted 2004) [#3]
Sorry:it's a 2d demo,with 2d graphics ecc ecc. and a simple background (no scrolling).


big10p(Posted 2004) [#4]

for a.bullet = each bullet------move bullet for a.alieno = each alieno----calculate collision----if collision delete a----exit (to prevent error)----next----next".



Valgar, can you post the actual code this refers to. I have my suspicions about it. :)


Rob Farley(Posted 2004) [#5]
Sounds to me if you're using 2D that you're drawing to the wrong buffer, or flipping at the wrong time.


Valgar(Posted 2004) [#6]
Ok i post the code,just don't care of the italian comment.
Here it comes:


I think that those 2 function is what contain the "bug".


big10p(Posted 2004) [#7]
I've only had time for a quick look but I think you might be using 'Exit' incorrectly, for one thing. Anyway, I'll try and have another look tonight. Someone else will probably have sorted it for you ny then, though. :)


Valgar(Posted 2004) [#8]
Thanks,i don't know what to do for this,so i make other thing :)
Eventually i post the whole code,but i think that the other function are correct (they make simple thing after all...).


big10p(Posted 2004) [#9]
Well, I've had a go at changing things that looked problematic but it's very difficult to debug code when you don't have the whole source and it's in another language. :)
Anyway, give it a go - not sure anything I changed would solve the flickering, though.




Valgar(Posted 2004) [#10]
Well greath it works!
I have made a simple cut&paste and deleted the old function and i don't see the flicker!!!
Just some info...i use the same manner of doing things in all my code....how do you have indiduated the problem?
Last but not least.....where's the problem? O_O'


big10p(Posted 2004) [#11]
Hey, glad it works. :)

As I said before, the main cause was using Exit when you didn't need it. For example, your original muovi_proiettile() function:

Function muovi_proiettile()

	For missile.bullet=Each bullet
		missile\durata=missile\durata-1
		missile\positionx=missile\positionx
		missile\positiony=missile\positiony-missile\velocita
		counter=counter+1
		DrawImage (missile\immagine,missile\positionx,missile\positiony)
		If missile\durata=<0
			Delete missile
			Exit ;<-------- error!
		EndIf
	
		For a.alieno =Each alieno
			If ImagesCollide(bullet_image,missile\positionx,missile\positiony,0,ObjectFrames(fotogramma),a\posizionex,a\posizioney,0)
				a\vitalita=a\vitalita-missile\potenza
				Delete missile
				Exit
			EndIf
		Next
	Next

End Function


I have marked an Exit command as an error. This is wrong because it causes the 'For missile.bullet = Each bullet' loop to be exited whenever a missile's 'durata' reaches zero, meaning all the remaining bullet's that come after it in the type list don't get processed OR drawn for that frame. This constantly causes some bullets to get drawn on some frames, but not on others, hence the flickering.


Valgar(Posted 2004) [#12]
I understand now!
I have read MUCH better the online help and i have read that "exit" break a for----next loop immediately;so if i used exit even inside of a "if---endif" i exit the WHOLE "for---next" instead.
Exit must be used when i whant to exit "totally" a function,and because i use a for next at the beginning ov most of my function....this will cause the other object to not display themselves at that frame.
I think that i need much more experience :)
Many thanks


Valgar(Posted 2004) [#13]
Argh i have see another "bug" :P
With your modification now the object don't flicker but....if no enemy are on screen the jet don't shoot!but if i create an enemy immediately after i have shooted...the bullet start it's position from where it was when he isn't on screen -_-'
I must check the creation function to see the error.


Valgar(Posted 2004) [#14]
Sorry for bothering,i have individuated the error.
Usually i use function in this manner:make all calculation of position and AFTER the calculation i display the object....but in this manner if no enemy are onscreen no object is created because the display bullet function is AFTER the condition check...so if the condition is positive...no bullet displayed -_-
I have simply put the drawimage as one of the first command and voila,all go well now!