Hide/Show and Position Problem
Blitz3D Forums/Blitz3D Programming/Hide/Show and Position Problem
So I'm working an a turn-based little demo game as a learning project, and I have an entity that is shown around the player whose turn it is when that player's making his/her decision, but is hidden when the turn is "playing itself out," if you understand what I'm saying.
In an if statement that determines when the turn is done playing itself out and it's the next player's turn, this entity is both shown with ShowEntity and positioned to the next player's position with PositionEntity in two consecutive lines of code. But for some reason, in one game loop, the entity is un-hidden, and in the next it's re-positioned, and I can't for the life of me figure out why.
I use render-tweening, and was wondering if this could create this problem. Any ideas?
could you post code? it would really help
Sounds like your program flow is
UpdateWorld
ShowEntity
PositionEntity
Renderworld
and should be
ShowEntity
PositionEntity
Updateworld
Renderworld
i.e. your rendering of entities is getting updated before you have updated their positions.
With render-tweening, try doing any abrupt changes in position immediately before the CaptureWorld command, if possible.
If collisions are involved, try doing a ResetEntity on the moved entity, immediately after you re-position it.
No collisions are involved, Bill, but I think all of my code is done after the CaptureWorld command. Is that not right? I was under the impression that - to use Mark's sample code - it was done like so:
While Not KeyDown(1)
Repeat
elapsed = MilliSecs() - time
Until elapsed
ticks = elapsed / period
tween# = Float#(elapsed Mod period) / period
For k = 1 To ticks
time = time + period
If k = ticks
CaptureWorld
EndIf
UpdateGame()
UpdateWorld()
Next
RenderWorld(tween#)
Flip
Wend
...with all of my game mechanics done within the UpdateGame() parent function.
Buggy, the way you're doing it seems to be the correct way for the most part. Trying to do it differently causes a lot of jittery effects.
If you're moving something over a large distance (teleporting, etc), though; jitteriness is less of an issue, and interpolation will cause the object being moved to be rendered at various points along the line it is being moved along; which may be undesirable. Doing the positioning immediately before CaptureWorld eliminates this, as the new position of the object is captured and interpolation begins at the captured position, rather than the original one.
Whether any of this relates to your problem is a whole other question, though.
So if I want to have all of my game code within the UpdateGame() function, then there's no easy alternative? I think I could come up with a workaround, but it certainly wouldn't be easy or pretty.
Try:
HideEntity
MoveEntity
ShowEntity
Or rather than using HideEntity, use EntityAlpha with a value of 0 when hidden and 1 when active.
6, that will still cause a 'jittery' transition.
The entity needs to be hidden to exclude it from calculations, until it's time to show it again.