OK I created a spinning ring of death made out of green rectangles, they’re all attached to a parent display group, which is the one rotating everything.
Awesome.
I attach physics bodies to each of the rectangles.
Awesomer!
I run my app, and the thing spins as expected, 'cept the !@#$@ physics bodies are staying as flat as a board!! They’re rotating around the center of my display group, but they’re staying horizontal all the time!!! What the heck?!
Teh Lame!
Anyone know how I can make the physics bodies, y know, STAY MATCHED with my rectangles that they’re attached to? I know I gotta be missing something cause, y know, you expect by ATTACHING a physics body that the thing will stay aligned to the object it’s attached to?!?!
&*^@%&^!
OK, code here:
local tweens = {}
local gameBoard = display.newGroup()
local myDisplayGroup = display.newGroup()
myDisplayGroup:insert(display.newCircle( 0, 0, 5 ))
local increments = 18
physics = require "physics"
physics.start()
physics.setDrawMode( "hybrid" )
physics.setGravity( 0, 0 )
for i=1,increments do
-- Create a new rectangle
local tempObject = display.newRect(0,0,60,2)
physics.addBody( tempObject )
tempObject:setFillColor(0,255,0)
-- .. and throw it in the group
myDisplayGroup:insert(tempObject)
-- Do fancy math to have our rectangle
-- segments rotated around a central point
-- of our 'myDisplayGroup' object.
local x = 10
local y = 10
local degrees = i\*360/increments
-- Adjust our rectangle's rotation so we
-- have sort of a closed circle.
tempObject.rotation = degrees - 45
local theta = (math.pi \* degrees) / 180
local xx = x\*math.cos(theta) - y\*math.sin(theta)
local yy = x\*math.sin(theta) + y\*math.cos(theta)
-- Add the physics body
tempObject.bodyType = "dynamic"
tempObject.x = xx \* 10
tempObject.y = yy \* 10
end
myDisplayGroup.x = 300
myDisplayGroup.y = 300
----------------------------------------------------------------
-- MAIN LOOP
----------------------------------------------------------------
local function main( event )
-- Just rotate our display group
-- The rectangles I created show up fine
-- But the darned physics bodies that I
-- attached to the rectangles don't rotate
-- along with their respective rectangles, they
-- just stay horizontal!? WTH?!
myDisplayGroup.rotation = myDisplayGroup.rotation + 1
end
Runtime:addEventListener( "enterFrame", main )
Appreciate any pointers!
[import]uid: 11636 topic_id: 14513 reply_id: 314513[/import]