Molecule icon indicating copy to clipboard operation
Molecule copied to clipboard

How can I get a hit event

Open avil13 opened this issue 10 years ago • 6 comments

Hello. Thanks for this great library. I have some questions. How can I get a hit event?

avil13 avatar Apr 10 '14 21:04 avil13

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

fjsantosb avatar Apr 12 '14 19:04 fjsantosb

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

avil13 avatar Apr 12 '14 19:04 avil13

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

fjsantosb avatar Apr 12 '14 20:04 fjsantosb

Thanks

avil13 avatar Apr 12 '14 20:04 avil13

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.

avil13 avatar Dec 03 '14 13:12 avil13

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.

avil13 avatar Dec 05 '14 08:12 avil13