When moving the position of the group, the hitboxes of physical bodies do not move and objects collide incorrectly.
device = require('Plugins.device')
physics = require('physics')
physics.start()
physics.setDrawMode("hybrid")
local group = display.newGroup()
local player = display.newRect(cx, cy, 50, 50)
physics.addBody(player, "dynamic")
player.gravityScale = 10
--player.isSensor = true
local first
local pos = 0
for i = 1, 10 do
local column = display.newRect(pos, 0, 52, dacth*2) group:insert(column)
column.y = cy + player.height/2 + column.height/2
physics.addBody(column, "static")
pos = pos + math.random(100, 500)
pos = pos + column.width
if i == 1 then first = column end
end
local power = display.newRoundedRect(cx, originY + 100, dw - 200, 10, 25)
power.power, power.beganpower = dw - 200, dw - 200 power.mode = "left" power.speed = 20
timer.performWithDelay(0,
function()
group.x = display.contentCenterX - player.x
group.y = display.contentCenterY - player.y
if power.mode == "left" then
power.power = power.power - power.speed
power.x = power.x - power.speed/2
power.width = power.power
elseif power.mode == "right" then
power.power = power.power + power.speed
power.x = power.x + power.speed/2
power.width = power.power
end
if power.power >= power.beganpower then power.mode = "left" end
if power.power <= 0 then power.mode = "right" end
end, 0)
local jump = function(event)
if event.phase == "ended" then
player:applyForce(power.power/power.beganpower*30, -power.power/power.beganpower*70, player.x, player.y)
end
end
Runtime:addEventListener("touch", jump)