Right. Here’s what I’ve found and I’d really, really like to know if I’m doing something wrong, not read the docs properly or if this is a bug in Corona…
It seems as though pistons only work if the anchor is an image.
Ok, let me caveat that: I have a piece of code which tries to create a piston using a display.newRect and a display.newImage. That fails by crashing the simulator. When I replace the display.newRect with a display.newImage it works.
Here’s my code (assume require physics, etc. above)…
local physprop = { density=0.0, friction=0.0, bounce=0.0 }
local img = display.newImage( “crate.png” )
img.x = 100
local anchor = display.newRect( 0,0 , 10,10 )
anchor.x = 100
anchor.y = display.contentHeight - 100
anchor:setFillColor( 50,50,50 )
local crate = physics.addBody( img, physprop )
img.linearDamping = 2
local block = {}
block[“img”] = img
block[“crate”] = crate
block[“physprop”] = physprop
local crate = display.newImage( “crate.png” )
crate.x = 100
crate.y = display.contentHeight - 200
physics.addBody( crate, “static”, physprop )
– local piston = physics.newJoint( “piston”, anchor, img, anchor.x,anchor.y , 0,5 ) – breaks!
local piston = physics.newJoint( “piston”, crate, img, crate.x,crate.y , 0,5 )
[import]uid: 8271 topic_id: 2026 reply_id: 6042[/import]