Author Topic: Animated falling block ?  (Read 139 times)

FacciaBianca

  • Newbie
  • *
  • Posts: 5
  • *speaks Shakespeare's and Molière's language*
    • View Profile
Animated falling block ?
« on: September 27, 2017, 01:23:24 pm »
Hello everyone~

I've been making a "push-block-to-switch" puzzle in Solarus, along with a script which creates another block after you've pushed it in a hole, then re-entered the room.

However, it appears that when I push said block in a hole, it immediatly disappears halfway between the ground and the ravine.

So, I've been wondering if I needed to create the rest of the block's moving and falling animation, or if I did something wrong. Of course, I can provide the script if required !

In advance, thank you very much and have a nice day.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1041
    • View Profile
Re: Animated falling block ?
« Reply #1 on: September 27, 2017, 01:38:35 pm »
A solution can be to create an animation using a new entity, right after the block disappears. It can be a custom entity with the sprite animation you need.

FacciaBianca

  • Newbie
  • *
  • Posts: 5
  • *speaks Shakespeare's and Molière's language*
    • View Profile
Re: Animated falling block ?
« Reply #2 on: September 27, 2017, 02:17:53 pm »
Thanks a lot for answering Christopho, I'll do that, however I'm trying to figure out which method/event would allow me to get the position of the hole in which the block falls/disappears, so that it would create the animation wherever it should be happening. (I'm a newbie in lua, so I'm quite toying with anything that could work according to my own "logic" ^^)

Edit : or maybe that could be done with sensors ? Nevermind, I think that only works with the hero.
« Last Edit: September 27, 2017, 02:31:41 pm by FacciaBianca »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1041
    • View Profile
Re: Animated falling block ?
« Reply #3 on: September 27, 2017, 02:53:25 pm »
You can use the event block:on_moving() or block:on_moved() and detect the ground below the block to know if it is a hole.

Diarandor

  • Hero Member
  • *****
  • Posts: 758
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Animated falling block ?
« Reply #4 on: September 27, 2017, 04:04:05 pm »
Do what Chris says. You only need to define the events once, for the block metatable.

FacciaBianca

  • Newbie
  • *
  • Posts: 5
  • *speaks Shakespeare's and Molière's language*
    • View Profile
Re: Animated falling block ?
« Reply #5 on: September 27, 2017, 04:37:02 pm »
(Sorry for the late answer, I prefer trying to fix things myself before asking for help.)

Do what Chris says. You only need to define the events once, for the block metatable.
Alright I'll do this. Though am I brainstorming too much, or does it actually work with local variables ?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1041
    • View Profile
Re: Animated falling block ?
« Reply #6 on: September 27, 2017, 04:40:32 pm »
To keep things simple, I'd start by making it local to the one block you want to make fall.
And only later do some refactoring with metatables to make the code reusable.

FacciaBianca

  • Newbie
  • *
  • Posts: 5
  • *speaks Shakespeare's and Molière's language*
    • View Profile
Re: Animated falling block ?
« Reply #7 on: September 27, 2017, 06:43:10 pm »
Thank you both for helping out. Now that I think about it, I should have named this thread "Animated falling vase/item/enemy", since this kind of block I'm using normally can't be pushed into holes unlike blocks created by the Cane of Somaria.