Author Topic: Question on using self.game.animations....  (Read 1081 times)

uncivil engineer

  • Wizard
  • *****
  • Posts: 118
  • Alan
    • View Profile
Question on using self.game.animations....
« on: June 20, 2015, 08:12:03 PM »
Michael,
I know in normal pyprocgames, the sub-class AnimatedLayer has a property called 'hold'.  This allows you to display the last frame on an animation indefinably after the animation plays.  I was wondering if there is a way to do this with your PyProcgameHD self.game.animations? 

Thanks,
Alan

MOcean

  • Moderator
  • ****
  • Posts: 822
  • Michael Ocean
    • View Profile
Re: Question on using self.game.animations....
« Reply #1 on: June 21, 2015, 07:35:54 AM »
Two ways to do this.

In your code, change the attribute of the appropriate asset, since the animations dictionary contains animated layers, and each  has all the normal attributes and methods of an animated layer.  like so:

Code: [Select]
self.game.animations["extra_ball"].hold = True

But the easier way is in the asset_list.yaml

The following excerpt from the asset manager Python shows what attributes it can read from the yaml per entry and what the defaults are, if not present: https://github.com/mjocean/PyProcGameHD-SkeletonGame/blob/master/procgame/assetmanager.py#L239

So if you add an attribute in the asset_list for this entry called holdLastFrame: True, it will do so.

Enjoy!
- Michael



uncivil engineer

  • Wizard
  • *****
  • Posts: 118
  • Alan
    • View Profile
Re: Question on using self.game.animations....
« Reply #2 on: June 21, 2015, 11:33:14 PM »
Michael,
What I have found is that using it like this:
self.layer = self.game.animations['skillOpening'].hold = True
Does not currently work.  When I try it, I get the attached error.

However, I was able to get it to work using by placing holdLastFrame property in my asset list file.  I also tried holdLastFrame at the end of my command above, but got the same error.


MOcean

  • Moderator
  • ****
  • Posts: 822
  • Michael Ocean
    • View Profile
Re: Question on using self.game.animations....
« Reply #3 on: June 22, 2015, 07:07:17 AM »
The reason this line:

Code: [Select]
self.layer = self.game.animations['skillOpening'].hold = True

Doesnt work is because it's not really what you mean to do. If you read it from right to left (which isn't exactly what's done, but close enough) it says, assign true to the hold attribute of a layer in the animations dictionary. It's the result of that assignment that's then stored in your self.layer, not the layer from the animations dictionary.

You'd do this in two lines, as such:

Code: [Select]
self.game.animations['skillOpening'].hold = True # 1. Change the hold attribute of the animation layer stored at skillOpening
self.layer = self.game.animations['skillOpening'] # 2. set this mode's layer to the animation layer stored at skillOpening

That said, if you always want that animation to hold the last frame, then just adding holdLastFrame to the asset_manager.yaml is cleaner and easier.

- Michael