Solarus-Games English Forum

Solarus => Development => Topic started by: FacciaBianca on September 27, 2017, 01:23:24 PM

Title: Animated falling block ?
Post by: FacciaBianca 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.
Title: Re: Animated falling block ?
Post by: Christopho 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.
Title: Re: Animated falling block ?
Post by: FacciaBianca 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.
Title: Re: Animated falling block ?
Post by: Christopho 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.
Title: Re: Animated falling block ?
Post by: Diarandor on September 27, 2017, 04:04:05 PM
Do what Chris says. You only need to define the events once, for the block metatable.
Title: Re: Animated falling block ?
Post by: FacciaBianca on September 27, 2017, 04:37:02 PM
(Sorry for the late answer, I prefer trying to fix things myself before asking for help.)

Quote from: Diarandor on September 27, 2017, 04:04:05 PM
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 ?
Title: Re: Animated falling block ?
Post by: Christopho 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.
Title: Re: Animated falling block ?
Post by: FacciaBianca 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.