Snap inside drop area?

Vikash,

In this post you mention successfully limiting an object’s draggable range. Presumably you do this by checking if an object’s X position is greater than one certain value and smaller than another value.

This code can easily be adapted. Instead of just checking the X position of the object, you need to check the X position and the width of the sprite (we will divide the width of the sprite by two).

assume the cupboard goes from 200 to 400.
x.pos is the X position of the cucumber.
x.width is the width of the cucumber.

if x.pos - (x.width/2) > 200 then
– the left side of the object is inside the boundary
if x.pos +(x.width/2) < 400 then
– the right side of the object is within the boundary.
end
end

I hope the above pseudo code helps you understand the concept.

3 Likes