Author Topic: [Solved]How to add an "opening" animation for chests?  (Read 783 times)

Diarandor

  • Hero Member
  • *****
  • Posts: 758
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: How to add an "opening" animation for chests?
« Reply #15 on: May 11, 2017, 10:19:14 am »
You will need to do something similar for NPCs, and many other types of interactions with other entities (switches, carried entities, etc). That is a lot of work.

Zefk

  • Sr. Member
  • ****
  • Posts: 492
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Re: How to add an "opening" animation for chests?
« Reply #16 on: May 11, 2017, 05:52:14 pm »
The switch I have already basically done, but only for stepping on. I do not plan to make all the entities except for when it is simple or when I need it for animation purposes. I probably will not have a second player feature because it is not something I want with my games, but in some cases simple second player features can be useful.  For example, when you want an entity to step on a switch or to move a block that can only be pushed from their side.

froggy77

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: How to add an "opening" animation for chests?
« Reply #17 on: May 12, 2017, 11:30:56 am »
Thanks for the time spent. I just needed advice, not a brainstorming.  ;)
I would like to use the editor to create the chest normally; maybe it could be disabled and replaced by an entity during the opening and at the end enabled to appear when completely opened. I will try to write a script even I lost my poor level in lua.

MetalZelda

  • Hero Member
  • *****
  • Posts: 504
    • View Profile
Re: How to add an "opening" animation for chests?
« Reply #18 on: May 12, 2017, 05:48:03 pm »
I did posted the solution on page 1, it does replace the default chest by a custom entity, you might do some tweaks to make it properly work to your needs though

froggy77

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: How to add an "opening" animation for chests?
« Reply #19 on: June 18, 2017, 01:10:07 pm »
Thank you MetalZelda, I did not understand where to put those scripts and I did not realize that there was no need to create an entity from the editor.
Even if I managed to make it work, I found some problems.

  • If there is no treasure_savegame_variable, then there are these error messages:
Error: In on_created: [string "entities/chest/chest.lua"]:23: bad argument #1 to is_open (string expected, got nil))
Error: In on_interaction: [string "entities/chest/chest.lua"]:44: bad argument #1 to is_open (string expected, got nil))

  • If there is a treasure_savegame_variable but no treasure, then there is the following error message
Error: In sprite callback: [string "entities/chest/chest.lua"]:52: bad argument #1 to start_treasure (string expected, got nil))
This one is not a problem.

  • If there is no delay for "opening" animation in "delay between frames", then nothing happens: no error message, no treasure, "hero:unfreeze()" does not start.
In order to correct this, I added a value for "delay between frames", for example: 200 ms.

  • hero:freeze() and hero:unfreeze() seem not to be necessary.
« Last Edit: June 20, 2017, 12:26:15 am by froggy77 »

MetalZelda

  • Hero Member
  • *****
  • Posts: 504
    • View Profile
Re: How to add an "opening" animation for chests?
« Reply #20 on: June 18, 2017, 03:31:18 pm »
To make this work you need to create a chest entity, not a custom entity, the script do the rest (delete the chest and create the custom entity).

You need to define the sprite, treasure and savegame variable from there, like this



But, it is very basic atm, the entity name could be used to store frame delays or other stuffs