I’m working with a student who wants to make a plinko game. My thought was to generate the pegs, put them in a group, and position the group. Interestingly, when I reposition the group to the center of the screen, the physics bodies (view in hybrid) appear to have moved, but the when the chip drops, it bounces off “invisible pegs” This is where the pegs were originally made before I moved the group. Any help is greatly appreciated as I have NO IDEA why this is happening!
display.setStatusBar( display.HiddenStatusBar )
– Screen Coordinates
centerX = display.contentCenterX
centerY = display.contentCenterY
screenLeft = display.screenOriginX
screenWidth = display.contentWidth - screenLeft * 2
screenRight = screenLeft + screenWidth
screenTop = display.screenOriginY
screenHeight = display.contentHeight - screenTop * 2
screenBottom = screenTop + screenHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight
local physics = require(“physics”)
physics.start()
physics.setDrawMode(“hybrid”)
local pegRadius = 10
local pegGroup = display.newGroup()
pegGroup.anchorChildren= true
pegGroup.x = centerX
pegGroup.y = centerY
local function generatePegs()
local x, y
local offset = 50
local peg
for row = 1,10 do
if row % 2 == 1 then
for column = 1, 8 do
x = 100 * column
y = 100* row
peg = display.newCircle(x, y, 10)
peg.name = "peg"
physics.addBody(peg,"static", {bounce = .1,friction = .2,radius = 10})
pegGroup:insert(peg)
peg = nil
print(x,y)
end
else
for column = 1, 7 do
x = 100 * column+offset
y = 100 * row
peg = display.newCircle(x, y, 10)
peg.name = "peg"
pegGroup:insert(peg)
physics.addBody(peg,"static", {bounce = 0.1,friction = .2, radius = 10})
peg = nil
print(x,y)
end
end
end
end
generatePegs()
local ball = display.newCircle(centerX, screenTop + 50, 35)
physics.addBody(ball, “dynamic”, {radius=35})