Once an object (we’ll use a rectangle for this example) has been created and has had physics.addBody enacted… is it possible to later change the physics properties of that object. In the following example the physical properties would change when the rectangle is tapped.
Thanks for any help.
[blockcode]
local physics = require(“physics”)
physics.start()
–Function that runs when the object is tapped.
local function testTap(event)
–I am able to get the event name, numtaps, etc without issue.
testTapEvent.text=event.name --Works
event.target.alpha=.2 --Works
–Try to change bounce (or set item to static is ideal
event.target.physics.bounce=0.9 --Doesn’t work… was a shot in the dark… Tried many variations.
–Tried syntax like the following as well with no success
physics.addBody( event.target, { density=2, friction=.7, bounce=0.9 })
–Tried changing the item to static as well
physics.addBody( event.target, “static”, { density=2, friction=.7, bounce=0.9 })
end
–Creation of rectangle
local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
myRectangle:addEventListener( “tap”, testTap )
–initial physics
physics.addBody( block, { density=2, friction=.7, bounce=0.1 })
[/blockcode] [import]uid: 59514 topic_id: 10140 reply_id: 310140[/import]