Animation to graphic

edited January 2011 in Help request
Hi!

This is my first post here,

I was thinking about doing a animation to a object/graphic that has been scaled down just like in Mushroom Stew s Enemies in the right upper corner.
 orxOBJECT *pstIcon;

  // Gets its icon
  pstIcon = orxOBJECT(orxHashTable_Get(mpstEnemyTable, orxString_ToCRC(_roEnemy.GetName())));

  // Valid?
  if(pstIcon)
  {
    orxGRAPHIC *pstGraphic;

    // Gets its graphic object
    pstGraphic = orxOBJECT_GET_STRUCTURE(pstIcon, GRAPHIC);

    // Valid?
    if(pstGraphic)
    {
      orxFLOAT  fHealthRatio, fShift;
      orxVECTOR vPivot, vSize, vOrigin;

      // Gets enemy's health ratio
      fHealthRatio = _roEnemy.GetHealth() / _roEnemy.GetMaxHealth();

      // Pushes its section
      orxConfig_PushSection(orxObject_GetName(pstIcon));

      // Gets its original pivot, origin & size
      orxConfig_GetVector(szConfigIconPivot, &vPivot);
      orxConfig_GetVector(szConfigIconOrigin, &vOrigin);
      orxConfig_GetVector(szConfigIconSize, &vSize);

      // Pops config section
      orxConfig_PopSection();

      // Gets shift value
      fShift = orxMath_Ceil(vSize.fY * (orxFLOAT_1 - fHealthRatio));

      // Updates pivot, origin & size according to health
      vPivot.fY  -= fShift;
      vOrigin.fY += fShift;
      vSize.fY   -= fShift;

      // Applies them
      orxGraphic_SetPivot(pstGraphic, &vPivot);
      orxGraphic_SetOrigin(pstGraphic, &vOrigin);
      orxGraphic_SetSize(pstGraphic, &vSize);

I can't come up with way to do it. I thought that I'd have to do this for every frame of animation but did not get it to work. Can someone help me?


Thanks

-lasmus

Comments

  • edited January 2011
    lasmus wrote:
    Hi!

    This is my first post here,

    Hi lasmus, and welcome here! :)

    As for your problem, you need to get the current animation frame's graphic, not the base one. So instead of:
    orxGRAPHIC *pstGraphic;
    
    // Gets its graphic object
    pstGraphic = orxOBJECT_GET_STRUCTURE(pstIcon, GRAPHIC);
    

    Try something like:
    orxGRAPHIC     *pstGraphic;
    orxANIMPOINTER *pstAnimPointer;
    
    // Gets animation pointer
    pstAnimPointer = orxOBJECT_GET_STRUCTURE(pstIcon, ANIMPOINTER);
    
    // Valid?
    if(pstAnimPointer)
    {
      // Gets current anim data
      pstGraphic = orxGRAPHIC(orxAnimPointer_GetCurrentAnimData(pstAnimPointer));
    }
    else
    {
      // Gets base graphic
      pstGraphic = orxOBJECT_GET_STRUCTURE(pstIcon, GRAPHIC);
    }
    

    Let me know if it works! :)
  • edited January 2011
    Thanks for the help! :)

    Did not get it to work properly yet.

    If I understand correctly I should do this for every frame of the animation? Maybe im still missing something :(

    lasmus
  • edited January 2011
    Yes, you need to call that every frame, in an Update function, for example.

    Can you give me more details about what didn't work? :)
  • edited February 2011
    Hi!

    Now I'm calling the scaling function from update function and at first animation is flickering (its like showing up in two different positions at the same time. ) and after about one cycle of animation it shows correctly? I dont know is that explained correctly. Maybe its just something that I dont understand. Can you help :D

    Regards,
    Lassi
  • edited February 2011
    Interesting! ^^

    Would you mind posting your code/config here or send me all your files by email (my address is in the README file)?

    I'm pretty sure it'll be very fast to fix but it's hard to say what it is without access to your code/config. =)
  • edited February 2011
    Ok heres something
    INI-file:
    [Object]
    Graphic = ObjectGraphic
    TextureSize = (295, 246, 0)
    Position = (-0.375, 0.15, 0.0001)
    ParentCamera = Camera
    UseParentSpace = true
    Pivot = (147.5, 246, 0) ; bottom center
    Scale (0.00078125, 0.0010416666667)
    AnimationSet = ObjectAnimationSet
    

    Creating object and setting animation:
    void Analysis::Init()
    {
      object_ = orxObject_CreateFromConfig("Object"); 
      orxObject_SetCurrentAnim(object_, ObjectIdleAnimation);
    }
    

    Generating objects according to percentage:
    void Analysis::GenerateObject(const orxCHAR* chord, orxOBJECT* object)
    {
      //Make animal graphics to analysis view
      animPointer = orxOBJECT_GET_STRUCTURE(object, ANIMPOINTER);
      
      if(animPointer)
      {
          object_graphic_ = orxGRAPHIC(orxAnimPointer_GetCurrentAnimData(animPointer));
      }
      else
      {
        object_graphic_ = orxOBJECT_GET_STRUCTURE(object, GRAPHIC);  
      }
      
      if(object_graphic_)
      {
        
        orxFLOAT  percentage, fShift;
        orxVECTOR vPivot, vSize, vOrigin;
        
        //Get chord percentage achieved  
        percentage = chord_percent_achieved[chord]; //gets value for example 0.25f
        
        // Pushes its section
        orxConfig_PushSection(orxObject_GetName(object));
        
        orxConfig_GetVector(texturesize, &vSize);// texturesize = "TextureSize"
        orxConfig_GetVector(origin, &vOrigin);//origin = "Position"
        orxConfig_GetVector(pivot, &vPivot);//pivot = "Pivot"
    
        // Pops config section
        orxConfig_PopSection();
         
        fShift = vSize.fY * (orxFLOAT_1 - percentage);
           
        vOrigin.fY += fShift;
        vSize.fY -= fShift;
        vPivot.fY -= fShift;
        		
        orxGraphic_SetPivot(object_graphic_, &vPivot);
        orxGraphic_SetOrigin(object_graphic_, &vOrigin);
        orxGraphic_SetSize(object_graphic_, &vSize);
      } 
    }
    

    Then calling that in update function constantly
    void Analysis::Update(const orxCLOCK_INFO *clock_info)
    {
      GenerateObject("Chord", object_);
    }
    

    Hope that has some use :) if I dont call the GenerateObject function animation works like its supposed to with full image.

    regards,
    Lassi
  • edited February 2011
    Mmh, beside what are probably typos in the config section (only 2 values for Scale and no = sign) the code looks good.

    Would you mind sending me somewhere a working example of the issue so that I can trace and see what's going on? I won't publish your code, of course, but if you'd rather not send it, maybe a minimal working set showing the issue then?

    Thanks in advance! :)
  • edited February 2011
    MMh, just in case, all your graphics have the same size/coordinates? Also, how often is your Update() method called? Every frame?
  • edited February 2011
    Hi, Haven't yet sent you anything try to get you somekind of version thats doing that thing.

    Answers to those questions: All the frames are same sized and update() is called more then once for every frame.

    Lassi
  • edited February 2011
    No worries! Thanks for the details but I'm afraid I'll still need to trace the code to give you a reason of why it's not working. :)
Sign In or Register to comment.