Here is a sample of what I did, if you ever need any samples:
-- variables
world = display.newGroup()
masks = { ..., }
-- functions
setupAxis = nil
onTap = nil
setupAxis = function(object)
object.dg = display.newGroup()
world:insert(object.dg)
object.dg.x = object.x
object.dg.y = object.y
local blades = {}
for i=1,#object.blades do
local params = object.blades[i]
local blade = display.newImage(object.dg, "blade.png", 0, 0)
blade.x = params.x - object.dg.x
blade.y = params.y - object.dg.y
blade.rotation = params.rotation
local filter = {
categoryBits = masks.delimiter.categoryBits,
maskBits = masks.delimiter.maskBits,
}
physics.addBody(blade, "static", {
density = 1.0,
friction = 0.0,
bounce = 0.0,
filter = filter,
})
blades[#blades+1] = blade
end
object.axis = display.newImage("axis.png", 0, 0)
object.axis.x = 0
object.axis.y = 0
object.axis.blades = blades
object.dg:addEventListener("tap", onTap)
return
end
onTap = function(event)
local object = event.target.object
local time = (object.time or 1000)
local step = (object.step or 90)
local rstep = step \* math.pi/180
local easingx = require("easing")
for i=1,#object.axis.blades do
local blade = object.axis.blades[i]
if not blade.rotationTransition then
blade.rotationTransition = transition.to(blade, {
time = time,
rotation = blade.rotation - step,
transition = easingx.easeOutBounce,
onComplete = function()
if blade.rotationTransition then
blade.rotationTransition = nil
end
end
})
end
end
if not object.dg.rotationTransition then
object.dg.rotationTransition = transition.to(blade, {
time = time,
rotation = object.dg.rotation - step,
transition = easingx.easeOutBounce,
onComplete = function()
if object.dg.rotationTransition then
object.dg.rotationTransition = nil
end
end
})
end
return
end
-- main
setupAxis({
"IsAxis" = true,
"x" = 160,
"y" = 170,
"blades": {
{"x" = 160, "y" = 170, "rotation" = 44},
{"x" = 155, "y" = 174, "rotation" = -134},
{"x" = 164, "y" = 174, "rotation" = -45},
{"x" = 160, "y" = 170, "rotation" = -45}
},
})
I hope I’ve manage to be synthetic enough so that you see my point. Blade’s physical body is rotating according to my expectations, but has a shift in regard to blade’s display object. [import]uid: 40274 topic_id: 12001 reply_id: 43796[/import]