Announcement

Collapse
No announcement yet.

Problem of Scaleform HUD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem of Scaleform HUD

    Hello everyone, thanks for reading this post.

    I got a problem when I'm trying to make an animation for my HUD using Flash through Scaleform GFx, here's the code:
    Code:
    class GFxHUD extends GFxMoviePlayer;
    	
    var GFxObject HealthBar, EnegryBar;
    
    var GFxObject displayer;
    
    var int Health, Enegry;
    
    function Init(optional LocalPlayer LocPlay)
    {
            super.Init(LocPlay);
    
    	Start();
    	Advance(0);
    
    	HealthBar = GetVariableObject("_root.healthbar");
    	EnegryBar = GetVariableObject("_root.enegrybar");
    
    	displayer = GetVariableObject("_root.box");
    
    	Initialization();
    }
    
    function Initialization()
    {
    	if(Health != -5)
    	{
    		HealthBar.SetVisible(true);
    		HealthBar.GotoAndStopI(36);
    		Health = -5;
    	}
    
    	if(Enegry != -10)
    	{
    		EnegryBar.SetVisible(true);
    		EnegryBar.GotoAndStopI(41);
    		Enegry = -10;
    	}
    }
    
    function TickHud()
    {
            local CyrilPawn CP;
            local int i1, i2;
       
    	CP = CP.Spawn(class'CyrilGame.CyrilPawn');
            i1 = CP.GetHealth();
    	i2 = CP.GetEnegry();
    
    	if(Health != CP.GetHealth())
    	{
                    Health = CP.GetHealth();
    		HealthBar.GotoAndStopI(31 - i1);
    	}
    
    	if(Enegry != CP.GetEnegry())
    	{
    		Enegry = CP.GetEnegry();
                    EnegryBar.GotoAndStopI(31 - i2);
    	}
    }
    
    DefaultProperties
    {
    	MovieInfo=SwfMovie'CyrilGUI.HUD'
    }
    And the HUD class:

    Code:
    class CHUD extends HUD;
    
    var GFxHUD gfx;
    var class<GFxHUD> gfxClass;
    
    simulated function PostBeginPlay()
    {
    	super.PostBeginPlay();
    
            Play();
    }
    
    function Play()
    {
    	gfx = new gfxClass;
    	gfx.SetTimingMode(TM_Real);
    	gfx.Init(class'Engine'.static.GetEngine().GamePlayers[gfx.LocalPlayerOwnerIndex]);
    }
    
    function RemoveMovie()
    {
    	if(gfx != None)
    	{
    		gfx.Close(True);
    		gfx = None;
    	}
    }
    
    function int LocalPlayerOwnerIndex()
    {
    	return gfx.LocalPlayerOwnerIndex;
    }
    
    event PostRender()
    {
    	super.PostRender();
    
    	gfx.TickHud();
    }
    
    DefaultProperties
    {
    	gfxClass=class'CyrilGame.GFxHUD'
    }
    Finally, the pawn class:

    Code:
    class CyrilPawn extends GamePawn
    	config(Game);
    
    var int CHealth;
    var int Enegry;
    
    var bool bRunning;
    var bool bSneak;
    
    var int AmmoCount1, AmmoCount2;
    
    function Init()
    {
            if(Health > 30)
    	{
    		Health = 30;
    	}
    	else
    	{
    		if(Health < 0)
    		{
    			Health = 0;
    		}
    	}
    
    	if(Enegry > 30)
    	{
    		Enegry = 30;
    	}
    	else
    	{
    		if(Enegry < 0)
    		{
    			Enegry = 0;
    		}
    	}
    }
    
    function int GetHealth()
    {
    	return self.CHealth;
    }
    
    function int GetEnegry()
    {
    	return self.Enegry;
    }
    
    defaultproperties
    {
    	CHealth=30
            Enegry=30
    }
    (The other classes is not important)
    My problem is: Although I have described that the HealthBar and the EnegryBar should jump to a specified frame using 'GotoAndStopI', The Game skips them to the last one!!!
    Please Help!!!! This is really important for me!!!!!

    #2
    How can we solve the problem when you haven't pinpointed out what it is? Saying "I have a problem with my Hud!" doesn't communicate much. What is the exact problem you are having? Describe it in detail. Then describe what it is you wish to end product to be, so we know what direction to head in when solving the problem.

    Posting a picture also helps

    Comment


      #3
      I have edited my post, juanitudev1 pls help me!!!

      Comment


        #4
        So you want to make your Health and Energy Bar jump to a corresponding frame depending on the Pawns variables, correct? Your implementation is a bit confusing, so I'm just going to post how I handled this in my game:

        Code:
        // Frame at which health is considered to be 100%, relative to Flash's timeline. 
        var const           protected int                MaxHealthTimeLineFrame;
        var       transient protected int                LastHealth;
        
        function TickHud( float DeltaTime )
        {
        	local int                            Health, 
        
        	if ( Pawn != None ) {
        	        Health                       = Clamp( Pawn.Health, 0, Pawn.MaxHealth ); // Set the min and the max to your Pawns min and max allowed health. Same for energy!
                                                                                                                        // Change the 'MaxHealth' variable to whatever your Pawns maximum health is. Do the same below.
        	} 
        	if ( LastHealth != Health ) {
        		LastHealth                   = Health;
        		LastHealthPos                = int( GetMappedRangeValue( vect2d(0,Pawn.MaxHealth), vect2d(1,MaxHealthTimeLineFrame), LastHealth ) );
        	        HealthBarMC.GoToAndStopI( LastHealthPos );
        	}
        }
        
        defaultproperties
        {	
        	MaxHealthTimeLineFrame         = 100 // Set this to be the frame in your Flash timeline that is equal to 100% health. Mine's is 100 ( makes sense ).
        }
        ^^You can then do the same for the Energy bar. Remember to change the two instances of 'Pawn.MaxHealth' in my code to your Pawns max values.
        • In your healthbar movieclip, make sure frame 1 is zero health, and your max frame is full health. Use the MaxHealthTimeLineFrame variable to record what you set the max frame to be.
        • Look up the function GetMappedRangeValue() in the Object.uc class so that you understand what it does. It has the explanation in the class.

        Comment


          #5
          Thank you!!! I solved the problem finally!!! Thank you so much!!!

          Comment

          Working...
          X