hell yeah, thank you, this is working!
my problem now:
sometimes the bar is at the wrong position and moves to the place where it should be for either the movetime or just for a frame
here is my code:
Code:
/*>> self == trigger * * */
monitorPlayer( player )
{
self endon( "death" );
size = 60; /* * * size of the bar * * */
border = 3; /* * * surrounding box is abit larger thn the bar * * */
xOffset = -100; /* * * xPos * * */
yOffset = 0; /* * * yPos * * */
/* * * cleanup * * */
if( isDefined( player.hud_box ) )
player.hud_box destroy();
if( isDefined( player.hud_bar ) )
player.hud_bar destroy();
for( ; ; )
{
if( !isDefined( player ) )
break;
else if( player.sessionstate != "playing" )
break;
else if( !player isTouching( self ) )
break;
if( !isDefined( player.hud_box ) ) /* * * draw the surrounding box (static frame) * * */
{
player.hud_box = newClientHudElem( player );
player.hud_box.x = xOffset - border;
player.hud_box.y = yOffset - border;
player.hud_box.horzAlign = "right";
player.hud_box.vertAlign = "middle";
player.hud_box setShader( "serthy_box" , size + ( 2 * border ) , size + ( 2 * border ) );
}
if( !isDefined( player.hud_bar ) )
{
player.hud_bar = newClientHudElem( player );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset + ( size * ( 1 - self.ratio ) );
player.hud_bar.horzAlign = "right";
player.hud_bar.vertAlign = "middle";
player.hud_bar.rate = 100;
}
/* * * if the rate of the bar changes... * * */
if( player.hud_bar.rate != self.rate )
{
player.hud_bar.rate = self.rate; /* * * assign the new change-rate (speed of the bar) * * */
player.hud_bar setShader( "white" , size , max( 1 , int( ( size * self.ratio ) + 0.5 ) ) ); /* * * set the shader (range: 1-size) * * */
/* * * self.ratio = current bar fraction * * */
if( self.rate > 0 && self.ratio < 1 ) /* * * bar should scale from the bottom to the top * * */
{
/* * * time is calculating correct * * */
time = ( 1 - self.ratio ) / ( 20 / self.captureTime * self.rate );
player.hud_bar scaleOverTime( time , size , size );
player.hud_bar moveOverTime( time );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset; /* * * bar is at the top * * */
}
else if( self.rate < 0 && self.ratio > 0 ) /* * * bar should scale from the top to the bottom * * */
{
/* * * time is calculating correct * * */
time = self.ratio / ( -1 * ( 20 / self.captureTime * self.rate ) );
player.hud_bar scaleOverTime( time , size , 1 );
player.hud_bar moveOverTime( time );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset + size; /* * * bar is at the bottom * * */
}
}
wait( 0.05 );
}
/* * * cleanup * * */
if( isDefined( player ) )
{
if( isDefined( player.hud_box ) )
player.hud_box destroy();
if( isDefined( player.hud_bar ) )
player.hud_bar destroy();
}
}
hopefully its not an engine bug ~.~
edited on Oct. 20, 2012 05:59 am by serthy
this is freaking me out... i never have used a moveOverTime on the hud_box element, but sometimes its moving! lol i guess i have to optimize my code -.-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EDIT: i located it, but it seems there will be no solution..
code:
Code:
monitorPlayer( player )
{
self endon( "death" );
size = 60;
border = 3;
xOffset = -100;
yOffset = 0;
if( isDefined( player.hud_basezonebar_bar ) )
player.hud_bar destroy();
if( isDefined( player.hud_box ) )
player.hud_box destroy();
player.hud_box = newClientHudElem( player );
player.hud_box.x = xOffset - border;
player.hud_box.y = yOffset - border;
player.hud_box.horzAlign = "right";
player.hud_box.vertAlign = "middle";
player.hud_box.color = ( 1 , 1 , 1 );
player.hud_box.foreground = true;
player.hud_box.sort = -1;
player.hud_box.archived = true;
player.hud_box setShader( "serthy_basezone_box" , size + ( 2 * border ) , size + ( 2 * border ) );
player.hud_box.alpha = 1;
player.hud_bar = newClientHudElem( player );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset + ( size * ( 1 - self.ratio ) );
player.hud_bar.horzAlign = "right";
player.hud_bar.vertAlign = "middle";
player.hud_bar.alpha = 1.0;
player.hud_bar.foreground = true;
player.hud_bar.sort = -2;
player.hud_bar.rate = 100;
player.hud_bar.archived = true;
player.hud_bar setShader( "white" , size , max( 1 , int( ( size * self.ratio ) + 0.5 ) ) );
for( ; ; )
{
wait( 0.05 );
if( !isDefined( player ) )
break;
else if( player.sessionstate != "playing" )
break;
else if( !player isTouching( trigger ) )
break;
if( player.hud_bar.rate != self.rate )
{
player.hud_bar.rate = self.rate;
player.hud_bar setShader( "white" , size , max( 1 , int( ( size * self.ratio ) + 0.5 ) ) );
if( self.rate > 0 && self.ratio < 1 )
{
time = ( 1 - self.ratio ) / ( 20 / self.captureTime * self.rate );
player.hud_bar scaleOverTime( time , size , size );
player.hud_bar moveOverTime( time );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset;
}
else if( self.rate < 0 && self.ratio > 0 )
{
time = self.ratio / ( -1 * ( 20 / self.captureTime * self.rate ) );
player.hud_bar scaleOverTime( time , size , 1 );
player.hud_bar moveOverTime( time );
player.hud_bar.x = xOffset;
player.hud_bar.y = yOffset + size - 1;
}
else
{
player iprintlnbold( "^1STOP FRIGGIN MOVEOVERTIME" );
}
}
}
if( isDefined( player ) )
{
if( isDefined( player.hud_box ) )
player.hud_box destroy();
if( isDefined( player.hud_bar ) )
player.hud_bar destroy();
}
}
guess what happens... yeah you are right, the HUD's move while it prints me the message >.<
so how to stop this moveovertime()?
i tried without success:
> setshader()
> setshader() + setting the x and y coords
> destroy the hud and recreate it without moveovertime() + right coords
> destroy the hud + wait a frame + recreate it without moveovertime() + right coords
the result remains the same: the bar is moving from the topleft to its position