PositionEntity after HideEntity causing flickering?

Blitz3D Forums/Blitz3D Programming/PositionEntity after HideEntity causing flickering?

rhuk(Posted 2003) [#1]
I'm having a weird problem that just makes no sense to me. Picture this, I have a mothership entity moving across the screen. When it gets hit by a bullet, i HideEntity(mothership), then user PositionEntity to move it off the side of the screen for the next time it does its pass. Problem is that the next time my little rand timer goes off and I unhide the mothership, and start it moving again, there is this flicker of an image as the mothership 'jumps' to that off screen position then starts moving. Even though in the code, the mothership was positioned off screen many frames ago.
I have this same effect with my figher/player entity, when it gets hit, i hide it, and move it back to center to start again with the next life, and this jumping effect happens there too.

The only way I have gotten around it, is to create a new entity every time and use CopyEntity() to copy the template entity into it. Then when the entity is killed, i do a FreeEntity(). This does not seem optimal to me, and somewhat wasteful.

Any ideas?

Cheers,

rhuk


semar(Posted 2003) [#2]
So, you have a mothership on the screen. When it is hit, should disappear and go out of the screen ? And what should do then ? Re-enter in the screen from one of the border ?

I don't get it, sorry.

Could you explain better what you want to achieve ?

I think you don't need to hide the entity to move it on the center of the screen.

If you want to avoid collision, you can reset its collision settings with
Entitytype entity,0
before to move it on the center of the screen, and then again, once moved (using the next updateworld), you can set its collision again using the same command.

Otherwise, I don't see where is the problem here.

Sergio.


Michael Reitzenstein(Posted 2003) [#3]
Use EntityAlpha. This is the fault of Blitz's tweening.


rhuk(Posted 2003) [#4]
Ok, as i'm brand-spanking-new to b3d, i thought i'de start of recreating space invaders. So picture your player at the bottom of the screen with a b3d model of a mother ship, rotating and moving across the screen. When you shoot it they will be an explosion (to be done), and then the mothership should vanish, only to reappear a short while later to repeat its path across the top of the screen.

Michael, I've actually played with this for a while, I've tried every combination of HideEntity, EntityAlpha, PositionEntity I can think of, but every time I get the same problem every time.

I think your right about the tweening, its as if, the entity image is getting tweened between the time it gets hit, and the time it moves of the screen.


WolRon(Posted 2003) [#5]
Why hide it at all? Just move it offscreen immediately.


Pete Rigz(Posted 2003) [#6]
Michael is right, using entity alpha should work because updateworld and captureworld will still calculate entities with alpha set to 0. Hidden entities however are ignored so even though you move them into a new position and unhide them, as far as blitz is concerned its last known captured postion was on screen therefore giving you undesired tweening. this code higlights the problem.

Graphics3D 800,600,0,2

Const FPS=30

period=1000/FPS
time=MilliSecs()-period

cube=CreateCube()
cam=CreateCamera()
PositionEntity cam,0,0,-50

While Not KeyHit(1)

	Repeat
		elapsed=MilliSecs()-time
	Until elapsed

	;how many 'frames' have elapsed	
	ticks=elapsed/period
	
	;fractional remainder
	tween#=Float(elapsed Mod period)/Float(period)
	
	For k=1 To ticks
		time=time+period
		If k=ticks Then CaptureWorld

		MoveEntity cube,KeyDown(205)-KeyDown(203),KeyDown(200)-KeyDown(208),0
		;If KeyDown(57) Then EntityAlpha cube,0 Else EntityAlpha cube,1
		If KeyDown(57) Then HideEntity cube Else ShowEntity cube
		
		UpdateWorld

	Next
	
	RenderWorld tween
	Flip
	
Wend


There are 2 lines in the code, one that hides the cube when space bar is held down, and one that uses entityalpha. Run the code using the hideentity line first, and move the cube to a new position with space bar held, and let go to see it tween across the screen. Then try it with the alpha line instead - no more flicker.

Obviously the optimal solution is to use both hide entity and alpha because theres a good reason we dont wont blitz to calculate hidden stuff, but as long as u give your code a chance to update and capture for both positions of the entity whilst its alpha'd out then it should be ok.


rhuk(Posted 2003) [#7]
Roger pointed me towards the solution. Turns out this is a bug of some kiind in blitz' tweening. He pointed me towards this article:

http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gamemorduun03212002.html

As an alternative way to handle FPS limiting. It works like a charm, more efficient, plus fixes all these 'ghosting' type problems with hidden entities.