Hi, I’m trying to connect two images- a sprite with physics applied and a background lighting effect (a rotating png image). When I move one, I’d like to the other to be fixed and move with it, as if they were one display object.
What’s the best approach?
If I apply physics to both objects they won’t stay at the same position.
I’ve tried to put them in the same display group but I can’t seem to position the group.
Eventually I’d like to spawn these grouped pairs and have them fall under gravity from a spawn object off screen… but that’s the next hurdle.
Thanks for any pointers.
[lua]
local lightingeffect= display.newImageRect( “glimmer.png”, 35, 35 )
lightingeffect.anchorX = 0.5
lightingeffect.anchorY = 0.5
lightingeffect.x, lightingeffect.y = 200,100
map.layer[1]:insert(lightingeffect)
local function spinGlimmer (event)
transition.to( lightingeffect, { rotation = lightingeffect.rotation-360, time=4000, onComplete=spinGlimmer } )
end
spinGlimmer ()
local object = display.newImageRect( “object.png”, 7, 12 )
object.anchorX = 0.5
object.anchorY = 0.5
object.x, object.y = 200,100
physics.addBody( object, “dynamic”, { density=1, friction=1, bounce=0.0 } )
map.layer[1]:insert(object)
[/lua]