Jump to content

can we change collision check with and height of the image


Recommended Posts

hi all,

When ever we make collision check it will take the width and height of the image or object which we are giving .

Now can we change width and height of the collision check alone .in my case my image size is 100*100 but while dragging and droping i am making collision check in which it taking 100*100 for check but i wana change it to 200*200 can it be possible .

i tried changing the image with and height while dragstart,dragmove and pointerdown ,but still for collision it will take 100*100 only

Link to comment
Share on other sites

if you want to change the collision box but NOT the image, the only way i see is to resize it by yourself.

You can get a reference to it by using the getBounds() method, then you have access to a me.Rect object that you can resize as you wish. However be aware that as soon as you apply any transformation to your sprite, melonJS will recalculate the sprite bounds and therefore ignore your changes.

If you need a larger collision area for a sprite object, I would either more recommend to also add a transparent border to your sprite, or use an Entity object !

Link to comment
Share on other sites

I recommend adjusting the collision shape(s) on the entity body. If you only have one shape, it's very easy.

// When `this` references a me.Entity
var shape = this.body.getShape(0);
shape.resize(shape.width, 200);

If you're not using the me.Entity class, then you can adjust the bounding rectangle directly. But as obiot pointed out, the bounding rect is just a cache, and melonJS will wipe it out on you. (So use me.Entity)

// When `this` references a me.Sprite
var shape = this.getBounds();
shape.resize(shape.width, 200);


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...