Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
shapes and collision — Gideros Forum

shapes and collision

Diego_85Diego_85 Member
edited April 2013 in General questions
Hi everybody,
I'm trying to make some rectangular shapes to drag in the space.
The thing i want to achieve is like the "Drag me" Gideros default example, but i don't want the shapes to overlap (I want to make a puzzle-like game so the pieces don't have to intersect).
I tried with box2d dynamic bodies but the gravity is driving me crazy (even if i set it to 0 the bodies will keep going after I release the finger while moving).
Ideas/tips/suggestions?
Thanks

Comments

  • use this function to chk collition
    function Sprite:collidesWith(sprite2)
    	local x,y,w,h = self:getBounds(stage)
    	local x2,y2,w2,h2 = sprite2:getBounds(stage)
     
    	return not ((y+h < y2) or (y > y2+h2) or (x > x2+w2) or (x+w < x2))
    end
    basically you need one array of all the shapes and you need to iterate through each to chk any overlaps on mouse_move event

    or at the time of mouse_down you can calculate minimum and maximum x and y position and then move accordingly assuming you are trying to make game like unblock me.


    :)
  • ar2rsawseenar2rsawseen Maintainer
    @Diego_85 for box2d you may set the linear dampening of the body so it will not have such inertia.

    b2.Body:setLinearDamping(linearDamping)

    Likes: Diego_85

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks @ar2rsawseen, didn't know about linearDamping. @hgvyas123 I will try your solution too
  • Seems interesting, I'll give a look at TNT
Sign In or Register to comment.