I am just playing with different ways of doing the same program. This is a simple ball dropping down, following the ramps, hitting the bottom then resetting to the top and repeating. When I put the balls in a newGroup the balls “see” the ramps as not being where the graphic is, the ball “see” the ramps as being below their visual placement. When I do the same program the long way without newGroup and give each ball it’s physics without using the array index method the physics works fine. The balls are the same ones used in the sample pool program. I see nothing obvious causing the dislocation.
require ( “physics” )
physics.start()
local ramp1 = display.newRect(0,200,300,10)
ramp1:setFillColor(255,0,0)
ramp1.rotation = 30
local ramp2 = display.newRect(200,400,300,10)
ramp2:setFillColor(255,0,0)
ramp2.rotation = -30
local ramp3 = display.newRect(0,600,300,10)
ramp3:setFillColor(255,0,0)
ramp3.rotation = 30
local leftWall = display.newRect(0,0,10,850)
leftWall:setFillColor(255,0,0)
local rightWall = display.newRect(470,0,10,850)
rightWall:setFillColor(255,0,0)
local bottom = display.newRect(0,850,470,10)
bottom:setFillColor(255,255,0)
function InitializeBall()
ball_blue = display.newImage( “ball_blue.png” )
ball_red = display.newImage( “ball_red.png” )
ball_green = display.newImage( “ball_green.png” )
ball_orange = display.newImage( “ball_orange.png” )
ball_pink = display.newImage( “ball_pink.png” )
ball_purple = display.newImage( “ball_purple.png” )
ball_yellow = display.newImage( “ball_yellow.png” )
balls = display.newGroup(ball_blue, ball_red, ball_green, ball_orange, ball_pink,ball_purple, ball_yellow)
for i = 1, balls.numChildren do
balls[i].x = 200
balls[i].y = -40 * i
physics.addBody( balls[i], { bounce=0, radius = 15 } )
end
end
InitializeBall()
function CheckBottom(cnt)
if balls[cnt].y > 800 then
balls[cnt]:setLinearVelocity(0,0)
balls[cnt].y = -40
balls[cnt].x = 40
end
end
–Function to check the ball’s location
local function checkPos ()
CheckBottom(1)
CheckBottom(2)
CheckBottom(3)
CheckBottom(4)
CheckBottom(5)
CheckBottom(6)
CheckBottom(7)
end
–Add a runtime listener
Runtime: addEventListener (“enterFrame”, checkPos)
physics.addBody(bottom, “static”, {bounce = 0})
physics.addBody(rightWall, “static”)
physics.addBody(leftWall, “static”)
physics.addBody(ramp1, “static”, {bounce = 0})
physics.addBody(ramp2, “static”, {bounce = 0})
physics.addBody(ramp3, “static”, {bounce = 0}) [import]uid: 23256 topic_id: 23325 reply_id: 323325[/import]
[import]uid: 52491 topic_id: 23325 reply_id: 93462[/import]