Hi, I’m giving a try to corona and lua, and in general to game programing (coming from IT development). So I’m having hard times trying to understand why my display objects are not getting piled when they collide, but instead they are getting overlapped.
The goal is simply to get the rects piled, as if they were stones falling from sky. I would also like to sometimes rotate the floor (base) 90º, and still get the rects pilled and glued. However sometimes the rects bounce a little and they join in a weird angle, although I set the bounce property to 0.
Thanks in advance.
[code]
display.setStatusBar( display.HiddenStatusBar )
local obj_fisica = require(“physics”);
obj_fisica.start();
obj_fisica.setDrawMode(“hybrid”)
ANCHO = display.contentWidth;
ALTO = display.contentHeight;
base = display.newRect(0, (ALTO-100) , ANCHO, 200)
obj_fisica.addBody(base, “static”, { friction=0.5, bounce=0})
function unir(self)
t_weld = {}
table.insert(t_weld, obj_fisica.newJoint(“weld”, self, base, base.x, base.y))
print(self.nombre)
end
local function onCollision(self, event)
local closure = function() return unir( self ) end
timer.performWithDelay( 10, closure )
end
function nuevaPieza()
local posAleatoria = 100 + math.random(200)
nuevaPieza = display.newRect(base.x -39, 10, base.contentHeight / 2, 10);
nuevaPieza:setReferencePoint(display.TopCenterReferencePoint);
obj_fisica.addBody(nuevaPieza, “dinamyc”,{ density=2, bounce=0 });
nuevaPieza.nombre = “Pieza”
nuevaPieza.collision = onCollision
nuevaPieza:addEventListener(“collision”, nuevaPieza)
end
timer.performWithDelay(2000, nuevaPieza, 10)
[/code] [import]uid: 8933 topic_id: 7198 reply_id: 307198[/import]
[import]uid: 8933 topic_id: 7198 reply_id: 25480[/import]
[import]uid: 8933 topic_id: 7198 reply_id: 25669[/import]