Шукати в цьому блозі

Корисні функції


Z-order / Встановити шар

--Перемістити в самий верхній шар
function Sprite:bringToFront()
        self:getParent():addChild(self)
end

--Перемістити в самий нижній шар
function Sprite:sendToBack()
        self:getParent():addChildAt(self, 0)
end

--Перемістити в зазначений шар, якщо значення більше максимального шару - перемістимо в самий верхній.
function Sprite:setIndex(index)
        local parent=self:getParent()
        if index<parent:getChildIndex(self) then
                index=index-1
        end
        parent:addChildAt(self, index)
end

Видалити об'єкт
--Видалити yourObjectSprite
stage:removeChild(yourObjectSprite)

--При кліці на будь-якому об'єкту
local function onMouseDown(event)
        for i=1,stage:getNumChildren() do
                local sprite = stage:getChildAt(i)
                local body = sprite.body
                if sprite:hitTestPoint(event.x, event.y) then
                        stage:removeChild(sprite)
                        world:destroyBody(body)
                        break
                end
        end
end

stage:addEventListener(Event.MOUSE_DOWN, onMouseDown)


stage:addEventListener(Event.TOUCHES_BEGIN , onTouchesBegin)

--При кліці по екрану
function onTouchesBegin(event)
        world:destroyBody(yourObjectBody)
        stage:removeChild(yourObjectSprite)
end
 

Видалити всіх дітей
function clear(sprite)
    while sprite:getNumChildren() > 0 do
        sprite:removeChildAt(1)
    end
end

Теж саме але по іншому
function clear(sprite)
    for i = sprite:getNumChildren(), 1, -1 do
        sprite:removeChildAt(i)
    end
end

Destructor
function EventDispatcher:postInit()
        self._proxy = newproxy(true)
        getmetatable(self._proxy).__gc = function() self:_destroy() end
end

function EventDispatcher:_destroy()
end





























3

Немає коментарів:

Дописати коментар