Flip whole Game Object

For sprites, you have sprite.set_hflip, but for the game objects, it should suffice to loop over the game objects and move them relative their parents position. Something like this:


local function flip(names, left)
    -- skip the first node (the top parent)
    for i = 2, #names do
        local name = names[i]
        local pos = go.get_position(name)
        go.set_position(vmath.vector3(-pos.x, pos.y, pos.z), name)
        sprite.set_hflip(name .. "#sprite", left)
    end
    print("flip ", left)
end

function init(self)
    self.timeout = 0.5
    self.timer = self.timeout
    self.left = false
    self.names = {"parent", "child1", "child2"}
end

function update(self, dt)
    self.timer = self.timer - dt
    if self.timer < 0 then
        self.timer = self.timeout
        self.left = not self.left
        flip(self.names, self.left)
    end
end
3 Likes