Hashasm

collision detection between two entites

Recommended Posts

HI ,

can someone tell me how can I detect collision between two me.DraggableEntity  entites. or detecting collision between two sprites when they are dragging and dropping on each other.

we can detect the collision by using me.DroptargetEntity but when i make an entity as me.DroptargetEntity  then i cant able to drag the same please help me with this 

Thank You

Share this post


Link to post
Share on other sites

I am creating city building game in that from hud element  I am dragging and placing my house in a map,so user experience perspective if he tries to put a house over an exsisting house then i should say u can't place here(check for overlap or collision), so only I want to prevent being collide with each other. 

after dropping the house I am letting user to modify the house place i mean again in the game also use can drag his house anywhere he wants.

so please can you tell me how can I do the same.:mellow:

Share this post


Link to post
Share on other sites

you just need to add a entity with a body shape, at the same place of the house, and check for collision from or with that entity.

if you look at the melonJS source code, it's all we really we do  : create an entity with a body, and configure them as WORLD_SHAPE for the the collision layer  :

https://github.com/melonjs/melonJS/blob/master/src/level/TMXTiledMap.js#L463-L465

Share this post


Link to post
Share on other sites

finally i got it. i am creating entity with collision type .

but can you guys help me with this:-

now i am creating one new building in my game, when i am refreshing my browser that building disappearing i mean its not saving can someone tell me how to save my building at  that position only even when I refresh my building:rolleyes:

Share this post


Link to post
Share on other sites

You only have a few options for saving;

  1. Save and load from localStorage; melonJS provides a wrapper for this.
  2. Create an HTTP REST API to save and load from your favorite database ... or directly rewrite the TMX/JSON files

Option 2 is really cool if you are saving directly to the TMX/JSON files, but doing any of that is way outside of the scope of melonJS.

Share this post


Link to post
Share on other sites

hmm thank you , saving in local storage i got one example but I dont know how to start with option 2,how can i change my tmx /json directly suggest me some documentation or example to do the same Thank you 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.