cocos-lua-spriteex

来源:互联网 发布:3dsmax2014软件许可证 编辑:程序博客网 时间:2024/05/01 18:46




local Sprite = cc.Sprite


function Sprite:playAnimationOnce(animation, args)
    local actions = {}


    local showDelay = args.showDelay or 0
    if showDelay then
        self:setVisible(false)
        actions[#actions + 1] = cc.DelayTime:create(showDelay)
        actions[#actions + 1] = cc.Show:create()
    end


    local delay = args.delay or 0
    if delay > 0 then
        actions[#actions + 1] = cc.DelayTime:create(delay)
    end


    actions[#actions + 1] = cc.Animate:create(animation)


    if args.removeSelf then
        actions[#actions + 1] = cc.RemoveSelf:create()
    end


    if args.onComplete then
        actions[#actions + 1] = cc.CallFunc:create(args.onComplete)
    end


    local action
    if #actions > 1 then
        action = cc.Sequence:create(actions)
    else
        action = actions[1]
    end
    self:runAction(action)
    return action
end


function Sprite:playAnimationForever(animation)
    local animate = cc.Animate:create(animation)
    local action = cc.RepeatForever:create(animate)
    self:runAction(action)
    return action
end


-- 开启/关闭外围包装盒,单个
function Sprite:setRectEnabled(args)
    self.rect_list = self.rect_list or {}
    if args then
        local draw_node = cc.DrawNode:create()
        dump(self:getSize())
        local x, y = self:getPos()
        local w, h = self:getSize().width, self:getSize().height


        draw_node:drawRect(cc.p(x,y),cc.p(x + w , h + y),cc.c4b(100,255,0,100))
        self.rect_list[#self.rect_list + 1] = draw_node
        print("#self.rect_list",#self.rect_list)
        draw_node:setName('rect'..#self.rect_list)
        self:addme(draw_node,9999,#self.rect_list + 1000)
        return self
    end   
    if next(self.rect_list) == nil then return end
    for i = #self.rect_list , 0 , -1 do 
        ChestError(self.rect_list[i]) -- 检查空指针
        self:delObjByName(self.rect_list[i]:getName())
    end
    return self
end
0 0
原创粉丝点击