Hashasm Posted May 7, 2017 Share Posted May 7, 2017 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 Quote Link to comment Share on other sites More sharing options...
obiot Posted May 8, 2017 Share Posted May 8, 2017 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 ! Quote Link to comment Share on other sites More sharing options...
Hashasm Posted May 13, 2017 Author Share Posted May 13, 2017 no i am not getting it. i am just changing this.getBounds().height=200; i dont know syntax is correct or not. Quote Link to comment Share on other sites More sharing options...
Parasyte Posted May 13, 2017 Share Posted May 13, 2017 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); Quote Link to comment Share on other sites More sharing options...
Hashasm Posted May 14, 2017 Author Share Posted May 14, 2017 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 .. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.