0
\$\begingroup\$

As the topic says, I want to know how to get the ID of an active colliding entity.

My Player Entity is called with

Crafty.e("Player") 

Please notice, that I do not want the ID of my Player Entity. I want the ID of the Collision element

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Do you want the id of the entity your player collided with?

var mobs = this.hit('Mob'); if (mobs) { // mobs is an array, could be more than one var collidingMob = mobs[0].obj; // if you still want the crafty id of this entity var mobId = collidingMob[0]; } 
\$\endgroup\$
5
  • \$\begingroup\$ Hm, if i call the "mobId" per alert, nothing useful is returned.. Its just [object Object] \$\endgroup\$ Commented Sep 10, 2014 at 21:25
  • \$\begingroup\$ So, if i use this method on "this" it's working: alert(this.getid()) \$\endgroup\$ Commented Sep 11, 2014 at 5:48
  • \$\begingroup\$ Firstly, don't use alert, use console.log(). Then you can see the object itself in your console. Second, "this" in this context is your player, or the entity you are using to test collision. Not the entity you collided with. Third, using your method you would want collidingMob.getId() to get the crafty id of the entity you collided with. \$\endgroup\$ Commented Sep 11, 2014 at 7:12
  • \$\begingroup\$ Perhaps you need to know that I'm using the TiledMapBuilder.js component \$\endgroup\$ Commented Sep 11, 2014 at 20:44
  • \$\begingroup\$ Ahh, that is probably the cause of our confusion. Sorry I know nothing about that component. Please include important information like that in your question. \$\endgroup\$ Commented Sep 12, 2014 at 8:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.