Sign in to follow this  
Followers 0
Hashasm

can we change collision check with and height of the image

5 posts in this topic

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

Share this post


Link to post
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 !

Share this post


Link to post
Share on other sites

no i am not getting it.

i am just changing this.getBounds().height=200;

i dont know syntax is correct or not.

Share this post


Link to post
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);
this.body.updateBounds();

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);

 

Share this post


Link to post
Share on other sites

yeah you guys right but if i am using me.Entity the dragging functionalities is not so smooth as in me.DraggableEntity so i am sticking with DraggableEntity only .. 

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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.