Having trouble getting 'onCollision' to fire.

55 views
Skip to first unread message

kiefe...@gmail.com

unread,
Sep 20, 2014, 5:27:29 PM9/20/14
to mel...@googlegroups.com
Title says it, here's my code for my entities:

https://gist.github.com/kieferhagin/f6e41e7548e261742682

Basically I'm trying to determine when my 'Hero' collides with my 'Goal' object. They are both correctly defined in Tiled and are loading just fine, no errors in the console.

What am I missing here?

kiefe...@gmail.com

unread,
Sep 20, 2014, 5:44:55 PM9/20/14
to mel...@googlegroups.com, kiefe...@gmail.com

So I just found this: http://melonjs.github.io/docs/me.collision.html#check

That seems to fire just fine. Is this the preferred way to detect collision? What's the purpose of body.onCollision, if so? Thanks!

kiefe...@gmail.com

unread,
Sep 20, 2014, 5:47:58 PM9/20/14
to mel...@googlegroups.com, kiefe...@gmail.com
And now I've found if I call check(), all the body.onCollision handlers on any of my other entities seem to fire just fine!

I might go in and add a pull request for a simple boolean variable that automatically calls check() if true. This seems like a lot of work just to enable collisions for an entity.

Jay Oster

unread,
Sep 20, 2014, 7:31:46 PM9/20/14
to mel...@googlegroups.com, kiefe...@gmail.com
This collision code is all new in 1.1.0. It needs to be reworked to do collision checking automatically (as you discovered). For performance reasons, we can't have each entity doing the collision checking; it just needs to be done once globally.
Reply all
Reply to author
Forward
0 new messages