my goal is to create a platform, from one x,y coordinate, to the touch event, in such a way that sliding your finger around will move and resize the platform in real time. However the problem is, that if there is a ball on said platform, and i then move the platform, The ball will freeze and stop acting like a ball, until the platform is done being manipulated.
Is there a way that I can get the balls to continue to behave as normal even while the platform they are on is being moved?
I have included the code so you can play with it and see what I mean. The best way to see what I am talking about is to click to create a platform, wait for a ball to land on it, and then drag the end of the platform around.
local physics = require("physics");
physics.start();
physics.setDrawMode("hybrid");
W = display.contentWidth;
H = display.contentHeight;
balls = {};
local function createPlatform(event)
if (event.phase == "began") then
if(line) then
line.parent:remove(line);
end
x = (event.x - (W/2 - 80));
y = (event.y - (H/2));
line = display.newLine(W/2 - 80, H/2, event.x, event.y)
line.width = 5;
physics.addBody(line, "static", {shape = {0, 0, x, y}});
line.isBullet = true;
end
if (event.phase == "moved") then
x = (event.x - (W/2 - 80));
y = (event.y - (H/2));
if (line) then
line.parent:remove(line);
end
line = display.newLine(W/2 - 80, H/2, event.x, event.y)
line.width = 5;
physics.addBody(line, "static", {shape = {0, 0, x, y}});
line.isBullet = true;
end
if (event.phase == "ended") then
end
end
local function spawnBalls(event)
i = 1;
local function spawnb(event)
rand = math.random(1, 4);
if (rand == 1) then
balls[i] = display.newCircle(math.random(140, 180), -30, 7.5);
balls[i]:setFillColor(255,0,0);
physics.addBody(balls[i], {radius = 7.5})
balls[i].isBullet = true;
i = i + 1;
rand = math.random(1,4)
elseif (rand == 2) then
balls[i] = display.newCircle(math.random(140, 180), -30, 7.5);
balls[i]:setFillColor(0, 255, 0);
physics.addBody(balls[i], {radius = 7.5})
balls[i].isBullet = true;
i = i + 1;
rand = math.random(1,4)
elseif (rand == 3) then
balls[i] = display.newCircle(math.random(140, 180), -30, 7.5);
balls[i]:setFillColor(0, 0, 255)
physics.addBody(balls[i], {radius = 7.5})
balls[i].isBullet = true;
i = i + 1;
rand = math.random(1,4)
elseif (rand == 4) then
balls[i] = display.newCircle(math.random(140, 180), -30, 7.5);
balls[i]:setFillColor(255, 255, 0);
physics.addBody(balls[i], {radius = 7.5})
balls[i].isBullet = true;
i = i + 1;
rand = math.random(1,4)
end
end
timer.performWithDelay(1500, spawnb, -1);
end
spawnBalls();
Runtime:addEventListener("touch", createPlatform)