Molecule
Molecule copied to clipboard
How can I get a hit event
Hello. Thanks for this great library. I have some questions. How can I get a hit event?
Dear avil13,
We are glad that you like Molecule as Framework to create awesome games!
Regarding your question, are you talking about collision between sprites or touch / click events?
Regards, Francisco Santos Belmonte
I'm talking about the moment when the sprite hit another character. How can I get an event when the hero was able to hit the character? I want to start at this point the enemy death animation.
Sorry for my English
Dear avil13,
You can check if a sprite has collided with another sprite using his property yourSprite.collision.sprite.id; it will give you the id of the sprite which has collides or null (if no collision).
Checking that id on update method, you can start the death enemy animation like: if(yourSprite.collision.sprite.id !== null) { yourSprite.animation.run('death'); }
Regards, Francisco Santos Belmonte
Thanks
I'm sorry that I ask again. But I did not get to catch the event of collision.
https://github.com/avil13/Molecule_Game/blob/master/js/env.js#L33
What am I doing wrong? Thanks.
Event work just if I add this line in coffee https://github.com/avil13/Molecule_Game/blob/master/coffee/env.coffee#L20 or in js https://github.com/avil13/Molecule_Game/blob/master/js/env.js#L24
But if object does not move, I can't get event.