I am spawning randomly colored and sized blocks, thusly:
[blockcode]
function createBoxes()
local function randBox()
local randW = mRand(60, 80)
local randH = randW
local genY = (-100)
local genX = mRand(100, 300)
local red = mRand(1, 245)
local green = mRand(1, 245)
local blue = mRand(1, 245)
local newBox = display.newRoundedRect (genX, genY, randW, randH, 10)
physics.addBody(newBox, “dynamic”, {friction=1, bounce=.05, density=3})
newBox.myName = “box”
newBox.strokeWidth = 5
newBox:setFillColor(red, blue, green)
newBox:addEventListener(“collision”, onCollision)
end
timer.performWithDelay(2000, randBox, 10)
end
[/blockcode]
These blocks fall on a platform that will eventually be moved via accelerometer. This is the code for the platform:
[blockcode]
function createDeck()
local deckHeight = 10
local deckWidth = _W/2
local motionx = 0
local motiony = 0
local deck = display.newRoundedRect(_W/2 - deckWidth/2, _H * .75, deckWidth, 10, 2)
physics.addBody(deck, “static”, {friction=.75, bounce=0.01, density=3})
deck.myName = “deck”
–using touch for testing
local function moveDeck(event)
deck.x = event.x
end
Runtime:addEventListener(“touch”, moveDeck)
[/blockcode]
The blocks interact with gravity and physics correctly (they hit the platform and bounce). I am having trouble figuring out how to get the blocks to move with the platform and each other once they land on it.
[import]uid: 55934 topic_id: 13864 reply_id: 313864[/import]